How to display custom media in basket view?
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
How to display custom media in basket view?
Hi,
we are using two different product media types ("default" and "custom").
On basket and checkout page the custom media should be displayed.
How can we select the custom media type here (\packages\myext\templates\client\html\common\summary\detail.php):
e.g. for favorite view (\packages\myext\templates\client\html\account\favorite\body.php) we used: But this does not work for the basket view.
Thank you!
we are using two different product media types ("default" and "custom").
On basket and checkout page the custom media should be displayed.
How can we select the custom media type here (\packages\myext\templates\client\html\common\summary\detail.php):
Code: Select all
<img src="<?= $this->content( $product->getMediaUrl() ) ?>" />
e.g. for favorite view (\packages\myext\templates\client\html\account\favorite\body.php) we used:
Code: Select all
$productItem->getRefItems('media', 'custom', 'default')
Thank you!
Re: How to display custom media in basket view?
You need to overwrite the copyFrom() method in order product item:
https://github.com/aimeos/aimeos-core/b ... #L747-L773
In the next versions, you will able to be overwrite the code by using macros:
https://github.com/aimeos/aimeos-core/b ... #L747-L773
In the next versions, you will able to be overwrite the code by using macros:
Code: Select all
\Aimeos\MShop\Order\Item\Product\Standard::macro( 'copyFrom', function( \Aimeos\MShop\Product\Item\Iface $product ) : \Aimeos\MShop\Order\Item\Base\Product\Iface {
// ...
return $this->setModified();
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: How to display custom media in basket view?
as the file has changed with the new version 2023.10 I think copyFrom() in file /aimeos-core/src/MShop/Order/Item/Product/Standard.php is the right one.
As suggested, I tried with macro in /app/ProvidersApp/ServiceProvider.php and changed the image form "default" to "custom"
laravel.log after adding an item to basekt:
Thank you
As suggested, I tried with macro in /app/ProvidersApp/ServiceProvider.php and changed the image form "default" to "custom"
Code: Select all
...
public function boot()
{
\Aimeos\MShop\Order\Item\Product\Standard::macro( 'copyFrom', function( \Aimeos\MShop\Product\Item\Iface $product ) : \Aimeos\MShop\Order\Item\Base\Product\Iface {
$this->fromArray( $values );
$this->setSiteId( $product->getSiteId() );
$this->setProductCode( $product->getCode() );
$this->setProductId( $product->getId() );
$this->setType( $product->getType() );
$this->setScale( $product->getScale() );
$this->setTarget( $product->getTarget() );
$this->setName( $product->getName() );
if( $item = $product->getRefItems( 'text', 'basket', 'default' )->first() ) {
$this->setDescription( $item->getContent() );
}
if( $item = $product->getRefItems( 'media', 'custom', 'default' )->first() ) {
$this->setMediaUrl( $item->getPreview() );
}
if( $item = $product->getSiteItem() ) {
$this->setVendor( $item->getLabel() );
}
return $this->setModified();
});
}
Code: Select all
ERROR: Call to undefined method App\Providers\AppServiceProvider::fromArray() {"userId":1,"exception":"[object] (Error(code: 0): Call to undefined method App\\Providers\\AppServiceProvider::fromArray() at /app/Providers/AppServiceProvider.php:32)
[stacktrace]
#0 /vendor/aimeos/aimeos-core/src/MShop/Order/Item/Product/Standard.php(766): App\\Providers\\AppServiceProvider->App\\Providers\\{closure}()
#1 /vendor/aimeos/ai-controller-frontend/src/Controller/Frontend/Basket/Standard.php(346): Aimeos\\MShop\\Order\\Item\\Product\\Standard->copyFrom()
#2 /vendor/aimeos/ai-controller-frontend/src/Controller/Frontend/Basket/Decorator/Category.php(59): Aimeos\\Controller\\Frontend\\Basket\\Standard->addProduct()
#3 /vendor/aimeos/ai-controller-frontend/src/Controller/Frontend/Basket/Decorator/Bundle.php(44): Aimeos\\Controller\\Frontend\\Basket\\Decorator\\Category->addProduct()
#4 /vendor/aimeos/ai-controller-frontend/src/Controller/Frontend/Basket/Decorator/Select.php(43): Aimeos\\Controller\\Frontend\\Basket\\Decorator\\Bundle->addProduct()
#5 /vendor/aimeos/ai-client-html/src/Client/Html/Basket/Standard/Standard.php(218): Aimeos\\Controller\\Frontend\\Basket\\Decorator\\Select->addProduct()
Re: How to display custom media in basket view?
Two mistakes:
1.) The function wasn't bound to the order product item object so $this referred to the AppServiceProvider where you've added the closure. This is now fixed and you need to execute:
2.) You are missing one line in your function:
1.) The function wasn't bound to the order product item object so $this referred to the AppServiceProvider where you've added the closure. This is now fixed and you need to execute:
Code: Select all
composer req aimeos/aimeos-core:2023.10.x-dev
Code: Select all
$values = $product->toArray();
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: How to display custom media in basket view?
for the sake of completeness - there was a third mistake in return parameter:
wrong: \Aimeos\MShop\Order\Item\Base\Product\Iface
-> correct: \Aimeos\MShop\Order\Item\Product\Iface
this code it is working fine:
Thank you!
wrong: \Aimeos\MShop\Order\Item\Base\Product\Iface
-> correct: \Aimeos\MShop\Order\Item\Product\Iface
this code it is working fine:
Code: Select all
public function boot()
{
\Aimeos\MShop\Order\Item\Product\Standard::macro( 'copyFrom', function( \Aimeos\MShop\Product\Item\Iface $product ) : \Aimeos\MShop\Order\Item\Product\Iface {
$values = $product->toArray();
$this->fromArray( $values );
$this->setSiteId( $product->getSiteId() );
$this->setProductCode( $product->getCode() );
$this->setProductId( $product->getId() );
$this->setType( $product->getType() );
$this->setScale( $product->getScale() );
$this->setTarget( $product->getTarget() );
$this->setName( $product->getName() );
if( $item = $product->getRefItems( 'text', 'basket', 'default' )->first() ) {
$this->setDescription( $item->getContent() );
}
if( $item = $product->getRefItems( 'media', 'custom', 'default' )->first() ) {
$this->setMediaUrl( $item->getPreview() );
}
if( $item = $product->getSiteItem() ) {
$this->setVendor( $item->getLabel() );
}
return $this->setModified();
});
}