The question is tagged with ce-1.7.0.2 but for future reference, if you are using ce-1.9.1.0 ee-1.14.1 or higher, the feature is already built in, with the so-called Configurable Swatches which allow "Product Image Swap".
You can enable this feature in System > Configuration > CATALOG > Configurable Swatches
The following animation shows how this works on product listing and
product detail pages:
Swap Images Defined by Option Label
One way to configure swap images is to upload images to a configurable
product with labels exactly matching the specific option labels (for
example, Royal Blue
).
Here is an example of a configurable product image gallery images that
contains images for three colors:
Swap Images Defined by Base Image
Another way to configure swap images is to upload base images to each
child product of the configurable product.
Here is an example of a Royal Blue child product with an attached base
image:
Source and full documentation: http://docs.magento.com/m1/ce/user_guide/catalog/product-configurable-swatch.html
Try this module:
File : app\etc\modules\Rkt_CrossSell.xml
<?xml version="1.0"?>
<config>
<modules>
<Rkt_CrossSell>
<active>true</active>
<codePool>community</codePool>
<depends>
<Mage_Catalog />
</depends>
</Rkt_CrossSell>
</modules>
</config>
File : app\code\community\Rkt\CrossSell\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Rkt_CrossSell>
<version>1.0.0</version>
</Rkt_CrossSell>
</modules>
<global>
<helpers>
<rkt_crossell>
<class>Rkt_CrossSell_Helper</class>
</rkt_crossell>
</helpers>
<blocks>
<rkt_crossell>
<class>Rkt_CrossSell_Block</class>
</rkt_crossell>
</blocks>
</global>
<frontend>
<layout>
<updates>
<rkt_crossell>
<file>rkt_crossell.xml</file>
</rkt_crossell>
</updates>
</layout>
</frontend>
</config>
File : app\code\community\Rkt\CrossSell\Block\Catalog\Product\View\Crosssell.php
<?php
class Rkt_CrossSell_Block_Catalog_Product_View_Crosssell extends Mage_Checkout_Block_Cart_Crosssell
{
/**
* Get crosssell items
*
* @return array
*/
public function getItems()
{
$items = $this->getData('items');
if (is_null($items)) {
$items = $this->getProduct()->getCrossSellProducts();
$this->setData('items', $items);
}
return $items;
}
}
File : app\code\community\Rkt\CrossSell\Helper\Data.php
<?php
class Rkt_CrossSell_Helper_Data extends Mage_Core_Helper_Abstract
{
}
File : app\design\frontend\base\default\layout\rkt_crossell.xml
<?xml version="1.0"?>
<layout>
<catalog_product_view>
<reference name="product.info">
<block type="rkt_crossell/catalog_product_view_crosssell" name="product.view.crosssell" as="crosssell" template="checkout/cart/crosssell.phtml" />
</reference>
</catalog_product_view>
</layout>
Now in your view.phtml add this code in the appropriate position
<?php echo $this->getChildHtml('crosssell') ?>
clear your cache and re-run product page.
Note: please check you have specify products cross sell for appropriate product.
I hope this will help you.
Best Answer
Hi you can change easy by layout handler. when magento is call a configurable products it add
PRODUCT_TYPE_configurable
handler to current layoutex:
create local.xml at app/design/frontent/yourpackage/yourtempate/layout/ and add this code