public function testCollectRates() { $this->mockIsActive(true); $this->mockGetLocations(); $this->mockBuildRateForLocation(); $this->rateResult->expects($this->once())->method('append')->with($this->method); $result = $this->model->collectRates(new \Magento\Framework\Object()); $this->assertInstanceOf('Magento\\Shipping\\Model\\Rate\\Result', $result); }
/** * Add a tracking to the result * * @param AbstractResult|RateResult $result * @return $this */ public function append($result) { if ($result instanceof AbstractResult) { $this->_trackings[] = $result; } elseif ($result instanceof RateResult) { $trackings = $result->getAllTrackings(); foreach ($trackings as $track) { $this->append($track); } } return $this; }
/** * 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; }
/** * @return $this */ protected function _getExpressRate() { $rate = $this->_rateMethodFactory->create(); $rate->setCarrier($this->_code); $rate->setCarrierTitle($this->getConfigData('title')); $rate->setMethodTitle('Express delivery'); $rate->setPrice(2.5); $rate->setCost(0); $this->_result->append($rate); return $this; }
/** * Get tracking response * * @return string */ public function getResponse() { $statuses = ''; if ($this->_result instanceof \Magento\Shipping\Model\Tracking\Result) { if ($trackings = $this->_result->getAllTrackings()) { foreach ($trackings as $tracking) { if ($data = $tracking->getAllData()) { if (!empty($data['track_summary'])) { $statuses .= __($data['track_summary']); } else { $statuses .= __('Empty response'); } } } } } if (empty($statuses)) { $statuses = __('Empty response'); } return $statuses; }
/** * @param \Magento\Shipping\Model\Rate\Result $result * @param string $methodId * @param \stdClass $method * @param string $msg * @return \Owebia\ShippingFree\Model\Carrier */ protected function appendError(\Magento\Shipping\Model\Rate\Result $result, $methodId, \stdClass $method, $msg) { if ($this->getConfigData('showmethod') != 0) { $error = $this->_rateErrorFactory->create(); $error->setCarrier($this->_code); $error->setCarrierTitle($this->getConfigData('title')); $methodTitle = isset($method->title) ? $method->title : "Method `{$methodId}`"; $error->setErrorMessage("{$methodTitle} - {$msg}"); $result->append($error); } return $this; }