Question

In the core wishlist indexcontroller I am replacing the configurable product with it's configured child product before i add it to the wishlist using:

    $productId = (int)$this->getRequest()->getParam('product');
    $product = Mage::getModel('catalog/product')->load($productId);
    if($product->getTypeId() == 'configurable'){
        $params = $this->getRequest()->getParams();
        $child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
        $product = Mage::getModel('catalog/product')->load($child->getId());
    }

This works well to get the simple product into the wishlist. However, when I add a different configuration (color = red) to the wishlist it will replace the previous configuration(color = blue) with a new one (color = red). When I add the same configuration(color = red) again it will delete that configuration entirely leaving the wishlist empty.

Without the above alteration, the configurable item will not be replaced and the quantity will simply iterate upon addition of the same item.

Thx

Was it helpful?

Solution

Did some testing on a Magento 1.9 installation and figured out how to swap the products. The trick lies in the $buyRequest

$buyRequest = new Varien_Object($requestParams); // this is the original code

[...]

$productId = (int)$this->getRequest()->getParam('product');
$product = Mage::getModel('catalog/product')->load($productId);
if($product->getTypeId() == 'configurable'){
   $params = $this->getRequest()->getParams();
   $child = $product->getTypeInstance(true)->getProductByAttributes($params['super_attribute'], $product);
   $product = Mage::getModel('catalog/product')->load($child->getId());
   $buyRequest->setData('product', $child->getId());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top