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

https://github.com/alexandresalome/Magento · PHP · 262 lines · 165 code · 35 blank · 62 comment · 43 complexity · f4e968e7305306ba7023aeb8e10c6dfc MD5 · raw file

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  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) 2011 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Shopping cart default item 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_Item_Renderer extends Mage_Checkout_Block_Cart_Item_Renderer
  34. {
  35. /**
  36. * Add product details to XML object
  37. *
  38. * @param Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj
  39. * @return Mage_XmlConnect_Model_Simplexml_Element
  40. */
  41. public function addProductToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj)
  42. {
  43. $_item = $this->getItem();
  44. $productXmlObj = $reviewXmlObj->addCustomChild('item');
  45. $productXmlObj->addCustomChild('name', $this->escapeHtml($this->getProductName()));
  46. if ($_options = $this->getOptionList()) {
  47. $optionsXmlObj = $productXmlObj->addChild('options');
  48. foreach ($_options as $_option) {
  49. $_formattedOptionValue = $this->getFormatedOptionValue($_option);
  50. if (isset($_formattedOptionValue['full_view'])) {
  51. $value = $_formattedOptionValue['full_view'];
  52. } else {
  53. $value = null;
  54. }
  55. $optionsXmlObj->addCustomChild('option', $value, array(
  56. 'label' => $this->escapeHtml($_option['label']),
  57. 'value' => $_formattedOptionValue['value']
  58. ));
  59. }
  60. }
  61. $this->_addPriceToXmlObj($productXmlObj);
  62. $this->_addSubtotalToXmlObj($productXmlObj);
  63. $productXmlObj->addCustomChild('qty', $_item->getQty());
  64. return $reviewXmlObj;
  65. }
  66. /**
  67. * Add product subtotal info to xml object
  68. *
  69. * @param Mage_XmlConnect_Model_Simplexml_Element $productXmlObj
  70. * @return Mage_XmlConnect_Model_Simplexml_Element
  71. */
  72. protected function _addSubtotalToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $productXmlObj)
  73. {
  74. $_item = $this->getItem();
  75. $subtotalXmlObj = $productXmlObj->addCustomChild('subtotal');
  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->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount()
  81. + $_item->getWeeeTaxRowDisposition();
  82. } else {
  83. $exclPrice = $_item->getRowTotal();
  84. }
  85. $exclPrice = $this->_formatPrice($exclPrice);
  86. $subtotalXmlObj->addAttribute('excluding_tax', $subtotalXmlObj->xmlentities($exclPrice));
  87. }
  88. if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
  89. $_incl = $this->helper('checkout')->getSubtotalInclTax($_item);
  90. if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
  91. && $_item->getWeeeTaxAppliedAmount()
  92. ) {
  93. $inclPrice = $_incl + $_item->getWeeeTaxAppliedRowAmount();
  94. } else {
  95. $inclPrice = $_incl - $_item->getWeeeTaxRowDisposition();
  96. }
  97. $inclPrice = $this->_formatPrice($inclPrice);
  98. $subtotalXmlObj->addAttribute('including_tax', $subtotalXmlObj->xmlentities($inclPrice));
  99. }
  100. if (Mage::helper('weee')->getApplied($_item)) {
  101. $this->_addWeeeToXmlObj($subtotalXmlObj, true);
  102. }
  103. return $productXmlObj;
  104. }
  105. /**
  106. * Format product price
  107. *
  108. * @param int $price
  109. * @return float
  110. */
  111. protected function _formatPrice($price)
  112. {
  113. return $this->getQuote()->getStore()->formatPrice($price, false);
  114. }
  115. /**
  116. * Add product price info to xml object
  117. *
  118. * @param Mage_XmlConnect_Model_Simplexml_Element $productXmlObj
  119. * @return Mage_XmlConnect_Model_Simplexml_Element
  120. */
  121. protected function _addPriceToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $productXmlObj)
  122. {
  123. $_item = $this->getItem();
  124. $priceXmlObj = $productXmlObj->addCustomChild('price');
  125. if ($this->helper('tax')->displayCartPriceExclTax()
  126. || $this->helper('tax')->displayCartBothPrices()
  127. ) {
  128. if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
  129. && $_item->getWeeeTaxAppliedAmount()
  130. ) {
  131. $exclPrice = $_item->getCalculationPrice() + $_item->getWeeeTaxAppliedAmount()
  132. + $_item->getWeeeTaxDisposition();
  133. } else {
  134. $exclPrice = $_item->getCalculationPrice();
  135. }
  136. $exclPrice = $this->_formatPrice($exclPrice);
  137. $priceXmlObj->addAttribute('excluding_tax', $priceXmlObj->xmlentities($exclPrice));
  138. }
  139. if ($this->helper('tax')->displayCartPriceInclTax()
  140. || $this->helper('tax')->displayCartBothPrices()
  141. ) {
  142. $_incl = $this->helper('checkout')->getPriceInclTax($_item);
  143. if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
  144. && $_item->getWeeeTaxAppliedAmount()
  145. ) {
  146. $inclPrice = $_incl + $_item->getWeeeTaxAppliedAmount();
  147. } else {
  148. $inclPrice = $_incl - $_item->getWeeeTaxDisposition();
  149. }
  150. $inclPrice = $this->_formatPrice($inclPrice);
  151. $priceXmlObj->addAttribute('including_tax', $priceXmlObj->xmlentities($inclPrice));
  152. }
  153. if (Mage::helper('weee')->getApplied($_item)) {
  154. $this->_addWeeeToXmlObj($priceXmlObj);
  155. }
  156. return $productXmlObj;
  157. }
  158. /**
  159. * Add weee tax product info to xml object
  160. *
  161. * @param Mage_XmlConnect_Model_Simplexml_Element $priceXmlObj
  162. * @param bool $subtotalFlag use true to get subtotal product info
  163. * @return Mage_XmlConnect_Model_Simplexml_Element
  164. */
  165. protected function _addWeeeToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $priceXmlObj, $subtotalFlag = false)
  166. {
  167. $_item = $this->getItem();
  168. $weeeXmlObj = $priceXmlObj->addCustomChild('weee');
  169. if ($subtotalFlag) {
  170. $_incl = $this->helper('checkout')->getSubtotalInclTax($_item);
  171. } else {
  172. $_incl = $this->helper('checkout')->getPriceInclTax($_item);
  173. }
  174. $typeOfDisplay2 = Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales');
  175. if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()) {
  176. foreach (Mage::helper('weee')->getApplied($_item) as $tax) {
  177. if ($subtotalFlag) {
  178. $amount = $tax['row_amount'];
  179. } else {
  180. $amount = $tax['amount'];
  181. }
  182. $weeeXmlObj->addCustomChild('item', null, array(
  183. 'name' => $tax['title'],
  184. 'amount' => $this->_formatPrice($amount)
  185. ));
  186. }
  187. } elseif ($_item->getWeeeTaxAppliedAmount()
  188. && ($typeOfDisplay2 || Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales'))
  189. ) {
  190. foreach (Mage::helper('weee')->getApplied($_item) as $tax) {
  191. if ($subtotalFlag) {
  192. $amount = $tax['row_amount_incl_tax'];
  193. } else {
  194. $amount = $tax['amount_incl_tax'];
  195. }
  196. $weeeXmlObj->addCustomChild('item', null, array(
  197. 'name' => $tax['title'],
  198. 'amount' => $this->_formatPrice($amount)
  199. ));
  200. }
  201. }
  202. if ($typeOfDisplay2 && $_item->getWeeeTaxAppliedAmount()) {
  203. if ($subtotalFlag) {
  204. $totalExcl = $_item->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount()
  205. + $_item->getWeeeTaxRowDisposition();
  206. } else {
  207. $totalExcl = $_item->getCalculationPrice() + $_item->getWeeeTaxAppliedAmount()
  208. + $_item->getWeeeTaxDisposition();
  209. }
  210. $totalExcl = $this->_formatPrice($totalExcl);
  211. $priceXmlObj->addAttribute(
  212. 'total_excluding_tax',
  213. $priceXmlObj->xmlentities($totalExcl)
  214. );
  215. }
  216. if ($typeOfDisplay2 && $_item->getWeeeTaxAppliedAmount()) {
  217. if ($subtotalFlag) {
  218. $totalIncl = $_incl + $_item->getWeeeTaxAppliedRowAmount();
  219. } else {
  220. $totalIncl = $_incl + $_item->getWeeeTaxAppliedAmount();
  221. }
  222. $totalIncl = $this->_formatPrice($totalIncl);
  223. $priceXmlObj->addAttribute('total_including_tax', $priceXmlObj->xmlentities($totalIncl));
  224. }
  225. return $priceXmlObj;
  226. }
  227. }