1

I found the following code for adding an item to a wishlist with configuration

$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$product = Mage::getModel('catalog/product')->load($productId);

//NOTE! I'm not sure this array format is correct so that may be the problem
$buyRequest = new Varien_Object(array('color'=>'blue','size'=>'large')); // any possible options that are configurable and you want to save with the product

$result = $wishlist->addNewItem($product, $buyRequest);
$wishlist->save();

The add to wishlist works successfully, except that either a) the color and size configuration are not stored anywhere, b) they're stored somewhere I don't know or c) they're not correct in syntax. Can someone please narrow this down and clarify?

1

The array to pass the product options in incorrect. You can try like below :

$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);
  • Does the optionId need to correspond to anything database-wise? i.e. to an entity_id in some options_.. table? – Oliver Williams Jun 25 '15 at 9:08
  • Also to note, my question is to where the option information is actually stored. – Oliver Williams Jun 25 '15 at 9:12

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.