TransWikia.com

How to display a selected simple product's image for configurables in the catalog?

Magento Asked by Alex on August 4, 2020

We import configurables without images, but the simples have images (marked by a special attribute).

How can we show the image of a simples as main image of the configurables (thumbnail, base image)

EDIT

There seems to be already similar logic in the core:

MagentoConfigurableProductModelProductTypeConfigurable::setImageFromChildProduct

public function setImageFromChildProduct(MagentoCatalogModelProduct $product)
{
    if (!$product->getData('image') || $product->getData('image') === 'no_selection') {
        foreach ($this->getUsedProducts($product) as $childProduct) {
            if ($childProduct->getData('image') && $childProduct->getData('image') !== 'no_selection') {
                $product->setImage($childProduct->getData('image'));
                break;
            }
        }
    }
    return parent::setImageFromChildProduct($product);
}

Problem is that I need something similar for category (product list) pages and I think they do not use the image but the small image.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP