Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Rate.php
Go to the documentation of this file.
1 <?php
7 
9 
38 class Rate extends AbstractModel
39 {
43  protected $_address;
44 
48  protected function _construct()
49  {
50  $this->_init(\Magento\Quote\Model\ResourceModel\Quote\Address\Rate::class);
51  }
52 
56  public function beforeSave()
57  {
58  parent::beforeSave();
59  if ($this->getAddress()) {
60  $this->setAddressId($this->getAddress()->getId());
61  }
62  return $this;
63  }
64 
69  public function setAddress(\Magento\Quote\Model\Quote\Address $address)
70  {
71  $this->_address = $address;
72  return $this;
73  }
74 
78  public function getAddress()
79  {
80  return $this->_address;
81  }
82 
87  public function importShippingRate(\Magento\Quote\Model\Quote\Address\RateResult\AbstractResult $rate)
88  {
89  if ($rate instanceof \Magento\Quote\Model\Quote\Address\RateResult\Error) {
90  $this->setCode(
91  $rate->getCarrier() . '_error'
92  )->setCarrier(
93  $rate->getCarrier()
94  )->setCarrierTitle(
95  $rate->getCarrierTitle()
96  )->setErrorMessage(
97  $rate->getErrorMessage()
98  );
99  } elseif ($rate instanceof \Magento\Quote\Model\Quote\Address\RateResult\Method) {
100  $this->setCode(
101  $rate->getCarrier() . '_' . $rate->getMethod()
102  )->setCarrier(
103  $rate->getCarrier()
104  )->setCarrierTitle(
105  $rate->getCarrierTitle()
106  )->setMethod(
107  $rate->getMethod()
108  )->setMethodTitle(
109  $rate->getMethodTitle()
110  )->setMethodDescription(
111  $rate->getMethodDescription()
112  )->setPrice(
113  $rate->getPrice()
114  );
115  }
116  return $this;
117  }
118 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
importShippingRate(\Magento\Quote\Model\Quote\Address\RateResult\AbstractResult $rate)
Definition: Rate.php:87
$address
Definition: customer.php:38
setAddress(\Magento\Quote\Model\Quote\Address $address)
Definition: Rate.php:69