/** * Prepare and set request to this instance * * @param \Magento\Quote\Model\Quote\Address\RateRequest $request * @return $this */ public function setRequest(\Magento\Quote\Model\Quote\Address\RateRequest $request) { if (is_array($request->getAllItems())) { $item = current($request->getAllItems()); if ($item instanceof QuoteItem) { $request->setQuote($item->getQuote()); $this->quote = $item->getQuote(); } } //SHQ16-1261 - further detail as values not on shipping address if (!$this->quote) { $this->quote = $this->shipperDataHelper->getQuote(); } $shippingAddress = $this->quote->getShippingAddress(); $key = $this->shipperDataHelper->getAddressKey($shippingAddress); $existing = $this->checkoutSession->getShipAddressValidation(); $validate = true; if (is_array($existing)) { if (isset($existing['key']) && $existing['key'] == $key) { $validate = false; } } else { $validate = $this->shipperRateHelper->shouldValidateAddress($shippingAddress->getValidationStatus(), $shippingAddress->getDestinationType()); } $request->setValidateAddress($validate); $request->setSelectedOptions($this->getSelectedOptions($shippingAddress)); $isCheckout = $this->shipperDataHelper->isCheckout($this->quote); $cartType = !is_null($isCheckout) && $isCheckout != 1 ? "CART" : "STD"; if ($this->quote->getIsMultiShipping()) { $cartType = 'MAC'; } $request->setCartType($cartType); $this->eventManager->dispatch('shipperhq_carrier_set_request', ['request' => $request]); $this->shipperRequest = $this->shipperMapper->getShipperTranslation($request); $this->rawRequest = $request; return $this; }