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_Sales
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: /**
29: * Enter description here ...
30: *
31: * @method Mage_Sales_Model_Resource_Quote_Address_Rate _getResource()
32: * @method Mage_Sales_Model_Resource_Quote_Address_Rate getResource()
33: * @method int getAddressId()
34: * @method Mage_Sales_Model_Quote_Address_Rate setAddressId(int $value)
35: * @method string getCreatedAt()
36: * @method Mage_Sales_Model_Quote_Address_Rate setCreatedAt(string $value)
37: * @method string getUpdatedAt()
38: * @method Mage_Sales_Model_Quote_Address_Rate setUpdatedAt(string $value)
39: * @method string getCarrier()
40: * @method Mage_Sales_Model_Quote_Address_Rate setCarrier(string $value)
41: * @method string getCarrierTitle()
42: * @method Mage_Sales_Model_Quote_Address_Rate setCarrierTitle(string $value)
43: * @method string getCode()
44: * @method Mage_Sales_Model_Quote_Address_Rate setCode(string $value)
45: * @method string getMethod()
46: * @method Mage_Sales_Model_Quote_Address_Rate setMethod(string $value)
47: * @method string getMethodDescription()
48: * @method Mage_Sales_Model_Quote_Address_Rate setMethodDescription(string $value)
49: * @method float getPrice()
50: * @method Mage_Sales_Model_Quote_Address_Rate setPrice(float $value)
51: * @method string getErrorMessage()
52: * @method Mage_Sales_Model_Quote_Address_Rate setErrorMessage(string $value)
53: * @method string getMethodTitle()
54: * @method Mage_Sales_Model_Quote_Address_Rate setMethodTitle(string $value)
55: *
56: * @category Mage
57: * @package Mage_Sales
58: * @author Magento Core Team <core@magentocommerce.com>
59: */
60: class Mage_Sales_Model_Quote_Address_Rate extends Mage_Shipping_Model_Rate_Abstract
61: {
62: protected $_address;
63:
64: protected function _construct()
65: {
66: $this->_init('sales/quote_address_rate');
67: }
68:
69: protected function _beforeSave()
70: {
71: parent::_beforeSave();
72: if ($this->getAddress()) {
73: $this->setAddressId($this->getAddress()->getId());
74: }
75: return $this;
76: }
77:
78: public function setAddress(Mage_Sales_Model_Quote_Address $address)
79: {
80: $this->_address = $address;
81: return $this;
82: }
83:
84: public function getAddress()
85: {
86: return $this->_address;
87: }
88:
89: public function importShippingRate(Mage_Shipping_Model_Rate_Result_Abstract $rate)
90: {
91: if ($rate instanceof Mage_Shipping_Model_Rate_Result_Error) {
92: $this
93: ->setCode($rate->getCarrier().'_error')
94: ->setCarrier($rate->getCarrier())
95: ->setCarrierTitle($rate->getCarrierTitle())
96: ->setErrorMessage($rate->getErrorMessage())
97: ;
98: } elseif ($rate instanceof Mage_Shipping_Model_Rate_Result_Method) {
99: $this
100: ->setCode($rate->getCarrier().'_'.$rate->getMethod())
101: ->setCarrier($rate->getCarrier())
102: ->setCarrierTitle($rate->getCarrierTitle())
103: ->setMethod($rate->getMethod())
104: ->setMethodTitle($rate->getMethodTitle())
105: ->setMethodDescription($rate->getMethodDescription())
106: ->setPrice($rate->getPrice())
107: ;
108: }
109: return $this;
110: }
111: }
112: