skip to Main Content
public function addItem(Mage_Wishlist_Model_Item $item)
{

    $superAttributes = Mage::app()->getRequest()->getParam('super_attribute');
    if ($item instanceof Mage_Wishlist_Model_Item && isset($superAttributes)) {
        $simpleItem = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($superAttributes, $item->getProduct());
    }

    return parent::addItem($simpleItem);
}

Now my problem is that i want to call the parent function which needs to receive an Mage_Wishlist_Model_Item not a Mage_Catalog_Model_Product

MyCustom_Wishlist_Model_Wishlist extends Mage_Wishlist_Model_Wishlist

How can i get the wishlistitem for the Product $simpleItem

2

Answers


  1. Chosen as BEST ANSWER
    public function addItem(Mage_Wishlist_Model_Item $item)
    {
        $superAttributes = Mage::app()->getRequest()->getParam('super_attribute');
        if ($item instanceof Mage_Wishlist_Model_Item && isset($superAttributes)) {
            $product = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($superAttributes, $item->getProduct());
            $item = Mage::getModel('wishlist/item');
            $storeId = $product->hasWishlistStoreId() ? $product->getWishlistStoreId() : $this->getStore()->getId();
            $qty = 1;
    
            $item->setProductId($product->getId())
                ->setWishlistId($this->getId())
                ->setAddedAt(now())
                ->setStoreId($storeId)
                ->setOptions($product->getCustomOptions())
                ->setProduct($product)
                ->setQty($qty)
                ->save();
        }
    
        return parent::addItem($item);
    }
    

    This works for me now but i didn't figure out how to set the $qty yet


  2. Have you checked this URL?
    https://magento.stackexchange.com/questions/19678/how-do-i-add-to-wishlist-programatically

    It’s the native way to add a product to wishlist.

    If you don’t want to change the parameter type then you may remove the $item type check from your code (it’s not necessary):

    $item instanceof Mage_Wishlist_Model_Item
    

    Hope it helps you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search