display variant attributes on catalog page

Help for integrating the Laravel package
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!
columbo
Advanced
Posts: 123
Joined: 09 Oct 2019, 09:42

display variant attributes on catalog page

Post by columbo » 23 Nov 2019, 10:32

Hi,

I'd like to display Variant attributes (eg. salesunit) on the catalog page.

I tried

Code: Select all

$productItem->getRefItems( 'attribute', null, 'variant' ),
in a cutom version of
/ext/ai-client-html/client/html/templates/catalog/lists/items-body-list.php
but it still does not work.

I'm using the wrong mehtod? Are there other / better possibilities to display variant attributes?
Thanks

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: display variant attributes on catalog page

Post by aimeos » 25 Nov 2019, 10:03

The attributes are not fetched by default in the list view. You can get them if you add "attribute" to this configuration:
https://aimeos.org/docs/Configuration/C ... ts/domains
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 123
Joined: 09 Oct 2019, 09:42

Re: display variant attributes on catalog page

Post by columbo » 26 Nov 2019, 22:54

I added 'attribute' to client/html/catalog/lists/domains:

Code: Select all

'domains' => [
    0 => 'media',
    1 => 'price',
    2 => 'text',
    3 => 'attribute'
],
but I still do not get any value for attributes definded under:
Products > Characteristic > Variant attributes > salesunit

I tried:

Code: Select all

$productItem->getRefItems( 'attribute', null, 'variant' ); 
$productItem->getRefItems( 'variant', null, 'salesunit' ); 

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: display variant attributes on catalog page

Post by aimeos » 28 Nov 2019, 09:32

Code: Select all

$productItem->getRefItems( 'attribute', null, 'variant' ); 
is correct but variant attributes are not attached to the selection product. Instead, they are part of the articles that are referenced by the selection product and you have to fetch them as well:

Code: Select all

'domains' => [
    0 => 'media',
    1 => 'price',
    2 => 'text',
    3 => 'attribute'
    4 => 'product'
],
Then, you can loop over the articles and get their variant attributes:

Code: Select all

foreach( $product->getRefItems( 'product', null, 'default' ) as $article ) {
	$attrItems = $article->getRefItems( 'attribute', null, 'variant' );
}
The product partial already does that if the "basket-add" configuration is enabled:
https://github.com/aimeos/ai-client-htm ... #L254-L287
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 123
Joined: 09 Oct 2019, 09:42

Re: display variant attributes on catalog page

Post by columbo » 28 Nov 2019, 23:01

unfortunately it's not working.
For a simple test I added just this code on my catalog/lists page:

Code: Select all

<?php 
    foreach( $productItem->getRefItems( 'product', null, 'default' ) as $article ) {
        echo $article;
        $attrItems = $article->getRefItems( 'attribute', null, 'variant' );
        echo $attrItems;
    }
?>
but I get on values either for $article nor $attrItems.
I'd like to list all variants with their sailesunit (e.g. kg, ml, g,) on a catalog page

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: display variant attributes on catalog page

Post by aimeos » 29 Nov 2019, 12:09

Use the "client/html/catalog/lists/basket-add" configuration setting, which does this already for you:
https://aimeos.org/docs/Configuration/C ... basket-add
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply