Jump to content

Edit History

Chisla

Chisla

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;
    }

 

Chisla

Chisla

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 carpet
        foreach ($images as $image) {
            if (empty($image['associatedVariants'])) {
                $image['cover'] = null;
                $filteredImages[] = $image;
            }
        }
        return (0 === count($filteredImages)) ? $images : $filteredImages;
    }

 

×
×
  • Create New...