*/ class Mage_Rss_Block_Wishlist extends Mage_Wishlist_Block_Abstract { /** * Customer instance * * @var Mage_Customer_Model_Customer */ protected $_customer; /** * Default MAP renderer type * * @var string */ protected $_mapRenderer = 'msrp_rss'; /** * Retrieve Wishlist model * * @return Mage_Wishlist_Model_Wishlist */ protected function _getWishlist() { if (is_null($this->_wishlist)) { $this->_wishlist = Mage::getModel('wishlist/wishlist'); $wishlistId = $this->getRequest()->getParam('wishlist_id'); if ($wishlistId) { $this->_wishlist->load($wishlistId); if ($this->_wishlist->getCustomerId() != $this->_getCustomer()->getId()) { $this->_wishlist->unsetData(); } } else { if($this->_getCustomer()->getId()) { $this->_wishlist->loadByCustomer($this->_getCustomer()); } } } return $this->_wishlist; } /** * Retrieve Customer instance * * @return Mage_Customer_Model_Customer */ protected function _getCustomer() { if (is_null($this->_customer)) { $this->_customer = Mage::getModel('customer/customer'); $params = Mage::helper('core')->urlDecode($this->getRequest()->getParam('data')); $data = explode(',', $params); $cId = abs(intval($data[0])); if ($cId && ($cId == Mage::getSingleton('customer/session')->getCustomerId()) ) { $this->_customer->load($cId); } } return $this->_customer; } /** * Build wishlist rss feed title * * @return string */ protected function _getTitle() { return Mage::helper('rss')->__('%s\'s Wishlist', $this->_getCustomer()->getName()); } /** * Render block HTML * * @return string */ protected function _toHtml() { /* @var $rssObj Mage_Rss_Model_Rss */ $rssObj = Mage::getModel('rss/rss'); if ($this->_getWishlist()->getId()) { $newUrl = Mage::getUrl('wishlist/shared/index', array( 'code' => $this->_getWishlist()->getSharingCode() )); $title = $this->_getTitle(); $lang = Mage::getStoreConfig('general/locale/code'); $rssObj->_addHeader(array( 'title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang )); /** @var $wishlistItem Mage_Wishlist_Model_Item*/ foreach ($this->getWishlistItems() as $wishlistItem) { /* @var $product Mage_Catalog_Model_Product */ $product = $wishlistItem->getProduct(); $productUrl = $this->getProductUrl($product); $product->setAllowedInRss(true); $product->setAllowedPriceInRss(true); $product->setProductUrl($productUrl); $args = array('product' => $product); Mage::dispatchEvent('rss_wishlist_xml_callback', $args); if (!$product->getAllowedInRss()) { continue; } $description = '' . '
' . $this->helper('catalog/output') ->productAttribute($product, $product->getShortDescription(), 'short_description') . '

'; if ($product->getAllowedPriceInRss()) { $description .= $this->getPriceHtml($product,true); } $description .= '

'; if ($this->hasDescription($product)) { $description .= '

' . Mage::helper('wishlist')->__('Comment:') . ' ' . $this->helper('catalog/output') ->productAttribute($product, $product->getDescription(), 'description') . '

'; } $description .= '

'; $rssObj->_addEntry(array( 'title' => $this->helper('catalog/output') ->productAttribute($product, $product->getName(), 'name'), 'link' => $productUrl, 'description' => $description, )); } } else { $rssObj->_addHeader(array( 'title' => Mage::helper('rss')->__('Cannot retrieve the wishlist'), 'description' => Mage::helper('rss')->__('Cannot retrieve the wishlist'), 'link' => Mage::getUrl(), 'charset' => 'UTF-8', )); } return $rssObj->createRssXml(); } /** * Retrieve Product View URL * * @param Mage_Catalog_Model_Product $product * @param array $additional * @return string */ public function getProductUrl($product, $additional = array()) { $additional['_rss'] = true; return parent::getProductUrl($product, $additional); } /** * Adding customized price template for product type, used as action in layouts * * @param string $type Catalog Product Type * @param string $block Block Type * @param string $template Template */ public function addPriceBlockType($type, $block = '', $template = '') { if ($type) { $this->_priceBlockTypes[$type] = array( 'block' => $block, 'template' => $template ); } } }