/** * Override Remove item */ public function removeAction() { if ($this->getRequest()->getParam('callback')) { $ajaxData = array(); $id = (int) $this->getRequest()->getParam('item'); $item = Mage::getModel('wishlist/item')->load($id); if (!$item->getId()) { return $this->norouteAction(); } $wishlist = $this->_getWishlist($item->getWishlistId()); if (!$wishlist) { return $this->norouteAction(); } try { $item->delete(); $wishlist->save(); } catch (Mage_Core_Exception $e) { Mage::getSingleton('customer/session')->addError($this->__('An error occurred while deleting the item from wishlist: %s', $e->getMessage())); } catch (Exception $e) { Mage::getSingleton('customer/session')->addError($this->__('An error occurred while deleting the item from wishlist.')); } Mage::helper('wishlist')->calculate(); $this->loadLayout(); $sidebarWishlist = ""; if ($this->getLayout()->getBlock('wishlist_sidebar')) { $sidebarWishlist = $this->getLayout()->getBlock('wishlist_sidebar')->toHtml(); } if ($this->getLayout()->getBlock('top.links')) { $toplink = $this->getLayout()->getBlock('top.links')->toHtml(); } $ajaxData['status'] = 1; $ajaxData['wishlist_sidebar'] = $sidebarWishlist; $ajaxData['type_sidebar'] = 'wishlist'; $ajaxData['top_link'] = $toplink; $this->getResponse()->setBody($this->getRequest()->getParam('callback') . '(' . Mage::helper('core')->jsonEncode($ajaxData) . ')'); return; } else { parent::removeAction(); } }
/** * Remove item */ public function removeAction() { $response = array(); $id = (int) $this->getRequest()->getParam('product'); if ($id) { $customer = Mage::getSingleton('customer/session')->getCustomer(); $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true); $wishlist = Mage::getModel('wishlist/item')->getCollection()->addFieldToFilter('wishlist_id', $wishlist->getId())->addFieldToFilter('product_id', $id); $item = $wishlist->getFirstItem(); if (!$item->getId()) { $response['error'] = 'No product available'; return $this->_echoJson($response); } if (!$wishlist) { $response['error'] = 'No wishlist available'; return $this->_echoJson($response); } } else { return parent::removeAction(); } try { $item->delete(); $wishlist->save(); } catch (Mage_Core_Exception $e) { $response['error'] = $this->__('An error occurred while deleting the item from wishlist: %s', $e->getMessage()); return $this->_echoJson($response); } catch (Exception $e) { $response['error'] = $this->__('An error occurred while deleting the item from wishlist.'); return $this->_echoJson($response); } Mage::helper('wishlist')->calculate(); $response['status'] = 'removed'; $response['message'] = $this->__('Product was been removed from your wishlist.'); return $this->_echoJson($response); }