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_Cart_Crosssell extends Mage_Checkout_Block_Cart_Crosssell
35: {
36: 37: 38: 39: 40:
41: protected function _toHtml()
42: {
43: if (is_object(Mage::getConfig()->getNode('modules/Enterprise_TargetRule'))) {
44: $blockRenderer = 'enterprise_targetrule/checkout_cart_crosssell';
45: $blockName = 'targetrule.checkout.cart.crosssell';
46: $this->getLayout()->createBlock($blockRenderer, $blockName);
47: $this->setItems($this->getLayout()->getBlock($blockName)->getItemCollection());
48: }
49:
50: $crossSellXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<crosssell></crosssell>');
51: if (!$this->getItemCount()) {
52: return $crossSellXmlObj->asNiceXml();
53: }
54:
55:
56: foreach ($this->getItems() as $product) {
57: $itemXmlObj = $crossSellXmlObj->addChild('item');
58: $itemXmlObj->addChild('name', $crossSellXmlObj->escapeXml($product->getName()));
59: $icon = $this->helper('catalog/image')->init($product, 'thumbnail')
60: ->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small'));
61:
62: $iconXml = $itemXmlObj->addChild('icon', $icon);
63:
64: $file = Mage::helper('xmlconnect')->urlToPath($icon);
65: $iconXml->addAttribute('modification_time', filemtime($file));
66:
67: $itemXmlObj->addChild('entity_id', $product->getId());
68: $itemXmlObj->addChild('entity_type', $product->getTypeId());
69:
70: 71: 72:
73: if ($product->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE
74: || $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
75: $product->setHasOptions(true);
76: }
77:
78: $itemXmlObj->addChild('has_options', (int)$product->getHasOptions());
79: $itemXmlObj->addChild('in_stock', (int)$product->getStockItem()->getIsInStock());
80: if ($product->getTypeId() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
81: $itemXmlObj->addChild('is_salable', 0);
82: } else {
83: $itemXmlObj->addChild('is_salable', (int)$product->isSalable());
84: }
85:
86: if ($this->getChild('product_price')) {
87: $this->getChild('product_price')->setProduct($product)->setProductXmlObj($itemXmlObj)
88: ->collectProductPrices();
89: }
90:
91: if (!$product->getRatingSummary()) {
92: Mage::getModel('review/review')->getEntitySummary($product, Mage::app()->getStore()->getId());
93: }
94:
95: $itemXmlObj->addChild('rating_summary', round((int)$product->getRatingSummary()->getRatingSummary() / 10));
96: $itemXmlObj->addChild('reviews_count', $product->getRatingSummary()->getReviewsCount());
97: }
98: return $crossSellXmlObj->asNiceXml();
99: }
100: }
101: