9 use Magento\Customer\Api\Data\AddressInterfaceFactory;
60 private $dataProcessor;
65 private $addressFactory;
70 private $quoteAddressResource;
87 AddressInterfaceFactory $addressFactory =
null,
95 ->get(AddressInterfaceFactory::class);
97 ->get(QuoteAddressResource::class);
111 throw new StateException(
__(
'The shipping address is missing. Set the address and try again.'));
122 if (!$shippingRate) {
125 return $this->converter->modelToDataObject($shippingRate,
$quote->getQuoteCurrencyCode());
139 if (
$quote->isVirtual() || 0 ==
$quote->getItemsCount()) {
145 throw new StateException(
__(
'The shipping address is missing. Set the address and try again.'));
149 foreach ($shippingRates as $carrierRates) {
150 foreach ($carrierRates as
$rate) {
151 $output[] = $this->converter->modelToDataObject(
$rate,
$quote->getQuoteCurrencyCode());
166 }
catch (\Exception $e) {
171 $this->quoteRepository->save(
$quote->collectTotals());
172 }
catch (\Exception $e) {
173 throw new CouldNotSaveException(
__(
'The shipping method can\'t be set. %1', $e->getMessage()));
192 if (0 ==
$quote->getItemsCount()) {
193 throw new InputException(
194 __(
'The shipping method can\'t be set for an empty cart. Add an item to cart and try again.')
197 if (
$quote->isVirtual()) {
198 throw new NoSuchEntityException(
199 __(
'The Cart includes virtual product(s) only, so a shipping address is not used.')
206 throw new StateException(
__(
'The shipping address is missing. Set the address and try again.'));
220 if (
$quote->isVirtual() || 0 ==
$quote->getItemsCount()) {
236 if (
$quote->isVirtual() || 0 ==
$quote->getItemsCount()) {
251 if (
$quote->isVirtual() || 0 ==
$quote->getItemsCount()) {
254 $address = $this->addressRepository->getById($addressId);
280 $address = $this->getAddressFactory()->create()
281 ->setCountryId($country)
282 ->setPostcode($postcode)
283 ->setRegionId($regionId)
284 ->setRegion($region);
305 foreach ($shippingRates as $carrierRates) {
306 foreach ($carrierRates as
$rate) {
307 $output[] = $this->converter->modelToDataObject(
$rate,
$quote->getQuoteCurrencyCode());
319 private function extractAddressData(
$address)
321 $className = \Magento\Customer\Api\Data\AddressInterface::class;
323 $className = \Magento\Quote\Api\Data\AddressInterface::class;
327 return $this->getDataObjectProcessor()->buildOutputDataArray(
339 private function getDataObjectProcessor()
341 if ($this->dataProcessor ===
null) {
343 ->get(DataObjectProcessor::class);
345 return $this->dataProcessor;
estimateByAddress($cartId, \Magento\Quote\Api\Data\EstimateAddressInterface $address)
elseif(isset( $params[ 'redirect_parent']))
__construct(\Magento\Quote\Api\CartRepositoryInterface $quoteRepository, Cart\ShippingMethodConverter $converter, \Magento\Customer\Api\AddressRepositoryInterface $addressRepository, \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector, AddressInterfaceFactory $addressFactory=null, QuoteAddressResource $quoteAddressResource=null)
getEstimatedRates(\Magento\Quote\Model\Quote $quote, $country, $postcode, $regionId, $region, $address=null)
estimateByAddressId($cartId, $addressId)
estimateByExtendedAddress($cartId, AddressInterface $address)