/**
  * Add a rate to the result
  *
  * @param \Magento\Quote\Model\Quote\Address\RateResult\AbstractResult|\Magento\Shipping\Model\Rate\Result $result
  * @return $this
  */
 public function append($result)
 {
     if ($result instanceof \Magento\Quote\Model\Quote\Address\RateResult\Error) {
         $this->setError(true);
     }
     if ($result instanceof \Magento\Quote\Model\Quote\Address\RateResult\AbstractResult) {
         $this->_rates[] = $result;
     } elseif ($result instanceof \Magento\Shipping\Model\Rate\Result) {
         $rates = $result->getAllRates();
         foreach ($rates as $rate) {
             $this->append($rate);
         }
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Do remote request for and handle errors
  *
  * @return Result
  */
 protected function _getQuotes()
 {
     $this->_result = $this->_rateFactory->create();
     // make separate request for Smart Post method
     $allowedMethods = explode(',', $this->getConfigData('allowed_methods'));
     if (in_array(self::RATE_REQUEST_SMARTPOST, $allowedMethods)) {
         $response = $this->_doRatesRequest(self::RATE_REQUEST_SMARTPOST);
         $preparedSmartpost = $this->_prepareRateResponse($response);
         if (!$preparedSmartpost->getError()) {
             $this->_result->append($preparedSmartpost);
         }
     }
     // make general request for all methods
     $response = $this->_doRatesRequest(self::RATE_REQUEST_GENERAL);
     $preparedGeneral = $this->_prepareRateResponse($response);
     if (!$preparedGeneral->getError() || $this->_result->getError() && $preparedGeneral->getError() || empty($this->_result->getAllRates())) {
         $this->_result->append($preparedGeneral);
     }
     return $this->_result;
 }