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

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

https://gitlab.com/LisovyiEvhenii/ismextensions
PHP | 254 lines | 176 code | 18 blank | 60 comment | 33 complexity | 318e6ca5a6fa094dc7b8bb153fcb3e91 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@magento.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.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_XmlConnect
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Shopping cart items renderer
  28. *
  29. * @category Mage
  30. * @package Mage_XmlConnect
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_XmlConnect_Block_Cart_Items extends Mage_Checkout_Block_Cart_Abstract
  34. {
  35. /**
  36. * Add product block to cart
  37. *
  38. * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObject
  39. * @param Mage_Sales_Model_Quote $quote
  40. * @return null
  41. */
  42. public function addCartProductsToXmlObj($xmlObject, $quote)
  43. {
  44. $productSmallImageSize = Mage::getModel('xmlconnect/images')->getImageLimitParam('content/product_small');
  45. $products = $xmlObject->addCustomChild('products');
  46. /* @var $item Mage_Sales_Model_Quote_Item */
  47. foreach ($this->getItems() as $item) {
  48. $type = $item->getProductType();
  49. $renderer = $this->getItemRenderer($type)->setItem($item);
  50. /**
  51. * General information
  52. */
  53. $itemXml = $products->addCustomChild('item', null, array('entity_id' => $item->getProduct()->getId()));
  54. $itemXml->addCustomChild('entity_type', $type);
  55. $itemXml->addCustomChild('item_id', $item->getId());
  56. $itemXml->addCustomChild('name', $xmlObject->escapeXml($renderer->getProductName()));
  57. $itemXml->addCustomChild('code', 'cart[' . $item->getId() . '][qty]');
  58. $itemXml->addCustomChild('qty', $renderer->getQty());
  59. $icon = $renderer->getProductThumbnail()->resize($productSmallImageSize);
  60. $iconXml = $itemXml->addChild('icon', $icon);
  61. $iconXml->addAttribute('modification_time', filemtime($icon->getNewFile()));
  62. /**
  63. * Price
  64. */
  65. $pricesXmlObj = $itemXml->addCustomChild('price_list');
  66. $exclPrice = $inclPrice = 0;
  67. if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
  68. if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
  69. && $item->getWeeeTaxAppliedAmount()
  70. ) {
  71. $exclPrice = $item->getCalculationPrice() + $item->getWeeeTaxAppliedAmount()
  72. + $item->getWeeeTaxDisposition();
  73. } else {
  74. $exclPrice = $item->getCalculationPrice();
  75. }
  76. }
  77. if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
  78. $incl = $this->helper('checkout')->getPriceInclTax($item);
  79. if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
  80. && $item->getWeeeTaxAppliedAmount()
  81. ) {
  82. $inclPrice = $incl + $item->getWeeeTaxAppliedAmount();
  83. } else {
  84. $inclPrice = $incl - $item->getWeeeTaxDisposition();
  85. }
  86. }
  87. $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice);
  88. $paypalPrice = Mage::helper('xmlconnect')->formatPriceForXml($item->getCalculationPrice());
  89. $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false);
  90. $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice);
  91. $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false);
  92. $priceXmlObj = $pricesXmlObj->addCustomChild('prices', null, array('id' => 'price'));
  93. if ($this->helper('tax')->displayCartBothPrices()) {
  94. $priceXmlObj->addCustomChild('price', $exclPrice, array(
  95. 'id' => 'excluding_tax',
  96. 'label' => $this->__('Excl. Tax'),
  97. 'formatted_value' => $formattedExclPrice
  98. ));
  99. $priceXmlObj->addCustomChild('price', $inclPrice, array(
  100. 'id' => 'including_tax',
  101. 'label' => $this->__('Incl. Tax'),
  102. 'formatted_value' => $formattedInclPrice
  103. ));
  104. } else {
  105. if ($this->helper('tax')->displayCartPriceExclTax()) {
  106. $priceXmlObj->addCustomChild('price', $exclPrice, array(
  107. 'id' => 'regular',
  108. 'label' => $this->__('Unit Price'),
  109. 'formatted_value' => $formattedExclPrice
  110. ));
  111. }
  112. if ($this->helper('tax')->displayCartPriceInclTax()) {
  113. $priceXmlObj->addCustomChild('price', $inclPrice, array(
  114. 'id' => 'regular',
  115. 'label' => $this->__('Unit Price'),
  116. 'formatted_value' => $formattedInclPrice
  117. ));
  118. }
  119. }
  120. /**
  121. * Info for paypal MEP if it's enabled
  122. */
  123. $appConfig = Mage::helper('xmlconnect')->getApplication()->loadConfiguration()->getRenderConf();
  124. $isMepActive = $appConfig['paypal']['isActive'];
  125. $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null);
  126. if ($paypalMepIsAvailable && $isMepActive) {
  127. $paypalPriceXmlObj = $pricesXmlObj->addCustomChild('prices', null, array('id' => 'paypal'));
  128. $paypalPriceXmlObj->addCustomChild('price', $paypalPrice, array(
  129. 'id' => 'regular',
  130. 'label' => $this->__('Unit Price'),
  131. 'formatted_value' => $quote->getStore()->formatPrice($paypalPrice, false)
  132. ));
  133. $paypalSubtotalPrice = Mage::helper('xmlconnect')->formatPriceForXml($item->getRowTotal());
  134. $paypalPriceXmlObj->addCustomChild('price', $paypalSubtotalPrice, array(
  135. 'id' => 'subtotal',
  136. 'label' => $this->__('Subtotal'),
  137. 'formatted_value' => $quote->getStore()->formatPrice($paypalSubtotalPrice, false)
  138. ));
  139. }
  140. /**
  141. * Subtotal
  142. */
  143. $subtotalExclTax = $subtotalInclTax = 0;
  144. if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
  145. if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
  146. && $item->getWeeeTaxAppliedAmount()
  147. ) {
  148. $subtotalExclTax = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount()
  149. + $item->getWeeeTaxRowDisposition();
  150. } else {
  151. $subtotalExclTax = $item->getRowTotal();
  152. }
  153. }
  154. if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
  155. $incl = $this->helper('checkout')->getSubtotalInclTax($item);
  156. if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
  157. && $item->getWeeeTaxAppliedAmount()
  158. ) {
  159. $subtotalInclTax = $incl + $item->getWeeeTaxAppliedRowAmount();
  160. } else {
  161. $subtotalInclTax = $incl - $item->getWeeeTaxRowDisposition();
  162. }
  163. }
  164. $subtotalExclTax = Mage::helper('xmlconnect')->formatPriceForXml($subtotalExclTax);
  165. $formattedSubtotalExcl = $quote->getStore()->formatPrice($subtotalExclTax, false);
  166. $subtotalInclTax = Mage::helper('xmlconnect')->formatPriceForXml($subtotalInclTax);
  167. $formattedSubtotalIncl = $quote->getStore()->formatPrice($subtotalInclTax, false);
  168. $priceXmlObj = $pricesXmlObj->addCustomChild('prices', null, array('id' => 'subtotal'));
  169. if ($this->helper('tax')->displayCartBothPrices()) {
  170. $priceXmlObj->addCustomChild('price', $subtotalExclTax, array(
  171. 'id' => 'excluding_tax',
  172. 'label' => $this->__('Subtotal Excl. Tax'),
  173. 'formatted_value' => $formattedSubtotalExcl
  174. ));
  175. $priceXmlObj->addCustomChild('price', $subtotalInclTax, array(
  176. 'id' => 'including_tax',
  177. 'label' => $this->__('Subtotal Incl. Tax'),
  178. 'formatted_value' => $formattedSubtotalIncl
  179. ));
  180. } else {
  181. if ($this->helper('tax')->displayCartPriceExclTax()) {
  182. $priceXmlObj->addCustomChild('price', $subtotalExclTax, array(
  183. 'id' => 'regular',
  184. 'label' => $this->__('Subtotal'),
  185. 'formatted_value' => $formattedSubtotalExcl
  186. ));
  187. }
  188. if ($this->helper('tax')->displayCartPriceInclTax()) {
  189. $priceXmlObj->addCustomChild('price', $subtotalInclTax, array(
  190. 'id' => 'regular',
  191. 'label' => $this->__('Subtotal'),
  192. 'formatted_value' => $formattedSubtotalIncl
  193. ));
  194. }
  195. }
  196. /**
  197. * Options list
  198. */
  199. $options = $renderer->getOptionList();
  200. if ($options) {
  201. $itemOptionsXml = $itemXml->addCustomChild('options');
  202. foreach ($options as $_option) {
  203. $formattedOptionValue = $renderer->getFormatedOptionValue($_option);
  204. $itemOptionsXml->addCustomChild('option', null, array(
  205. 'label' => $xmlObject->xmlAttribute($_option['label']),
  206. 'text' => $xmlObject->xmlAttribute($formattedOptionValue['value'])
  207. ));
  208. }
  209. }
  210. /**
  211. * Downloadable products
  212. */
  213. $links = $renderer->getLinks();
  214. if ($links) {
  215. $itemOptionsXml = $itemXml->addCustomChild('options', null, array(
  216. 'label' => $renderer->getLinksTitle()
  217. ));
  218. foreach ($links as $link) {
  219. $itemOptionsXml->addCustomChild('option', null, array('label' => $link->getTitle()));
  220. }
  221. }
  222. /**
  223. * Item messages
  224. */
  225. $messages = $renderer->getMessages();
  226. if ($messages) {
  227. $itemMessagesXml = $itemXml->addCustomChild('messages');
  228. foreach ($messages as $message) {
  229. $messageXml = $itemMessagesXml->addCustomChild('option');
  230. $messageXml->addCustomChild('type', $message['type']);
  231. $messageXml->addCustomChild('text', $xmlObject->escapeXml($message['text']));
  232. }
  233. }
  234. }
  235. }
  236. }