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_Cart_Totals extends Mage_Checkout_Block_Cart_Totals
35: {
36: 37: 38: 39: 40:
41: protected function _toHtml()
42: {
43:
44: $totalsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<totals></totals>');
45:
46: foreach ($this->getQuote()->getTotals() as $total) {
47: $code = $total->getCode();
48: if ($code == 'giftwrapping') {
49: continue;
50: }
51:
52: $title = '';
53: $value = null;
54: $renderer = $this->_getTotalRenderer($code)->setTotal($total);
55:
56: switch ($code) {
57: case 'subtotal':
58: if ($renderer->displayBoth()) {
59: $title = $this->__('Subtotal (Excl. Tax)');
60: $this->_addTotalDataToXmlObj(
61: $totalsXmlObj,
62: $code . '_excl_tax',
63: $title,
64: $total->getValueExclTax()
65: );
66:
67: $code = $code . '_incl_tax';
68: $title = $this->__('Subtotal (Incl. Tax)');
69: $value = $total->getValueInclTax();
70: }
71: break;
72: case 'shipping':
73: if ($renderer->displayBoth()) {
74: $title = $renderer->getExcludeTaxLabel();
75: $this->_addTotalDataToXmlObj(
76: $totalsXmlObj, $code . '_excl_tax', $title, $renderer->getShippingExcludeTax()
77: );
78:
79: $code = $code . '_incl_tax';
80: $title = $renderer->getIncludeTaxLabel();
81: $value = $renderer->getShippingIncludeTax();
82: } else if ($renderer->displayIncludeTax()) {
83: $value = $renderer->getShippingIncludeTax();
84: } else {
85: $value = $renderer->getShippingExcludeTax();
86: }
87: break;
88: case 'grand_total':
89: $grandTotalExlTax = $renderer->getTotalExclTax();
90: $displayBoth = $renderer->includeTax() && $grandTotalExlTax >= 0;
91: if ($displayBoth) {
92: $title = $this->__('Grand Total (Excl. Tax)');
93: $this->_addTotalDataToXmlObj(
94: $totalsXmlObj, $code . '_excl_tax', $title, $grandTotalExlTax
95: );
96: $code = $code . '_incl_tax';
97: $title = $this->__('Grand Total (Incl. Tax)');
98: }
99: break;
100: case 'giftwrapping':
101: foreach ($renderer->getValues() as $title => $value) {
102: $this->_addTotalDataToXmlObj($totalsXmlObj, $code, $title, $value);
103: }
104: continue 2;
105: case 'giftcardaccount':
106: $_cards = $renderer->getTotal()->getGiftCards();
107: if (!$_cards) {
108: $_cards = $renderer->getQuoteGiftCards();
109: }
110: if ($renderer->getTotal()->getValue()) {
111: foreach ($_cards as $cardCode) {
112: $title = $this->__('Gift Card (%s)', $cardCode['c']);
113: $value = $cardCode['c'];
114: $totalXmlObj = $totalsXmlObj->addChild($code);
115: $totalXmlObj->addChild('title', $totalsXmlObj->escapeXml($title));
116: $totalXmlObj->addChild('value', $value);
117: $value = Mage::helper('xmlconnect')->formatPriceForXml($cardCode['a']);
118: $formattedValue = $this->getQuote()->getStore()->formatPrice($value, false);
119: $totalXmlObj->addChild('formated_value', '-' . $formattedValue);
120: }
121: }
122: continue 2;
123: default:
124: break;
125: }
126: if (empty($title)) {
127: $title = $total->getTitle();
128: }
129: if (null === $value) {
130: $value = $total->getValue();
131: }
132: if (null !== $value) {
133: $this->_addTotalDataToXmlObj($totalsXmlObj, $code, $title, $value);
134: }
135: }
136:
137: return $this->getReturnObjectFlag() ? $totalsXmlObj : $totalsXmlObj->asNiceXml();
138: }
139:
140: 141: 142: 143: 144: 145: 146: 147:
148: protected function _addTotalDataToXmlObj($totalsXmlObj, $code, $title, $value)
149: {
150: $value = Mage::helper('xmlconnect')->formatPriceForXml($value);
151: $totalXmlObj = $totalsXmlObj->addChild($code);
152: $totalXmlObj->addChild('title', $totalsXmlObj->escapeXml($title));
153: $formattedValue = $this->getQuote()->getStore()->formatPrice($value, false);
154: $totalXmlObj->addChild('value', $value);
155: $totalXmlObj->addChild('formated_value', $formattedValue);
156: }
157: }
158: