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 Mage_XmlConnect_Block_Wishlist extends Mage_Wishlist_Block_Customer_Wishlist
35: {
36: 37: 38: 39: 40:
41: protected function _toHtml()
42: {
43:
44: $wishlistXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<wishlist></wishlist>');
45: 46: 47:
48: $request= $this->getRequest();
49: $offset = (int)$request->getParam('offset', 0);
50: $count = (int)$request->getParam('count', 0);
51: $offset = $offset < 0 ? 0 : $offset;
52: $count = $count <= 0 ? 1 : $count;
53: $hasMoreItems = 0;
54: if ($offset + $count < $this->getWishlistItems()->getSize()) {
55: $hasMoreItems = 1;
56: }
57: $this->getWishlistItems()->getSelect()->limit($count, $offset);
58:
59: $wishlistXmlObj->addAttribute('items_count', $this->getWishlistItemsCount());
60: $wishlistXmlObj->addAttribute('has_more_items', $hasMoreItems);
61:
62: if ($this->hasWishlistItems()) {
63: 64: 65:
66: foreach ($this->getWishlistItems() as $item) {
67:
68: $itemXmlObj = $wishlistXmlObj->addChild('item');
69:
70: $itemXmlObj->addChild('item_id', $item->getWishlistItemId());
71: $itemXmlObj->addChild('entity_id', $item->getProductId());
72: $itemXmlObj->addChild('entity_type_id', $item->getProduct()->getTypeId());
73: $itemXmlObj->addChild('name', $wishlistXmlObj->escapeXml($item->getName()));
74: $itemXmlObj->addChild('in_stock', (int)$item->getProduct()->getStockItem()->getIsInStock());
75: $itemXmlObj->addChild('is_salable', (int)$item->getProduct()->isSalable());
76: 77: 78:
79: if ($item->getProduct()->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE
80: || $item->getProduct()->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
81: $item->getProduct()->setHasOptions(true);
82: }
83: $itemXmlObj->addChild('has_options', (int)$item->getProduct()->getHasOptions());
84:
85: $icon = $this->helper('catalog/image')->init($item->getProduct(), 'small_image')
86: ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small'));
87:
88: $iconXml = $itemXmlObj->addChild('icon', $icon);
89:
90: $file = Mage::helper('xmlconnect')->urlToPath($icon);
91: $iconXml->addAttribute('modification_time', filemtime($file));
92:
93: $description = $wishlistXmlObj->escapeXml($item->getDescription());
94: $itemXmlObj->addChild('description', $description);
95:
96: $addedDate = $wishlistXmlObj->escapeXml($this->getFormatedDate($item->getAddedAt()));
97: $itemXmlObj->addChild('added_date', $addedDate);
98:
99: if ($this->getChild('product_price')) {
100: $this->getChild('product_price')->setProduct($item->getProduct())->setProductXmlObj($itemXmlObj)
101: ->collectProductPrices();
102: }
103:
104: if (!$item->getProduct()->getRatingSummary()) {
105: Mage::getModel('review/review')
106: ->getEntitySummary($item->getProduct(), Mage::app()->getStore()->getId());
107: }
108: $ratingSummary = (int)$item->getProduct()->getRatingSummary()->getRatingSummary();
109: $itemXmlObj->addChild('rating_summary', round($ratingSummary / 10));
110: $itemXmlObj->addChild('reviews_count', $item->getProduct()->getRatingSummary()->getReviewsCount());
111: }
112: }
113:
114: return $wishlistXmlObj->asNiceXml();
115: }
116: }
117: