/app/code/core/Mage/XmlConnect/Block/Customer/Order/Totals.php

https://bitbucket.org/kdms/sh-magento · PHP · 140 lines · 81 code · 6 blank · 53 comment · 14 complexity · 93fbb96423fe082db9b09caf5d9a6e01 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. * Customer order totals xml renderer
  28. *
  29. * @category Mage
  30. * @package Mage_XmlConnect
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_XmlConnect_Block_Customer_Order_Totals extends Mage_Sales_Block_Order_Totals
  34. {
  35. /**
  36. * Add order totals rendered to XML object
  37. * (get from template: sales/order/totals.phtml)
  38. *
  39. * @param Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj
  40. * @return null
  41. */
  42. public function addTotalsToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj)
  43. {
  44. // all Enterprise renderers from layout update into array an realize checking of their using
  45. $enterpriseBlocks = array(
  46. 'reward.sales.order.total' => array(
  47. 'module' => 'Enterprise_Reward',
  48. 'block' => 'enterprise_reward/sales_order_total'
  49. ),
  50. 'customerbalance' => array(
  51. 'module' => 'Enterprise_CustomerBalance',
  52. 'block' => 'xmlconnect/customer_order_totals_customerbalance',
  53. 'template' => 'customerbalance/order/customerbalance.phtml'
  54. ),
  55. 'customerbalance_total_refunded' => array(
  56. 'module' => 'Enterprise_CustomerBalance',
  57. 'block' => 'xmlconnect/customer_order_totals_customerbalance_refunded',
  58. 'template' => 'customerbalance/order/customerbalance_refunded.phtml',
  59. 'after' => '-',
  60. 'action' => array(
  61. 'method' => 'setAfterTotal',
  62. 'value' => 'grand_total'
  63. )
  64. ),
  65. 'giftwrapping' => array(
  66. 'module' => 'Enterprise_GiftWrapping',
  67. 'block' => 'enterprise_giftwrapping/sales_totals'
  68. ),
  69. 'giftcards' => array(
  70. 'module' => 'Enterprise_GiftCardAccount',
  71. 'block' => 'xmlconnect/customer_order_totals_giftcards',
  72. 'template' => 'giftcardaccount/order/giftcards.phtml'
  73. ),
  74. );
  75. foreach ($enterpriseBlocks as $name => $block) {
  76. // create blocks only for Enterprise/Pro modules which is in system
  77. if (is_object(Mage::getConfig()->getNode('modules/' . $block['module']))) {
  78. $blockInstance = $this->getLayout()->createBlock($block['block'], $name);
  79. $this->setChild($name, $blockInstance);
  80. if (isset($block['action']['method']) && isset($block['action']['value'])) {
  81. $method = $block['action']['method'];
  82. $blockInstance->$method($block['action']['value']);
  83. }
  84. }
  85. }
  86. $this->_beforeToHtml();
  87. $totalsXml = $orderXmlObj->addChild('totals');
  88. foreach ($this->getTotals() as $total) {
  89. if ($total->getValue()) {
  90. $total->setValue(strip_tags($total->getValue()));
  91. }
  92. if ($total->getBlockName()) {
  93. $block = $this->getLayout()->getBlock($total->getBlockName());
  94. if (is_object($block)) {
  95. if (method_exists($block, 'addToXmlObject')) {
  96. $block->setTotal($total)->addToXmlObject($totalsXml);
  97. } else {
  98. $this->_addTotalToXml($total, $totalsXml);
  99. }
  100. }
  101. } else {
  102. $this->_addTotalToXml($total, $totalsXml);
  103. }
  104. }
  105. }
  106. /**
  107. * Add total to totals XML
  108. *
  109. * @param Varien_Object $total
  110. * @param Mage_XmlConnect_Model_Simplexml_Element $totalsXml
  111. * @return null
  112. */
  113. private function _addTotalToXml($total, Mage_XmlConnect_Model_Simplexml_Element $totalsXml)
  114. {
  115. if ($total instanceof Varien_Object && $total->getCode() && $total->getLabel() && $total->hasData('value')) {
  116. $totalsXml->addCustomChild(preg_replace('@[\W]+@', '_', trim($total->getCode())),
  117. $this->_formatPrice($total), array('label' => strip_tags($total->getLabel()))
  118. );
  119. }
  120. }
  121. /**
  122. * Format price using order currency
  123. *
  124. * @param Varien_Object $total
  125. * @return string
  126. */
  127. protected function _formatPrice($total)
  128. {
  129. if (!$total->getIsFormated()) {
  130. return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $total->getValue());
  131. }
  132. return $total->getValue();
  133. }
  134. }