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_Customer_Order_Totals extends Mage_Sales_Block_Order_Totals
35: {
36: 37: 38: 39: 40: 41: 42:
43: public function addTotalsToXmlObject(Mage_XmlConnect_Model_Simplexml_Element $orderXmlObj)
44: {
45:
46: $enterpriseBlocks = array(
47: 'reward.sales.order.total' => array(
48: 'module' => 'Enterprise_Reward',
49: 'block' => 'enterprise_reward/sales_order_total'
50: ),
51: 'customerbalance' => array(
52: 'module' => 'Enterprise_CustomerBalance',
53: 'block' => 'xmlconnect/customer_order_totals_customerbalance',
54: 'template' => 'customerbalance/order/customerbalance.phtml'
55: ),
56: 'customerbalance_total_refunded' => array(
57: 'module' => 'Enterprise_CustomerBalance',
58: 'block' => 'xmlconnect/customer_order_totals_customerbalance_refunded',
59: 'template' => 'customerbalance/order/customerbalance_refunded.phtml',
60: 'after' => '-',
61: 'action' => array(
62: 'method' => 'setAfterTotal',
63: 'value' => 'grand_total'
64: )
65: ),
66: 'giftwrapping' => array(
67: 'module' => 'Enterprise_GiftWrapping',
68: 'block' => 'enterprise_giftwrapping/sales_totals'
69: ),
70: 'giftcards' => array(
71: 'module' => 'Enterprise_GiftCardAccount',
72: 'block' => 'xmlconnect/customer_order_totals_giftcards',
73: 'template' => 'giftcardaccount/order/giftcards.phtml'
74: ),
75: );
76:
77: foreach ($enterpriseBlocks as $name => $block) {
78:
79: if (is_object(Mage::getConfig()->getNode('modules/' . $block['module']))) {
80: $blockInstance = $this->getLayout()->createBlock($block['block'], $name);
81: $this->setChild($name, $blockInstance);
82: if (isset($block['action']['method']) && isset($block['action']['value'])) {
83: $method = $block['action']['method'];
84: $blockInstance->$method($block['action']['value']);
85: }
86: }
87: }
88:
89: $this->_beforeToHtml();
90:
91: $totalsXml = $orderXmlObj->addChild('totals');
92: foreach ($this->getTotals() as $total) {
93: if ($total->getValue()) {
94: $total->setValue(strip_tags($total->getValue()));
95: }
96: if ($total->getBlockName()) {
97: $block = $this->getLayout()->getBlock($total->getBlockName());
98: if (is_object($block)) {
99: if (method_exists($block, 'addToXmlObject')) {
100: $block->setTotal($total)->addToXmlObject($totalsXml);
101: } else {
102: $this->_addTotalToXml($total, $totalsXml);
103: }
104: }
105: } else {
106: $this->_addTotalToXml($total, $totalsXml);
107: }
108: }
109: }
110:
111: 112: 113: 114: 115: 116: 117:
118: private function _addTotalToXml($total, Mage_XmlConnect_Model_Simplexml_Element $totalsXml)
119: {
120: if ($total instanceof Varien_Object && $total->getCode() && $total->getLabel() && $total->hasData('value')) {
121: $totalsXml->addCustomChild(preg_replace('@[\W]+@', '_', trim($total->getCode())),
122: $this->_formatPrice($total), array('label' => strip_tags($total->getLabel()))
123: );
124: }
125: }
126:
127: 128: 129: 130: 131: 132:
133: protected function _formatPrice($total)
134: {
135: if (!$total->getIsFormated()) {
136: return Mage::helper('xmlconnect/customer_order')->formatPrice($this, $total->getValue());
137: }
138: return $total->getValue();
139: }
140: }
141: