addressValidator = $addressValidator; $this->logger = $logger; $this->quoteRepository = $quoteRepository; $this->addressRepository = $addressRepository; } /** * @inheritdoc * @SuppressWarnings(PHPMD.NPathComplexity) */ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false) { /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->getActive($cartId); $address->setCustomerId($quote->getCustomerId()); $quote->removeAddress($quote->getBillingAddress()->getId()); $quote->setBillingAddress($address); try { $this->getShippingAddressAssignment()->setAddress($quote, $address, $useForShipping); $quote->setDataChanges(true); $this->quoteRepository->save($quote); } catch (\Exception $e) { $this->logger->critical($e); throw new InputException(__('The address failed to save. Verify the address and try again.')); } return $quote->getBillingAddress()->getId(); } /** * @inheritdoc */ public function get($cartId) { $cart = $this->quoteRepository->getActive($cartId); return $cart->getBillingAddress(); } /** * Get shipping address assignment * * @return \Magento\Quote\Model\ShippingAddressAssignment * @deprecated 101.0.0 */ private function getShippingAddressAssignment() { if (!$this->shippingAddressAssignment) { $this->shippingAddressAssignment = ObjectManager::getInstance() ->get(\Magento\Quote\Model\ShippingAddressAssignment::class); } return $this->shippingAddressAssignment; } }