aimeos / ai-controller-jobs

Aimeos e-commerce job controllers
https://aimeos.org
GNU Lesser General Public License v3.0
112 stars 17 forks source link

Linking "selection" products to the gallery #40

Closed Ameeko closed 2 years ago

Ameeko commented 2 years ago

Hello Aimeos!

I imported "selection" type products.

For example, a product has 3 subproducts in 3 different colors. Each subproduct has an image (blue, red and green).

Can I connect the interface so that when I select the color blue from the drop-down list, the gallery jumps to the photo of the blue product? If the system doesn't know this, what's the easiest way to do it?

aimeos commented 2 years ago

The admin backend does that automatically for you (attach the variant attributes to the images) so the correct image is displayed when the variant attribute is selected in the frontend: https://github.com/aimeos/ai-admin-jqadm/blob/master/admin/jqadm/src/Admin/JQAdm/Product/Media/Standard.php#L250-L265

The code in the CSV importer doesn't do that up to now: https://github.com/aimeos/ai-controller-jobs/blob/master/controller/common/src/Controller/Common/Product/Import/Csv/Processor/Media/Standard.php

Ameeko commented 2 years ago

I'm so sorry, but I don't understand where can I attach the variant attributes to the images. And I can't find a description of this anywhere in the documentation. Can you describe where I can do this in the admin backend?

aimeos commented 2 years ago

In the admin backend it's done automatically for you in you save a product which contains variant attributes and images.

Ameeko commented 2 years ago

I understand, but it doesn't work.

I did this in the admin backend:

1) I created a "Selection" type product Type = Selection SKU = product1 Label = product1

2) For the "selection" type product, I created 2 subproducts in the "Variants" menu Type = Article SKU = subproduct1 Label = subproduct1 Stock level = 999 Variant attributes = Blue (MyAttribute)

Type = Article SKU = subproduct2 Label = subproduct2 Stock level = 999 Variant attributes = Red (MyAttribute)

3) I selected the "subproduct1" in the admin backend (Catalog/Products). 4) I uploaded an image in the "Media" menu (image1.jpg) 5) In the "Prices" menu I uploaded a price (tax and price) 6) In the "Characteristics" menu I see this: Variant attributes = Blue (MyAttribute) Looks like it's okay.

7) I selected the "subproduct2" in the admin backend (Catalog/Products). 8) I uploaded an image in the media menu (image2.jpg) 9) I uploaded a price (tax and price) in the "Prices" menu 10) In the "Characteristics" menu I see this: Variant attributes = Red (MyAttribute) Looks like it's okay.

I open product1 on the website. I see the 2 images. If I change the MyAttribute dropdown, the prices will change, but the images will not.

What am I doing wrong?

Ameeko commented 2 years ago

If I use the color attribute that is in admin backend by default, it works. If I create my own attribute, the "Swap Images" feature will not work. Does the "Swap Images" feature work specifically with this default color attribute?

aimeos commented 2 years ago

It only works with variant attribute, not with regular attributes but it should also works with other attributes which are not of type "color".

Ameeko commented 2 years ago

Thanks for the reply. As I wrote, I tried "Variant Attribute" and it doesn't work. Works only with the default color attribute. I don't understand because I don't see a difference between my variant attribute and the default color attribute. I wrote it down step by step because maybe you see something I’m doing wrong. Thank you anyway.

aimeos commented 2 years ago

The steps you described seem to be correct. We had a look into the code (PHP and JS) but found no reason up to now why it shouldn't work with other attributes too. Here's the code in question if you want to debug yourself:

Ameeko commented 2 years ago

I can’t set it to be not a dropdown but clickable boxes next to each other. For example: [M] [L] [XL] The default attribute works. What I create "Variant Attribute" there is always a dropdown. I can't find anything like this anywhere in the documentation or on the admin backend.

aimeos commented 2 years ago

Please have a look here: https://aimeos.org/docs/2021.x/config/client-html/catalog-selection/#type

Ameeko commented 2 years ago

Oh, I have to set it to "radio". Thanks.

Ameeko commented 2 years ago

The steps you described seem to be correct. We had a look into the code (PHP and JS) but found no reason up to now why it shouldn't work with other attributes too. Here's the code in question if you want to debug yourself:

I figured out why it didn't work. When I created the attribute type, I used a special (accented) character in the "Code" field. The contents of the "Code" field are added to the HTML data attribute: data-variant-MyAttributeCodeWithSpecialCharacter = "26"

Due to special character, Javascript could not find it: $ (this) .data ("variant-" + type)

When I renamed the attribute type code in the admin backend, the code was only rewritten in the "mshop_attribute_type" table. The "mshop_attribute" and "mshop_index_attribute" tables have not been updated. So the renaming didn't help.

The solution was to create a new variant attribute type whose code did not contain accented special characters, so it works flawlessly.

Thanks for all the help.

Ameeko commented 2 years ago

Maybe this could improve the system

But neither is critical.

aimeos commented 2 years ago

Only a copy of the attribute type code is used in the attribute so you have to reassign the new type to the existing attributes if you want to rename them. Regarding the special characters, we think about tightening what you can use in the future for types.

aimeos commented 2 years ago

Control characters like new line, etc. and spaces won't be allowed for codes beginning with 2022.04.