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_Checkout_Shipping_Method_Available
35: extends Mage_Checkout_Block_Onepage_Shipping_Method_Available
36: {
37: 38: 39: 40: 41:
42: protected function _toHtml()
43: {
44:
45: $methodsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<shipping_methods></shipping_methods>');
46: $_shippingRateGroups = $this->getShippingRates();
47: if ($_shippingRateGroups) {
48: $store = $this->getQuote()->getStore();
49: $_sole = count($_shippingRateGroups) == 1;
50: foreach ($_shippingRateGroups as $code => $_rates) {
51: $methodXmlObj = $methodsXmlObj->addChild('method');
52: $methodXmlObj->addAttribute('label', $methodsXmlObj->escapeXml($this->getCarrierName($code)));
53: $ratesXmlObj = $methodXmlObj->addChild('rates');
54:
55: $_sole = $_sole && count($_rates) == 1;
56: foreach ($_rates as $_rate) {
57: $rateXmlObj = $ratesXmlObj->addChild('rate');
58: $rateXmlObj->addAttribute('label', $methodsXmlObj->escapeXml($_rate->getMethodTitle()));
59: $rateXmlObj->addAttribute('code', $_rate->getCode());
60: if ($_rate->getErrorMessage()) {
61: $rateXmlObj->addChild('error_message', $methodsXmlObj->escapeXml($_rate->getErrorMessage()));
62: } else {
63: $price = Mage::helper('tax')->getShippingPrice(
64: $_rate->getPrice(),
65: Mage::helper('tax')->displayShippingPriceIncludingTax(),
66: $this->getAddress()
67: );
68: $formattedPrice = $store->convertPrice($price, true, false);
69: $rateXmlObj->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml(
70: $store->convertPrice($price, false, false)
71: ));
72: $rateXmlObj->addAttribute('formated_price', $formattedPrice);
73: }
74: }
75: }
76: } else {
77: Mage::throwException($this->__('Shipping to this address is not possible.'));
78: }
79: return $methodsXmlObj->asNiceXml();
80: }
81: }
82: