1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class extends Mage_Wishlist_Block_Abstract
35: {
36: 37: 38: 39: 40:
41: protected $_customer;
42:
43: 44: 45: 46: 47:
48: protected $_mapRenderer = 'msrp_rss';
49:
50: 51: 52: 53: 54:
55: protected function _getWishlist()
56: {
57: if (is_null($this->_wishlist)) {
58: $this->_wishlist = Mage::getModel('wishlist/wishlist');
59: $wishlistId = $this->getRequest()->getParam('wishlist_id');
60: if ($wishlistId) {
61: $this->_wishlist->load($wishlistId);
62: if ($this->_wishlist->getCustomerId() != $this->_getCustomer()->getId()) {
63: $this->_wishlist->unsetData();
64: }
65: } else {
66: if($this->_getCustomer()->getId()) {
67: $this->_wishlist->loadByCustomer($this->_getCustomer());
68: }
69: }
70: }
71: return $this->_wishlist;
72: }
73:
74: 75: 76: 77: 78:
79: protected function _getCustomer()
80: {
81: if (is_null($this->_customer)) {
82: $this->_customer = Mage::getModel('customer/customer');
83:
84: $params = Mage::helper('core')->urlDecode($this->getRequest()->getParam('data'));
85: $data = explode(',', $params);
86: $cId = abs(intval($data[0]));
87: if ($cId && ($cId == Mage::getSingleton('customer/session')->getCustomerId()) ) {
88: $this->_customer->load($cId);
89: }
90: }
91:
92: return $this->_customer;
93: }
94:
95: 96: 97: 98: 99:
100: protected function _getTitle()
101: {
102: return Mage::helper('rss')->__('%s\'s Wishlist', $this->_getCustomer()->getName());
103: }
104:
105: 106: 107: 108: 109:
110: protected function _toHtml()
111: {
112:
113: $rssObj = Mage::getModel('rss/rss');
114:
115: if ($this->_getWishlist()->getId()) {
116: $newUrl = Mage::getUrl('wishlist/shared/index', array(
117: 'code' => $this->_getWishlist()->getSharingCode()
118: ));
119:
120: $title = $this->_getTitle();
121: $lang = Mage::getStoreConfig('general/locale/code');
122:
123: $rssObj->_addHeader(array(
124: 'title' => $title,
125: 'description' => $title,
126: 'link' => $newUrl,
127: 'charset' => 'UTF-8',
128: 'language' => $lang
129: ));
130:
131:
132: foreach ($this->getWishlistItems() as $wishlistItem) {
133:
134: $product = $wishlistItem->getProduct();
135: $productUrl = $this->getProductUrl($product);
136: $product->setAllowedInRss(true);
137: $product->setAllowedPriceInRss(true);
138: $product->setProductUrl($productUrl);
139: $args = array('product' => $product);
140:
141: Mage::dispatchEvent('rss_wishlist_xml_callback', $args);
142:
143: if (!$product->getAllowedInRss()) {
144: continue;
145: }
146:
147: $description = '<table><tr><td><a href="' . $productUrl . '"><img src="'
148: . $this->helper('catalog/image')->init($product, 'thumbnail')->resize(75, 75)
149: . '" border="0" align="left" height="75" width="75"></a></td>'
150: . '<td style="text-decoration:none;">'
151: . $this->helper('catalog/output')
152: ->productAttribute($product, $product->getShortDescription(), 'short_description')
153: . '<p>';
154:
155: if ($product->getAllowedPriceInRss()) {
156: $description .= $this->getPriceHtml($product,true);
157: }
158: $description .= '</p>';
159: if ($this->hasDescription($product)) {
160: $description .= '<p>' . Mage::helper('wishlist')->__('Comment:')
161: . ' ' . $this->helper('catalog/output')
162: ->productAttribute($product, $product->getDescription(), 'description')
163: . '<p>';
164: }
165:
166: $description .= '</td></tr></table>';
167:
168: $rssObj->_addEntry(array(
169: 'title' => $this->helper('catalog/output')
170: ->productAttribute($product, $product->getName(), 'name'),
171: 'link' => $productUrl,
172: 'description' => $description,
173: ));
174: }
175: }
176: else {
177: $rssObj->_addHeader(array(
178: 'title' => Mage::helper('rss')->__('Cannot retrieve the wishlist'),
179: 'description' => Mage::helper('rss')->__('Cannot retrieve the wishlist'),
180: 'link' => Mage::getUrl(),
181: 'charset' => 'UTF-8',
182: ));
183: }
184:
185: return $rssObj->createRssXml();
186: }
187:
188: 189: 190: 191: 192: 193: 194:
195: public function getProductUrl($product, $additional = array())
196: {
197: $additional['_rss'] = true;
198: return parent::getProductUrl($product, $additional);
199: }
200:
201: 202: 203: 204: 205: 206: 207:
208: public function addPriceBlockType($type, $block = '', $template = '')
209: {
210: if ($type) {
211: $this->_priceBlockTypes[$type] = array(
212: 'block' => $block,
213: 'template' => $template
214: );
215: }
216: }
217: }
218: