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 extends Mage_Checkout_Block_Cart_Abstract
35: {
36: 37: 38: 39: 40:
41: protected function _toHtml()
42: {
43: $cartMessages = $this->getMessages();
44: $quote = $this->getQuote();
45:
46: $xmlObject = Mage::getModel('xmlconnect/simplexml_element', '<cart></cart>');
47: $xmlObject->addAttribute('is_virtual', (int)$this->helper('checkout/cart')->getIsVirtualQuote());
48: $xmlObject->addAttribute('summary_qty', (int)$this->helper('checkout/cart')->getSummaryCount());
49: if (strlen($quote->getCouponCode())) {
50: $xmlObject->addAttribute('has_coupon_code', 1);
51: }
52: $products = $xmlObject->addChild('products');
53:
54: foreach ($this->getItems() as $item) {
55: $type = $item->getProductType();
56: $renderer = $this->getItemRenderer($type)->setItem($item);
57: 58: 59:
60: $itemXml = $products->addChild('item');
61: $itemXml->addChild('entity_id', $item->getProduct()->getId());
62: $itemXml->addChild('entity_type', $type);
63: $itemXml->addChild('item_id', $item->getId());
64: $itemXml->addChild('name', $xmlObject->escapeXml($renderer->getProductName()));
65: $itemXml->addChild('code', 'cart[' . $item->getId() . '][qty]');
66: $itemXml->addChild('qty', $renderer->getQty());
67: $icon = $renderer->getProductThumbnail()->resize(
68: Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small')
69: );
70: $iconXml = $itemXml->addChild('icon', $icon);
71: $file = Mage::helper('xmlconnect')->urlToPath($icon);
72: $iconXml->addAttribute('modification_time', filemtime($file));
73: 74: 75:
76: $exclPrice = $inclPrice = 0;
77: if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
78: if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
79: && $item->getWeeeTaxAppliedAmount()
80: ) {
81: $exclPrice = $item->getCalculationPrice() + $item->getWeeeTaxAppliedAmount()
82: + $item->getWeeeTaxDisposition();
83: } else {
84: $exclPrice = $item->getCalculationPrice();
85: }
86: }
87: if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
88: $_incl = $this->helper('checkout')->getPriceInclTax($item);
89: if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
90: && $item->getWeeeTaxAppliedAmount()
91: ) {
92: $inclPrice = $_incl + $item->getWeeeTaxAppliedAmount();
93: } else {
94: $inclPrice = $_incl - $item->getWeeeTaxDisposition();
95: }
96: }
97: $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice);
98: $paypalPrice = Mage::helper('xmlconnect')->formatPriceForXml($item->getCalculationPrice());
99: $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false);
100: $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice);
101: $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false);
102:
103: $priceXmlObj = $itemXml->addChild('price');
104: $formattedPriceXmlObj = $itemXml->addChild('formated_price');
105:
106: if ($this->helper('tax')->displayCartBothPrices()) {
107: $priceXmlObj->addAttribute('excluding_tax', $exclPrice);
108: $priceXmlObj->addAttribute('including_tax', $inclPrice);
109:
110: $formattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice);
111: $formattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice);
112: } else {
113: if ($this->helper('tax')->displayCartPriceExclTax()) {
114: $priceXmlObj->addAttribute('regular', $exclPrice);
115: $formattedPriceXmlObj->addAttribute('regular', $formattedExclPrice);
116: }
117: if ($this->helper('tax')->displayCartPriceInclTax()) {
118: $priceXmlObj->addAttribute('regular', $inclPrice);
119: $formattedPriceXmlObj->addAttribute('regular', $formattedInclPrice);
120: }
121: }
122:
123: 124: 125:
126: $appConfig = Mage::helper('xmlconnect')->getApplication()->loadConfiguration()->getRenderConf();
127:
128: $isMepActive = $appConfig['paypal']['isActive'];
129:
130: $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null);
131: if ($paypalMepIsAvailable && $isMepActive) {
132: $paypalPriceXmlObj = $itemXml->addChild('paypal_price');
133: $paypalPriceXmlObj->addAttribute('regular', $paypalPrice);
134: $paypalPriceXmlObj->addAttribute(
135: 'subtotal', Mage::helper('xmlconnect')->formatPriceForXml($item->getRowTotal())
136: );
137: }
138:
139: 140: 141:
142: $exclPrice = $inclPrice = 0;
143: if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) {
144: if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
145: && $item->getWeeeTaxAppliedAmount()
146: ) {
147: $exclPrice = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount()
148: + $item->getWeeeTaxRowDisposition();
149: } else {
150: $exclPrice = $item->getRowTotal();
151: }
152: }
153: if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) {
154: $_incl = $this->helper('checkout')->getSubtotalInclTax($item);
155: if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales')
156: && $item->getWeeeTaxAppliedAmount()
157: ) {
158: $inclPrice = $_incl + $item->getWeeeTaxAppliedRowAmount();
159: } else {
160: $inclPrice = $_incl - $item->getWeeeTaxRowDisposition();
161: }
162: }
163:
164: $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice);
165: $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false);
166:
167: $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice);
168: $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false);
169:
170: $subtotalPriceXmlObj = $itemXml->addChild('subtotal');
171: $subtotalFormattedPriceXmlObj = $itemXml->addChild('formated_subtotal');
172:
173: if ($this->helper('tax')->displayCartBothPrices()) {
174: $subtotalPriceXmlObj->addAttribute('excluding_tax', $exclPrice);
175: $subtotalPriceXmlObj->addAttribute('including_tax', $inclPrice);
176:
177: $subtotalFormattedPriceXmlObj->addAttribute('excluding_tax', $formattedExclPrice);
178: $subtotalFormattedPriceXmlObj->addAttribute('including_tax', $formattedInclPrice);
179: } else {
180: if ($this->helper('tax')->displayCartPriceExclTax()) {
181: $subtotalPriceXmlObj->addAttribute('regular', $exclPrice);
182: $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedExclPrice);
183: }
184: if ($this->helper('tax')->displayCartPriceInclTax()) {
185: $subtotalPriceXmlObj->addAttribute('regular', $inclPrice);
186: $subtotalFormattedPriceXmlObj->addAttribute('regular', $formattedInclPrice);
187: }
188: }
189:
190: 191: 192:
193: $_options = $renderer->getOptionList();
194: if ($_options) {
195: $itemOptionsXml = $itemXml->addChild('options');
196: foreach ($_options as $_option) {
197: $_formattedOptionValue = $renderer->getFormatedOptionValue($_option);
198: $optionXml = $itemOptionsXml->addChild('option');
199: $optionXml->addAttribute('label', $xmlObject->xmlAttribute($_option['label']));
200: $optionXml->addAttribute('text', $xmlObject->xmlAttribute($_formattedOptionValue['value']));
201: }
202: }
203:
204: 205: 206:
207: $messages = $renderer->getMessages();
208: if ($messages) {
209: $itemMessagesXml = $itemXml->addChild('messages');
210: foreach ($messages as $message) {
211: $messageXml = $itemMessagesXml->addChild('option');
212: $messageXml->addChild('type', $message['type']);
213: $messageXml->addChild('text', $xmlObject->escapeXml($message['text']));
214: }
215: }
216: }
217:
218: 219: 220:
221: if ($cartMessages) {
222: $messagesXml = $xmlObject->addChild('messages');
223: foreach ($cartMessages as $status => $messages) {
224: foreach ($messages as $message) {
225: $messageXml = $messagesXml->addChild('message');
226: $messageXml->addChild('status', $status);
227: $messageXml->addChild('text', strip_tags($message));
228: }
229: }
230: }
231:
232: 233: 234:
235: if (count($this->getItems())) {
236: $crossellXml = $this->getChildHtml('crosssell');
237: } else {
238: $crossellXml = '<crosssell></crosssell>';
239: }
240:
241: $crossSellXmlObj = Mage::getModel('xmlconnect/simplexml_element', $crossellXml);
242: $xmlObject->appendChild($crossSellXmlObj);
243:
244: return $xmlObject->asNiceXml();
245: }
246: }
247: