Magento – Add Product to Wishlist with a Selected Custom option

custom-optionsproductwishlist

I used below code to add a product pragmatically to a Wishlist, and is working successfully-

  $customer = Mage::getModel('customer/customer');
  $wishlist = Mage::getModel('wishlist/wishlist');
  $product = Mage::getModel('catalog/product');

  $customer_id = 1;
  $product_id = 1;
  $customer->load($customer_id);
  $wishlist->loadByCustomer($customer_id);
  $wishlist->addNewItem($product->load($product_id));

My Question is that if I am having a Product with a Custom Option, then how could i add that selected option to a wishlist.

Completely, I need a Code which can add Product to a Wishlist with a selected custom option.

Please help me on this.

Best Answer

I got the solution for above please go through the below Code:

$wishlist=Mage::helper('wishlist')->getWishlist();
$storeId = Mage::app()->getStore()->getId();
$model = Mage::getModel('catalog/product');
$_product = $model->load($productId);
$params = array('product' => $productId,
        'qty' => 1,
        'store_id' => $storeId,
        'options' => array('optionId'=>'optionValue')
    );
$request = new Varien_Object();
$request->setData($params);
$result = $wishlist->addNewItem($_product, $request);
Related Topic