Product Image change with Conditional Product attribute selection

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
I am using Version 3.80.

we have an option of changing product image when selecting a product attribute.
This works so far good. but it stops working when there are conditional product attributes.
If I remove the condition from product attributes, then it works fine.
6 years ago
Could you please provide a complete list of steps to reproduce the issue?
6 years ago
Sure.

Create a Product.
Create a product attributes ex. Image Squares. 3 values. Edit a value and upload square image and product image.
Create another product attribute. Image squares. 3 values. Edit a value and upload square image and product image.
add a condition that if a value from first attribute is selected then only second product attribute should appear.
The first attribute selection will change the product image. The second won't.
Now if you remove the condition, second one selection will also work.
6 years ago
vkotecha91 wrote:
Sure.

Create a Product.
Create a product attributes ex. Image Squares. 3 values. Edit a value and upload square image and product image.
Create another product attribute. Image squares. 3 values. Edit a value and upload square image and product image.
add a condition that if a value from first attribute is selected then only second product attribute should appear.
The first attribute selection will change the product image. The second won't.
Now if you remove the condition, second one selection will also work.


Update :

correction in the steps -

1. Create a Product.
2. Create a product attributes ex. Image Squares. 3 values. Edit a value and upload square image and product image.
3. Create another product attribute. Image squares. 3 values. Edit a value and upload square image and product image.
4. add a condition on second attribute that if a value from first attribute is selected then only second product attribute should appear.
5. The first attribute selection will change the product image. The second won't.
6. Now if you remove the product image from first attribute, then second attribute selection will work.
6 years ago
vkotecha91 wrote:
Sure.

Create a Product.
Create a product attributes ex. Image Squares. 3 values. Edit a value and upload square image and product image.
Create another product attribute. Image squares. 3 values. Edit a value and upload square image and product image.
add a condition that if a value from first attribute is selected then only second product attribute should appear.
The first attribute selection will change the product image. The second won't.
Now if you remove the condition, second one selection will also work.


Update :

even after removing condition,if you select the attribute 2 directly, then it changes the product image.
Selecting first attribute,and then selecting second also doesn't work.

after digging, i figure out that ShoppingController's method ProductDetails_AttributeChange possibly giving the problem.

in the method, to load picture based on selection, following code is written


//just load (return) the first found picture (in case if we have several distinct attributes with associated pictures)
//actually we're going to support pictures associated to attribute combinations (not attribute values) soon. it'll more flexible approach

var attributeValues = _productAttributeParser.ParseProductAttributeValues(attributeXml);
var attributeValueWithPicture = attributeValues.FirstOrDefault(x => x.PictureId > 0);


here i get two attributeValues both have PictureId > 0 and it needs to pick the one with selection choice, but the code is picking first or default so it doesn't load the correct image.

Please atleast guide me what to do to load correct image.
6 years ago
Thank a lot! We'll investigate it - https://github.com/nopSolutions/nopCommerce/issues/2339
6 years ago
Is there a solution for this issue? I too have a similar problem where the main image will change on say a color selection, but if a product has a 2nd attribute, the main image does not change. it seems that the image will only change for 1 attribute only, not 2.
6 years ago
vkotecha91 wrote:
Sure.

Create a Product.
Create a product attributes ex. Image Squares. 3 values. Edit a value and upload square image and product image.
Create another product attribute. Image squares. 3 values. Edit a value and upload square image and product image.
add a condition that if a value from first attribute is selected then only second product attribute should appear.
The first attribute selection will change the product image. The second won't.
Now if you remove the condition, second one selection will also work.

Update :

even after removing condition,if you select the attribute 2 directly, then it changes the product image.
Selecting first attribute,and then selecting second also doesn't work.

after digging, i figure out that ShoppingController's method ProductDetails_AttributeChange possibly giving the problem.

in the method, to load picture based on selection, following code is written


//just load (return) the first found picture (in case if we have several distinct attributes with associated pictures)
//actually we're going to support pictures associated to attribute combinations (not attribute values) soon. it'll more flexible approach

var attributeValues = _productAttributeParser.ParseProductAttributeValues(attributeXml);
var attributeValueWithPicture = attributeValues.FirstOrDefault(x => x.PictureId > 0);


here i get two attributeValues both have PictureId > 0 and it needs to pick the one with selection choice, but the code is picking first or default so it doesn't load the correct image.

Please atleast guide me what to do to load correct image.


I've got the same problem. Here is a solution that might work. I know it's super duper uncool to adjust the core but because this bug is present in 3.9 and previous and because the topic isn't solved on github yet here is a small fix that might help you out.
Just select the last item from the list that way you will change the picture to what is selected even when it has multiple conditions:

In Nop.Web.Controllers ShoppingCartController go to  ProductDetails_AttributeChange method +- line 1001

// comment out this line  var attributeValueWithPicture = attributeValues.FirstOrDefault(x => x.PictureId > 0);
/* add this line  */      var attributeValueWithPicture = attributeValues.LastOrDefault();

That worked for me. Please note changing the core is not good practice and remember when you update Nop Commerce the Nop team could have an other and probably much better approach.
6 years ago
And finally done.
Now you can set images per attribute combination. Changes are here.
Thanks for the suggestion.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.