PageRenderTime 44ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/XmlConnect/Block/Cart.php

https://bitbucket.org/kdms/sh-magento
PHP | 246 lines | 165 code | 19 blank | 62 comment | 36 complexity | bfcb9848b4de728612b8c40989770a84 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento Enterprise Edition
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Magento Enterprise Edition License
  8. * that is bundled with this package in the file LICENSE_EE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.magentocommerce.com/license/enterprise-edition
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_XmlConnect
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://www.magentocommerce.com/license/enterprise-edition
  25. */
  26. /**
  27. * Shopping cart xml renderer
  28. *
  29. * @category Mage
  30. * @package Mage_Xmlconnect
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_XmlConnect_Block_Cart extends Mage_Checkout_Block_Cart_Abstract
  34. {
  35. /**
  36. * Render shopping cart xml
  37. *
  38. * @return string
  39. */
  40. protected function _toHtml()
  41. {
  42. $cartMessages = $this->getMessages();
  43. $quote = $this->getQuote();
  44. /** @var $xmlObject Mage_XmlConnect_Model_Simplexml_Element */
  45. $xmlObject = Mage::getModel('xmlconnect/simplexml_element', '<cart></cart>');
  46. $xmlObject->addAttribute('is_virtual', (int)$this->helper('checkout/cart')->getIsVirtualQuote());
  47. $xmlObject->addAttribute('summary_qty', (int)$this->helper('checkout/cart')->getSummaryCount());
  48. if (strlen($quote->getCouponCode())) {
  49. $xmlObject->addAttribute('has_coupon_code', 1);
  50. }
  51. $products = $xmlObject->addChild('products');
  52. /* @var $item Mage_Sales_Model_Quote_Item */
  53. foreach ($this->getItems() as $item) {
  54. $type = $item->getProductType();
  55. $renderer = $this->getItemRenderer($type)->setItem($item);
  56. /**
  57. * General information
  58. */
  59. $itemXml = $products->addChild('item');
  60. $itemXml->addChild('entity_id', $item->getProduct()->getId());
  61. $itemXml->addChild('entity_type', $type);
  62. $itemXml->addChild('item_id', $item->getId());
  63. $itemXml->addChild('name', $xmlObject->escapeXml($renderer->getProductName()));
  64. $itemXml->addChild('code', 'cart[' . $item->getId() . '][qty]');
  65. $itemXml->addChild('qty', $renderer->getQty());
  66. $icon = $renderer->getProductThumbnail()->resize(
  67. Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small')
  68. );
  69. $iconXml = $itemXml->addChild('icon', $icon);
  70. $file = Mage::helper('xmlconnect')->urlToPath($icon);
  71. $iconXml->addAttribute('modification_time', filemtime($file));
  72. /**
  73. * Price
  74. */
  75. $exclPrice = $inclPrice = 0;
  76. if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
  77. if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
  78. && $item->getWeeeTaxAppliedAmount()
  79. ) {
  80. $exclPrice = $item->getCalculationPrice() + $item->getWeeeTaxAppliedAmount()
  81. + $item->getWeeeTaxDisposition();
  82. } else {
  83. $exclPrice = $item->getCalculationPrice();
  84. }
  85. }
  86. if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
  87. $_incl = $this->helper('checkout')->getPriceInclTax($item);
  88. if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
  89. && $item->getWeeeTaxAppliedAmount()
  90. ) {
  91. $inclPrice = $_incl + $item->getWeeeTaxAppliedAmount();
  92. } else {
  93. $inclPrice = $_incl - $item->getWeeeTaxDisposition();
  94. }
  95. }
  96. $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice);
  97. $paypalPrice = Mage::helper('xmlconnect')->formatPriceForXml($item->getCalculationPrice());
  98. $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false);
  99. $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice);
  100. $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false);
  101. $priceXmlObj = $itemXml->addChild('price');
  102. $formattedPriceXmlObj = $itemXml->addChild('formated_price');
  103. if ($this->helper('tax')->displayCartBothPrices()) {
  104. $priceXmlObj->addAttribute('excluding_tax', $exclPrice);
  105. $priceXmlObj->addAttribute('including_tax', $inclPrice);
  106. $formattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice);
  107. $formattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice);
  108. } else {
  109. if ($this->helper('tax')->displayCartPriceExclTax()) {
  110. $priceXmlObj->addAttribute('regular', $exclPrice);
  111. $formattedPriceXmlObj->addAttribute('regular', $formattedExclPrice);
  112. }
  113. if ($this->helper('tax')->displayCartPriceInclTax()) {
  114. $priceXmlObj->addAttribute('regular', $inclPrice);
  115. $formattedPriceXmlObj->addAttribute('regular', $formattedInclPrice);
  116. }
  117. }
  118. /**
  119. * Info for paypal MEP if it's enabled
  120. */
  121. $appConfig = Mage::helper('xmlconnect')->getApplication()->loadConfiguration()->getRenderConf();
  122. $isMepActive = $appConfig['paypal']['isActive'];
  123. $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null);
  124. if ($paypalMepIsAvailable && $isMepActive) {
  125. $paypalPriceXmlObj = $itemXml->addChild('paypal_price');
  126. $paypalPriceXmlObj->addAttribute('regular', $paypalPrice);
  127. $paypalPriceXmlObj->addAttribute(
  128. 'subtotal', Mage::helper('xmlconnect')->formatPriceForXml($item->getRowTotal())
  129. );
  130. }
  131. /**
  132. * Subtotal
  133. */
  134. $exclPrice = $inclPrice = 0;
  135. if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
  136. if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
  137. && $item->getWeeeTaxAppliedAmount()
  138. ) {
  139. $exclPrice = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount()
  140. + $item->getWeeeTaxRowDisposition();
  141. } else {
  142. $exclPrice = $item->getRowTotal();
  143. }
  144. }
  145. if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
  146. $_incl = $this->helper('checkout')->getSubtotalInclTax($item);
  147. if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
  148. && $item->getWeeeTaxAppliedAmount()
  149. ) {
  150. $inclPrice = $_incl + $item->getWeeeTaxAppliedRowAmount();
  151. } else {
  152. $inclPrice = $_incl - $item->getWeeeTaxRowDisposition();
  153. }
  154. }
  155. $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice);
  156. $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false);
  157. $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice);
  158. $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false);
  159. $subtotalPriceXmlObj = $itemXml->addChild('subtotal');
  160. $subtotalFormattedPriceXmlObj = $itemXml->addChild('formated_subtotal');
  161. if ($this->helper('tax')->displayCartBothPrices()) {
  162. $subtotalPriceXmlObj->addAttribute('excluding_tax', $exclPrice);
  163. $subtotalPriceXmlObj->addAttribute('including_tax', $inclPrice);
  164. $subtotalFormattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice);
  165. $subtotalFormattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice);
  166. } else {
  167. if ($this->helper('tax')->displayCartPriceExclTax()) {
  168. $subtotalPriceXmlObj->addAttribute('regular', $exclPrice);
  169. $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedExclPrice);
  170. }
  171. if ($this->helper('tax')->displayCartPriceInclTax()) {
  172. $subtotalPriceXmlObj->addAttribute('regular', $inclPrice);
  173. $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedInclPrice);
  174. }
  175. }
  176. /**
  177. * Options list
  178. */
  179. $_options = $renderer->getOptionList();
  180. if ($_options) {
  181. $itemOptionsXml = $itemXml->addChild('options');
  182. foreach ($_options as $_option) {
  183. $_formattedOptionValue = $renderer->getFormatedOptionValue($_option);
  184. $optionXml = $itemOptionsXml->addChild('option');
  185. $optionXml->addAttribute('label', $xmlObject->xmlAttribute($_option['label']));
  186. $optionXml->addAttribute('text', $xmlObject->xmlAttribute($_formattedOptionValue['value']));
  187. }
  188. }
  189. /**
  190. * Item messages
  191. */
  192. $messages = $renderer->getMessages();
  193. if ($messages) {
  194. $itemMessagesXml = $itemXml->addChild('messages');
  195. foreach ($messages as $message) {
  196. $messageXml = $itemMessagesXml->addChild('option');
  197. $messageXml->addChild('type', $message['type']);
  198. $messageXml->addChild('text', $xmlObject->escapeXml($message['text']));
  199. }
  200. }
  201. }
  202. /**
  203. * Cart messages
  204. */
  205. if ($cartMessages) {
  206. $messagesXml = $xmlObject->addChild('messages');
  207. foreach ($cartMessages as $status => $messages) {
  208. foreach ($messages as $message) {
  209. $messageXml = $messagesXml->addChild('message');
  210. $messageXml->addChild('status', $status);
  211. $messageXml->addChild('text', strip_tags($message));
  212. }
  213. }
  214. }
  215. /**
  216. * Cross Sell Products
  217. */
  218. if (count($this->getItems())) {
  219. $crossellXml = $this->getChildHtml('crosssell');
  220. } else {
  221. $crossellXml = '<crosssell></crosssell>';
  222. }
  223. $crossSellXmlObj = Mage::getModel('xmlconnect/simplexml_element', $crossellXml);
  224. $xmlObject->appendChild($crossSellXmlObj);
  225. return $xmlObject->asNiceXml();
  226. }
  227. }