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_Adminhtml
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: * Adminhtml sales order create shipping method form block
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Sales_Order_Create_Shipping_Method_Form
35: extends Mage_Adminhtml_Block_Sales_Order_Create_Abstract
36: {
37: protected $_rates;
38:
39: public function __construct()
40: {
41: parent::__construct();
42: $this->setId('sales_order_create_shipping_method_form');
43: }
44:
45: /**
46: * Retrieve quote shipping address model
47: *
48: * @return Mage_Sales_Model_Quote_Address
49: */
50: public function getAddress()
51: {
52: return $this->getQuote()->getShippingAddress();
53: }
54:
55: /**
56: * Retrieve array of shipping rates groups
57: *
58: * @return array
59: */
60: public function getShippingRates()
61: {
62: if (empty($this->_rates)) {
63: $groups = $this->getAddress()->getGroupedAllShippingRates();
64: /*
65: if (!empty($groups)) {
66:
67: $ratesFilter = new Varien_Filter_Object_Grid();
68: $ratesFilter->addFilter($this->getStore()->getPriceFilter(), 'price');
69:
70: foreach ($groups as $code => $groupItems) {
71: $groups[$code] = $ratesFilter->filter($groupItems);
72: }
73: }
74: */
75: return $this->_rates = $groups;
76: }
77: return $this->_rates;
78: }
79:
80: /**
81: * Rertrieve carrier name from store configuration
82: *
83: * @param string $carrierCode
84: * @return string
85: */
86: public function getCarrierName($carrierCode)
87: {
88: if ($name = Mage::getStoreConfig('carriers/'.$carrierCode.'/title', $this->getStore()->getId())) {
89: return $name;
90: }
91: return $carrierCode;
92: }
93:
94: /**
95: * Retrieve current selected shipping method
96: *
97: * @return string
98: */
99: public function getShippingMethod()
100: {
101: return $this->getAddress()->getShippingMethod();
102: }
103:
104: /**
105: * Check activity of method by code
106: *
107: * @param string $code
108: * @return bool
109: */
110: public function isMethodActive($code)
111: {
112: return $code===$this->getShippingMethod();
113: }
114:
115: /**
116: * Retrieve rate of active shipping method
117: *
118: * @return Mage_Sales_Model_Quote_Address_Rate || false
119: */
120: public function getActiveMethodRate()
121: {
122: $rates = $this->getShippingRates();
123: if (is_array($rates)) {
124: foreach ($rates as $group) {
125: foreach ($group as $code => $rate) {
126: if ($rate->getCode() == $this->getShippingMethod()) {
127: return $rate;
128: }
129: }
130: }
131: }
132: return false;
133: }
134:
135: public function getIsRateRequest()
136: {
137: return $this->getRequest()->getParam('collect_shipping_rates');
138: }
139:
140: public function getShippingPrice($price, $flag)
141: {
142: return $this->getQuote()->getStore()->convertPrice(
143: Mage::helper('tax')->getShippingPrice(
144: $price,
145: $flag,
146: $this->getAddress(),
147: null,
148: //We should send exact quote store to prevent fetching default config for admin store.
149: $this->getAddress()->getQuote()->getStore()
150: ),
151: true
152: );
153: }
154: }
155: