4

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.

  • I got the solution for above please go through the below Code:<br><br><br> $wishlist=Mage::helper('wishlist')->getWishlist();<br> $storeId = Mage::app()->getStore()->getId();<br> $model = Mage::getModel('catalog/product');<br> $_product = $model->load($productId);<br> $params = array('product' => $productId,<br> 'qty' => 1,<br> 'store_id' => $storeId,<br> 'options' => array('optionId'=>'optionValue')<br> );<br> $request = new Varien_Object();<br> $request->setData($params);<br> $result = $wishlist->addNewItem($_product, $request);<br> – Amit Dwivedi Aug 11 '14 at 8:52
5

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);
  • 2
    This would only work for me if the options param was renamed super_attribute. – Willster Jul 15 '15 at 11:49
0

Go to file: app/design/frontend/your_package/your_template/catalog/product/view/addto.phtml and change this line:

<li><a href="<?php echo $_wishlistSubmitUrl ?>" onclick="productAddToCartForm.submitLight(this, this.href); return false;" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>

to:

<li><a href="<?php echo $_wishlistSubmitUrl ?>" onclick="productAddToCartForm.submit(this, this.href); return false;" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>

I have changed productAddToCartForm.submitLight to productAddToCartForm.submit

I then made a hidden field to display the error:

<div class="validation-advice hidden" id="advice-required-entry-size-select">Please select product size.</div>

I added this in file: app/design/frontend/your_package/your_template/catalog/product/view/type/options/configurable.phtml Add it wherever you want to display the error.

and in the same configurable.phtml file i added this small script:

$('.link-wishlist').on('click',function(){
   if($('.size-select').val() == ''){
       $('#advice-required-entry-size-select').removeClass('hidden');
     }
    else{
         $('#advice-required-entry-size-select').addClass('hidden');
     }
  });

where .size-select is a class to my size options.

  • Twinkal, can you please tell us will we achieve the task mentioned in the question? – Haris May 20 '16 at 6:46
  • 1
    It did work for me Haris. I don't know your exact requirement, may be its worth a shot. – Twinkal May 22 '16 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.