How to get attribute's option on frontend

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!
akropivko
Posts: 36
Joined: 20 Jan 2021, 12:49

How to get attribute's option on frontend

Post by akropivko » 06 Mar 2021, 17:35

Could you give me an idea how can I get an attribute's option (see screenshot) on frontend?
I'd like to get the "colorcode" option for each color product attribute on frontend.
In user manual there is
"Option/Value (optional)
Arbitrary list of key/value pairs that will be available with each image/media item in the frontend"
But how?
Attachments
Screenshot_39.jpg
Screenshot_39.jpg (43.35 KiB) Viewed 1459 times

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

Re: How to get attribute's option on frontend

Post by aimeos » 08 Mar 2021, 09:32

For example, you can get the value here:
https://github.com/aimeos/ai-client-htm ... d.php#L375
using:

Code: Select all

$listItem->getConfigValue( 'colorcode' )
If you use a media property instead, you can also use it in the partial rendering the icons:
https://github.com/aimeos/ai-client-htm ... hp#L52-L57
by using:

Code: Select all

$item->getProperties( 'colorcode' )->first()
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

ttyy
Posts: 10
Joined: 02 Apr 2021, 16:31

Re: How to get attribute's option on frontend

Post by ttyy » 13 Apr 2021, 13:37

I'm wondering if the OP resolved the issue. I'm dealing with the same trouble, where catalog item has an image. while i'm setting options to the image i'm not able to retrieve that option.

Aimeos\MShop\Media\Item\Standard {#2132 ▼
-langid: "en"
-prefix: "media."
-available: true
-modified: false
#bdata: array:14 [▶]
-listItems: []
-listRefItems: []
-listRmItems: []
-listPrepared: true
-listRmMap: []
-listMap: []
-listMax: 0
-propItems: []
-propRmItems: []
-propMax: 0
}

$image->getProperties('imageopt') returns an empty map, despite the option is set for the media

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

Re: How to get attribute's option on frontend

Post by aimeos » 15 Apr 2021, 06:47

The option/value pairs are not stored as properties but in "bdata[media.config]" of the item instead. You can get the value using:

Code: Select all

$mediaItem->getConfigValue( 'colorcode' );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply