imagemagentoswitch-statementproductconfigurable

Magento, class to switch configurable product image


I trying to use baobaz class and magentowiki code to implement magento store and switch image when user select a different product attribute, however with baobaz class i can change image only once and cant back with others products images when the user select different attribute. --eg (i select blue tshirt color attribute and the class will return the result with the photo, then i select red attribute and the class stuck on the first image). With magentowiki nothing happens

class Baobaz_Imageswitch_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $prod_id  = (int) $this->getRequest()->getParam('prod_id');
        $color_value  = (int) $this->getRequest()->getParam('color_id');
        $product=Mage::getModel('catalog/product')->load($prod_id);
        if($color_value) {
            $allProducts = $product->getTypeInstance(true)->getUsedProducts(null, $product);      
            foreach ($allProducts as $prod) {
                if ($prod->getData('image_storing') && $prod->getColor()==$color_value) { // && $prod->isSaleable() 
                    break;
                }
            }           
            $prod_full=Mage::getModel('catalog/product')->load($prod->getId());
            Mage::register('product', $prod_full);
        }
        else {
            Mage::register('product', $product);
        }
        $this->loadLayout();     
        $this->renderLayout();
    }
}


Solution

  • The Simple Configurable Products extension from Organic Internet has an image switcher which we've used successfully on a couple of projects. Be aware that it changes how pricing of the configurable products works, but it's an excellent extension. It's free, open source, and available on Github and Magento Connect.