1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_XmlConnect
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * PayPal MECL Shipping method list xml renderer
29: *
30: * @category Mage
31: * @package Mage_Xmlconnect
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_XmlConnect_Block_Cart_Paypal_Mecl_Shippingmethods
35: extends Mage_Paypal_Block_Express_Review
36: {
37: /**
38: * Render PayPal MECL shipping method list xml
39: *
40: * @return string xml
41: */
42: protected function _toHtml()
43: {
44: /** @var $listXmlObj Mage_XmlConnect_Model_Simplexml_Element */
45: $methodListXmlObj = Mage::getModel(
46: 'xmlconnect/simplexml_element',
47: '<shipping_method_list></shipping_method_list>'
48: );
49:
50: $methodListXmlObj->addAttribute('label', $this->__('Shipping Method'));
51:
52: if ($this->getCanEditShippingMethod() || !$this->getCurrentShippingRate()) {
53: $groups = $this->getShippingRateGroups();
54: if ($groups) {
55: $currentRate = $this->getCurrentShippingRate();
56: foreach ($groups as $code => $rates) {
57: $rateXmlObj = $this->_addRatesToXmlObj($methodListXmlObj, $code);
58: foreach ($rates as $rate) {
59: $rateAttributes = array(
60: 'label' => strip_tags($this->renderShippingRateOption($rate)),
61: 'code' => $this->renderShippingRateValue($rate)
62: );
63: if ($currentRate === $rate) {
64: $rateAttributes += array('selected' => 1);
65: }
66: $rateXmlObj->addCustomChild('rate', null, $rateAttributes);
67: }
68: }
69: } else {
70: $message = $this->_quote->isVirtual() ? $this->__('No shipping method required.')
71: : $this->__('Sorry, no quotes are available for this order at this time.');
72: $methodListXmlObj->addCustomChild('method', null, array('label' => $message));
73: }
74: } else {
75: $rateXmlObj = $this->_addRatesToXmlObj($methodListXmlObj);
76: $rateXmlObj->addCustomChild('rate', null, array(
77: 'label' => $this->renderShippingRateOption($this->getCurrentShippingRate()),
78: 'selected' => 1
79: ));
80: }
81:
82: return $methodListXmlObj->asNiceXml();
83: }
84:
85: /**
86: * Add cart details to XML object
87: *
88: * @param Mage_XmlConnect_Model_Simplexml_Element $methodListXmlObj
89: * @param string $code
90: * @return Mage_XmlConnect_Model_Simplexml_Element
91: */
92: protected function _addRatesToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $methodListXmlObj, $code = '')
93: {
94: $attributes = $code ? array('label' => $this->getCarrierName($code)) : array();
95: return $methodListXmlObj->addCustomChild('method', null, $attributes)->addCustomChild('rates');
96: }
97: }
98: