Magento - How to show the same images for product

2019-08-17 01:36发布

问题:

I created a bundled product following the instructions on the Magento site to enable it to have several sizes. See attached image:

I'm supposing that when I do the Quick simple product creation, it doesn't automatically add the same images. But since the option is only for size, the image should be the same. The problem is, when I go to the cart or checkout page or any other page, there is no image for the product. The combination of my products with the sizes, that s over 230 products, so re-uploading all the images is a nightmare.

Question is, how can I have the system use the same image for all the different sizes?

Thanks.

回答1:

I had similar problem with configurable products. I wanted the image which I assign to the main product to be added also to all options. So I created an extension and observed catalog_product_save_after event. Then I added this kind of code in my observer:

    $product = $observer->getEvent()->getProduct();         
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
        {
            $main_image = $product->getImage();
            if($main_image != "no_selection")
            {
                $productTypeIns = $product->getTypeInstance(true);
                $childIds = $productTypeIns->getChildrenIds($product->getId());
                $importDir = Mage::getBaseDir('media') . DS . 'catalog/product';
                foreach ($childIds as $childId) 
                {
                    foreach($childId as $_childId) 
                    {
                        $childProduct = Mage::getModel('catalog/product')->load($_childId);  //You get your child products here
                        if ($childProduct->getImage()=="no_selection")
                        {
                            $childProduct->addImageToMediaGallery($importDir.$main_image,array ('image','small_image','thumbnail'),false,false);
                            $childProduct->save();
                        }
                    }           
                }
            }
        }


标签: magento