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_Item_Renderer extends Mage_Checkout_Block_Cart_Item_Renderer
35: {
36: 37: 38: 39: 40: 41:
42: public function addProductToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj)
43: {
44: $_item = $this->getItem();
45: $productXmlObj = $reviewXmlObj->addCustomChild('item');
46: $productXmlObj->addCustomChild('name', $this->escapeHtml($this->getProductName()));
47:
48: if ($_options = $this->getOptionList()) {
49: $optionsXmlObj = $productXmlObj->addChild('options');
50: foreach ($_options as $_option) {
51: $_formattedOptionValue = $this->getFormatedOptionValue($_option);
52:
53: if (isset($_formattedOptionValue['full_view'])) {
54: $value = $_formattedOptionValue['full_view'];
55: } else {
56: $value = null;
57: }
58:
59: $optionsXmlObj->addCustomChild('option', $value, array(
60: 'label' => $this->escapeHtml($_option['label']),
61: 'value' => $_formattedOptionValue['value']
62: ));
63: }
64: }
65:
66: $this->_addPriceToXmlObj($productXmlObj);
67: $this->_addSubtotalToXmlObj($productXmlObj);
68:
69: $productXmlObj->addCustomChild('qty', $_item->getQty());
70:
71: return $reviewXmlObj;
72: }
73:
74: 75: 76: 77: 78: 79:
80: protected function _addSubtotalToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $productXmlObj)
81: {
82: $_item = $this->getItem();
83: $subtotalXmlObj = $productXmlObj->addCustomChild('subtotal');
84:
85: if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
86: if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
87: && $_item->getWeeeTaxAppliedAmount()
88: ) {
89: $exclPrice = $_item->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount()
90: + $_item->getWeeeTaxRowDisposition();
91: } else {
92: $exclPrice = $_item->getRowTotal();
93: }
94: $exclPrice = $this->_formatPrice($exclPrice);
95: $subtotalXmlObj->addAttribute('excluding_tax', $subtotalXmlObj->escapeXml($exclPrice));
96: }
97:
98: if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
99: $_incl = $this->helper('checkout')->getSubtotalInclTax($_item);
100:
101: if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
102: && $_item->getWeeeTaxAppliedAmount()
103: ) {
104: $inclPrice = $_incl + $_item->getWeeeTaxAppliedRowAmount();
105: } else {
106: $inclPrice = $_incl - $_item->getWeeeTaxRowDisposition();
107: }
108: $inclPrice = $this->_formatPrice($inclPrice);
109:
110: $subtotalXmlObj->addAttribute('including_tax', $subtotalXmlObj->escapeXml($inclPrice));
111: }
112:
113: if (Mage::helper('weee')->getApplied($_item)) {
114: $this->_addWeeeToXmlObj($subtotalXmlObj, true);
115: }
116:
117: return $productXmlObj;
118: }
119:
120: 121: 122: 123: 124: 125:
126: protected function _formatPrice($price)
127: {
128: return $this->getQuote()->getStore()->formatPrice($price, false);
129: }
130:
131: 132: 133: 134: 135: 136:
137: protected function _addPriceToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $productXmlObj)
138: {
139: $_item = $this->getItem();
140: $priceXmlObj = $productXmlObj->addCustomChild('price');
141:
142: if ($this->helper('tax')->displayCartPriceExclTax()
143: || $this->helper('tax')->displayCartBothPrices()
144: ) {
145: if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
146: && $_item->getWeeeTaxAppliedAmount()
147: ) {
148: $exclPrice = $_item->getCalculationPrice() + $_item->getWeeeTaxAppliedAmount()
149: + $_item->getWeeeTaxDisposition();
150: } else {
151: $exclPrice = $_item->getCalculationPrice();
152: }
153: $exclPrice = $this->_formatPrice($exclPrice);
154:
155: $priceXmlObj->addAttribute('excluding_tax', $priceXmlObj->escapeXml($exclPrice));
156: }
157:
158: if ($this->helper('tax')->displayCartPriceInclTax()
159: || $this->helper('tax')->displayCartBothPrices()
160: ) {
161: $_incl = $this->helper('checkout')->getPriceInclTax($_item);
162:
163: if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales')
164: && $_item->getWeeeTaxAppliedAmount()
165: ) {
166: $inclPrice = $_incl + $_item->getWeeeTaxAppliedAmount();
167: } else {
168: $inclPrice = $_incl - $_item->getWeeeTaxDisposition();
169: }
170: $inclPrice = $this->_formatPrice($inclPrice);
171:
172: $priceXmlObj->addAttribute('including_tax', $priceXmlObj->escapeXml($inclPrice));
173: }
174:
175: if (Mage::helper('weee')->getApplied($_item)) {
176: $this->_addWeeeToXmlObj($priceXmlObj);
177: }
178:
179: return $productXmlObj;
180: }
181:
182: 183: 184: 185: 186: 187: 188:
189: protected function _addWeeeToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $priceXmlObj, $subtotalFlag = false)
190: {
191: $_item = $this->getItem();
192: $weeeXmlObj = $priceXmlObj->addCustomChild('weee');
193:
194: if ($subtotalFlag) {
195: $_incl = $this->helper('checkout')->getSubtotalInclTax($_item);
196: } else {
197: $_incl = $this->helper('checkout')->getPriceInclTax($_item);
198: }
199:
200: $typeOfDisplay2 = Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales');
201:
202: if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()) {
203: foreach (Mage::helper('weee')->getApplied($_item) as $tax) {
204:
205: if ($subtotalFlag) {
206: $amount = $tax['row_amount'];
207: } else {
208: $amount = $tax['amount'];
209: }
210:
211: $weeeXmlObj->addCustomChild('item', null, array(
212: 'name' => $tax['title'],
213: 'amount' => $this->_formatPrice($amount)
214: ));
215: }
216: } elseif ($_item->getWeeeTaxAppliedAmount()
217: && ($typeOfDisplay2 || Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales'))
218: ) {
219: foreach (Mage::helper('weee')->getApplied($_item) as $tax) {
220: if ($subtotalFlag) {
221: $amount = $tax['row_amount_incl_tax'];
222: } else {
223: $amount = $tax['amount_incl_tax'];
224: }
225:
226: $weeeXmlObj->addCustomChild('item', null, array(
227: 'name' => $tax['title'],
228: 'amount' => $this->_formatPrice($amount)
229: ));
230: }
231: }
232:
233: if ($typeOfDisplay2 && $_item->getWeeeTaxAppliedAmount()) {
234: if ($subtotalFlag) {
235: $totalExcl = $_item->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount()
236: + $_item->getWeeeTaxRowDisposition();
237: } else {
238: $totalExcl = $_item->getCalculationPrice() + $_item->getWeeeTaxAppliedAmount()
239: + $_item->getWeeeTaxDisposition();
240: }
241:
242: $totalExcl = $this->_formatPrice($totalExcl);
243: $priceXmlObj->addAttribute('total_excluding_tax', $priceXmlObj->escapeXml($totalExcl));
244: }
245:
246: if ($typeOfDisplay2 && $_item->getWeeeTaxAppliedAmount()) {
247: if ($subtotalFlag) {
248: $totalIncl = $_incl + $_item->getWeeeTaxAppliedRowAmount();
249: } else {
250: $totalIncl = $_incl + $_item->getWeeeTaxAppliedAmount();
251: }
252:
253: $totalIncl = $this->_formatPrice($totalIncl);
254: $priceXmlObj->addAttribute('total_including_tax', $priceXmlObj->escapeXml($totalIncl));
255: }
256:
257: return $priceXmlObj;
258: }
259: }
260: