Magento - How to link the Configurable Product image to the Simple Product image?

Niels picture Niels · Feb 21, 2011 · Viewed 9.8k times · Source

This is the situation:

I have a configurable product with several simple products. These simple products need to have the same product image as the configurable product. Currently I have to upload the same image to each simple product over and over again.

Is there a way to link the product image of the configurable product to the simple products?

Some of my products have 30 simple products in 1 configurable product and it is overkill/annoying to upload the same image 30 times.

I hope someone can help me with this problem!

Thanks in advance!

Answer

Jonathan Day picture Jonathan Day · Feb 21, 2011

Insert this into your DOCROOT\app\design\frontend\<pachage>\<theme>\template\catalog\product\view\media.phtml after $_product = $this->getProduct();

$_parentIdArray = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($_product->getId());
if(sizeof($_parentIdArray)==1 && Mage::getModel('catalog/product')->load($_parentIdArray[0])->getTypeId() == 'configurable'){
  $_product = Mage::getModel('catalog/product')->load($_parentIdArray[0]);
}

That will use the images belonging to the parent configurable product if the simple product has a single parent of type configurable.

EDIT

To use this in the list view, open DOCROOT\app\design\frontend\<pachage>\<theme>\template\catalog\product\list.phtml and insert the same code block in 2 locations:

  • line 45 after <?php foreach ($_productCollection as $_product): ?> (inside the <?php ?> wrappers)
  • line 106 (approx, might be different in your theme) after <?php $i=0; foreach ($_productCollection as $_product): ?>

Both locations are required to deal with the grid view and list view versions of the page.

HTH,
JD