Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$this->getGallery() on multiple attributes in template yields unintended results. #1512

Closed
blairwinans opened this issue Aug 21, 2015 · 3 comments
Labels
Milestone

Comments

@blairwinans
Copy link
Member

This may simply be a variation on #1511, but I consider it a bug, or at the very least "strange behavior" :)

Say you have two Attributes on a product, images and special_images.

And you call them in your template in different orders, like so:

 //Loads files and renders first image from "images"
echo $this->getGallery('images')->generateMainImage();

//Loads files and renders first image from "special_images" 
echo $this->getGallery('special_images')->generateMainImage();  

//Renders the first image from "special_images", not "images"
echo $this->getGallery('images')->generateMainImage();

The problem lies in L55 of Model\Gallery:: createForProductAttribute() as well as L594 of Product\Standard::generate().

When you call getGallery on the second attribute, you are resetting the files in the Gallery model in the registry, which does not get reset again since you are passing the same model back in return $arrGalleries[$strAttribute].

I know that a lot of the reason you did what you did was for performance reasons, and the easiest workaround on my end is to simply call Model\Gallery:: createForProductAttribute() in the template again or just simply change the order of the output, but the behavior is odd and could trip up others....

Maybe at least documenting the behavior might be all that is needed.

@aschempp aschempp added the bug label Sep 1, 2015
@aschempp aschempp added this to the 2.3.1 milestone Sep 1, 2015
@danielhoover
Copy link

Hello Andreas, hello blairwinans,

I have a bug within my cart that looks like it has something to do with this issue - but before I post a new issue I want to clarify if that might be the same issue.

I've added 7 different products to the cart. Product 1 has a configurable text therefore it is not the exact same product but of same type. All products are rendered when

<td class="col_<?php echo $i++; ?> col_first image"><?php echo $this->getGallery('images', $item['item'])->generateMainImage(); ?></td><?php endif; ?>

is called within iso_collection_default.html5. (like it is in the original template

<td class="col_<?php echo $i++; ?> col_first image"><?php echo $this->getGallery('images', $item['item'])->generateMainImage(); ?></td><?php endif; ?>
)

In my product cart all products are listed:

product 1 text a
product 2
product 3
product 4
product 5
product 1 text b
product 1 text c

now for the images of the corresponding products:

product 1 - image of product 1
product 2 - image of product 2
product 3 - image of product 3
product 4 - image of product 4
product 5 - image of product 5
product 1 - image of product 5 (!!)
product 1 - image of product 5 (!!)

The only solution to remove this issue is (at least what I now tried) to comment/remove

if (!isset($arrGalleries[$strCacheKey])) {
in ProductCollection.php and

And as I debugged through the source code - it seems as if $arrGalleries is somehow mixed up externally and therefore not working. Because once product 1 needs to be displayed after product 5 was rendered the value of product 1 within that $arrGalleries cache for instance in $arrGalleries['product1_images'] is what you expect should be $arrGalleries['product5_images']

Is that the same issue or is it a new one?

Kind regards
Daniel

@aschempp
Copy link
Member

aschempp commented Sep 3, 2015

yeah, I guess that's the same issue…

@aschempp
Copy link
Member

Fixed in 8253a4d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants