I am trying to add products from the admin create order screen straight into the users wishlist programmatically however it doesn't seem to be working.
$quote = Mage::getSingleton('adminhtml/session_quote');
$currentQuote = $quote->getQuote();
$customer = $currentQuote->getCustomer();
$items = $currentQuote->getAllVisibleItems();
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer->getId(), true);
Mage::register('wishlist', $wishlist);
foreach ($items as $item)
{
$productId = $item->getProductId();
$product = Mage::getModel('catalog/product')->load($productId);
$buyRequest = $item->getBuyRequest();
$result = $wishlist->addNewItem($product, $buyRequest);
if(is_string($result))
{
Mage::throwException($result);
}
$wishlist->save();
Mage::dispatchEvent(
'wishlist_add_product',
array(
'wishlist' => $wishlist,
'product' => $product,
'item' => $result
)
);
Mage::helper('wishlist')->calculate();
}
Mage::getSingleton('core/session')->addSuccess("Quote sent successfully to customer!");
Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/index'));
I'm not to sure what is going on. I am getting no errors in the log or exceptions being thrown however no products end up in the customer's wishlist.