Shin_P Posted January 26, 2023 Share Posted January 26, 2023 Hello everyone Is there a way to show all the combination images on the product page, instead of only the image of the currently selected combination? The new (1.7) behavior is to show only the image associated to the selected combination, hiding all the other pictures. On 1.6 and earlier, all images were shown. And that made sense, as it was engaging for the user to see that there were other colors, other sizes, multiple pictures for multiple attribute combinations. I know there's a workaround (to assign all the images to every combination), but that just doesn't make sense. Is there a way to revert to the previous behavior? All these changes in 1.7 really dont make any sense. Thank you for any help you could give me. And please don't point me to a paid module, because it would really look like that developers have stripped the base CMS just to push more module sales.. Link to comment Share on other sites More sharing options...
s4lvozesta Posted January 27, 2023 Share Posted January 27, 2023 how is your case different from this one? I might misunderstood you https://www.prestashop.com/forums/topic/963580-showing-thumbnails-for-all-combinations/#comment-3078782 Link to comment Share on other sites More sharing options...
Shin_P Posted January 27, 2023 Author Share Posted January 27, 2023 thank you, i tried, but it doesnt work on 1.7.8.8 thumbnails are displayed, but the link between image and combination is lost in the process Link to comment Share on other sites More sharing options...
JBW Posted January 29, 2023 Share Posted January 29, 2023 My module "Please choose attributes" has an option to always display all combination images https://addons.prestashop.com/en/product.php?id_product=47851 Link to comment Share on other sites More sharing options...
Shin_P Posted January 29, 2023 Author Share Posted January 29, 2023 hi and thank you for replying I checked the backoffice demo on your module page is it this one? Produkt-Eigenschaften - Bitte wählen - Variantenauswahl als Pflicht if so, note that the demo doesn't work (see the attached screenshot) even so, still kinda sucks having to pay 70€ to get back a feature that has always been included in prestashop (until v. 1.7) Link to comment Share on other sites More sharing options...
ps8modules Posted January 29, 2023 Share Posted January 29, 2023 (edited) Hi @Shin_P, if you have a selected image in the administration for the combination, not all images will be displayed, but only the ones you have selected. If you want to display all the images you have uploaded to the product, it can be easily fixed in the database. Can you please put a screenshot of how you have the image association set up in the administration and the selected combination? Edited January 29, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted January 29, 2023 Share Posted January 29, 2023 Check the ps_product_attribute_image table in the database. All associated images for the combination are stored here 😉 Link to comment Share on other sites More sharing options...
idnovate.com Posted February 1, 2023 Share Posted February 1, 2023 (edited) On 1/26/2023 at 11:19 PM, Shin_P said: Hello everyone Is there a way to show all the combination images on the product page, instead of only the image of the currently selected combination? The new (1.7) behavior is to show only the image associated to the selected combination, hiding all the other pictures. On 1.6 and earlier, all images were shown. And that made sense, as it was engaging for the user to see that there were other colors, other sizes, multiple pictures for multiple attribute combinations. I know there's a workaround (to assign all the images to every combination), but that just doesn't make sense. Is there a way to revert to the previous behavior? All these changes in 1.7 really dont make any sense. Thank you for any help you could give me. And please don't point me to a paid module, because it would really look like that developers have stripped the base CMS just to push more module sales.. Edit function filterImagesForCombination() from class ProductLazyArray (src/Adapter/Presenter/Product/ProductLazyArray.php) : private function filterImagesForCombination(array $images, int $productAttributeId) { return $images; ... } https://github.com/PrestaShop/PrestaShop/blob/2e5e9c6720f562e73f005ff3c9d21ea98da9389b/src/Adapter/Presenter/Product/ProductLazyArray.php#L736 Edited February 1, 2023 by idnovate.com (see edit history) 1 Link to comment Share on other sites More sharing options...
Shin_P Posted February 2, 2023 Author Share Posted February 2, 2023 not really a fix if I change combination the picture remains the same, as if the associated image is lost thank you for trying tho Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 So I understood it now. What else should you have written as a request? 1. in thumbnail list i need to see all images 2. when I change the combination, the associated image of the combination is displayed 1 Link to comment Share on other sites More sharing options...
Shin_P Posted February 2, 2023 Author Share Posted February 2, 2023 (edited) like it was on 1.6, on any other major ecommerce CMS and how logic would want.. All product pictures are always displayed on the product page If I change combination, and there is a picture assigned to that specific combination, the main picture switches to that image bonus points: you click on the picture -> combination is switched Edited February 2, 2023 by Shin_P mother -> other lol (see edit history) 1 Link to comment Share on other sites More sharing options...
Shin_P Posted February 2, 2023 Author Share Posted February 2, 2023 geez coming from 1.6, this 1.7 version looks sooooooo dumb Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 Ok. 1. Modify ./src/Adapter/Presenter/Product/ProductLazyArray.php 2. find function fillImages 3. replace to: private function fillImages(array $product, Language $language): void { // Get all product images, including potential cover $productImages = $this->imageRetriever->getAllProductImages( $product, $language ); // Get filtered product images matching the specified id_product_attribute $this->product['images'] = $productImages; $this->product['default_image'] = reset($this->product['images']); foreach ($this->product['images'] as $image) { // If one of the image is a cover it is used as such if (isset($image['cover']) && null !== $image['cover']) { $this->product['default_image'] = $image; break; } } // Get default image for selected combination (used for product page, cart details, ...) if ($product['id_product_attribute']){ foreach ($productImages as $image) { if (in_array($product['id_product_attribute'], $image['associatedVariants'])) { $this->product['default_image'] = $image; } } } // Get generic product image, used for product listing if (isset($product['cover_image_id'])) { // First try to find cover in product images foreach ($productImages as $productImage) { if ($productImage['id_image'] == $product['cover_image_id']) { $this->product['cover'] = $productImage; break; } } // If the cover is not associated to the product images it is fetched manually if (!isset($this->product['cover'])) { $coverImage = $this->imageRetriever->getImage(new Product($product['id_product'], false, $language->getId()), $product['cover_image_id']); $this->product['cover'] = array_merge($coverImage, [ 'legend' => $coverImage['legend'], ]); } } // If no cover fallback on default image if (!isset($this->product['cover'])) { $this->product['cover'] = $this->product['default_image']; } } Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 Only the combination does not change when you click on the image in the thumbnail list. Because one image can be associated with multiple combinations. But even that can be solved, but I don't have time for it. 1 Link to comment Share on other sites More sharing options...
Shin_P Posted February 2, 2023 Author Share Posted February 2, 2023 (edited) almost! now all pictures are shown but it it looks like the first picture shown AS MAIN is the last of the array instead of the first (definitely not the cover) prolly have to reverse the array? my php is sooooo rusted Edited February 2, 2023 by Shin_P (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 (edited) The fault lies elsewhere. It works fine for me. Edited February 2, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
Shin_P Posted February 2, 2023 Author Share Posted February 2, 2023 (edited) have you tried assigning all pictures to the default combination? let me run some tests on a vanilla box Edited February 2, 2023 by Shin_P (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 3 minutes ago, Shin_P said: have you tried assigning all pictures to the default combination? Yes Link to comment Share on other sites More sharing options...
Shin_P Posted February 2, 2023 Author Share Posted February 2, 2023 (edited) Testing on the same product with originally only one picture (vanilla 1.7.8.8 with demo products) Steps: I added 2 new pictures to the product , without assigning any new pic to a combination -> only the first old picture shown on product page (not the new ones) (NOT OK) I assigned one of the 2 new photos (only that) to a non-default combination -> default combination shows the new picture in the carousel below (OK). If I switch to the combination with the new pic assigned, the first picture is NOT shown on the carousel (NOT OK) I assigned the third picture to another combination -> everything working as intended If no photos are assigned to a combination, but only loaded on the main product tab, they are not shown in the carousel. So, without changing the code above, this fix works only if every picture is assigned to at least one combination. Which is great, but not optimal. Thank you very much tho! I feel you are almost there! Edited February 2, 2023 by Shin_P formatting (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 Just change the condition in the function. Link to comment Share on other sites More sharing options...
Shin_P Posted February 2, 2023 Author Share Posted February 2, 2023 Another bug: - if ALL photos are assigned to the default combination, the last picture is shown twice.. bummer! Link to comment Share on other sites More sharing options...
apavlinets Posted October 29 Share Posted October 29 Hi. Did you manage to implement the task of displaying all images that are linked to different combinations? Maybe there is also a solution that automatically switches the combination when hovering over a particular image? True, I am already working on 8.2 Link to comment Share on other sites More sharing options...
Chisla Posted Wednesday at 10:50 AM Share Posted Wednesday at 10:50 AM (edited) For 8.2 /src/Adapter/Presenter/Product/ProductLazyArray.php function filterImagesForCombination private function filterImagesForCombination(array $images, int $productAttributeId) { $filteredImages = []; // flag to set cover to first associated image $need_set_cover_image = true; // first we collect all the associated images, the first one we put a cover foreach ($images as $image) { if (in_array($productAttributeId, $image['associatedVariants'])) { if($need_set_cover_image) { $image['cover'] = 1; $need_set_cover_image = false; } else { $image['cover'] = null; } $filteredImages[] = $image; } } // add all images not associated with combinations to the array and remove the cover foreach ($images as $image) { if (empty($image['associatedVariants'])) { $image['cover'] = null; $filteredImages[] = $image; } } return (0 === count($filteredImages)) ? $images : $filteredImages; } Edited Wednesday at 10:51 AM by Chisla (see edit history) Link to comment Share on other sites More sharing options...
DsToys Posted 9 hours ago Share Posted 9 hours ago Hi, i'm trying to achieve this in a 1.7.6.5 versión of prestashop, but i have an error when i change the code of FillImages in /src/Adapter/Presenter/Product/ProductLazyArray.php En 13/11/2024 a las 4:50 AM, Chisla dijo: For 8.2 /src/Adapter/Presenter/Product/ProductLazyArray.php function filterImagesForCombination private function filterImagesForCombination(array $images, int $productAttributeId) { $filteredImages = []; // flag to set cover to first associated image $need_set_cover_image = true; // first we collect all the associated images, the first one we put a cover foreach ($images as $image) { if (in_array($productAttributeId, $image['associatedVariants'])) { if($need_set_cover_image) { $image['cover'] = 1; $need_set_cover_image = false; } else { $image['cover'] = null; } $filteredImages[] = $image; } } // add all images not associated with combinations to the array and remove the cover foreach ($images as $image) { if (empty($image['associatedVariants'])) { $image['cover'] = null; $filteredImages[] = $image; } } return (0 === count($filteredImages)) ? $images : $filteredImages; } Can you help me to solve this, i really need this feature in my site (if don't i have to buy a module...... not the best solution for me) Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now