/** * @param CartInterface $quote * @param AddressInterface $address * @param bool $useForShipping * @return void * @throws NoSuchEntityException * @throws InputException */ public function save(CartInterface $quote, AddressInterface $address, $useForShipping = false) { /** @var \Magento\Quote\Model\Quote $quote */ $this->addressValidator->validate($address); $customerAddressId = $address->getCustomerAddressId(); $shippingAddress = null; $addressData = []; if ($useForShipping) { $shippingAddress = $address; } $saveInAddressBook = $address->getSaveInAddressBook() ? 1 : 0; if ($customerAddressId) { try { $addressData = $this->addressRepository->getById($customerAddressId); } catch (NoSuchEntityException $e) { // do nothing if customer is not found by id } $address = $quote->getBillingAddress()->importCustomerAddressData($addressData); if ($useForShipping) { $shippingAddress = $quote->getShippingAddress()->importCustomerAddressData($addressData); $shippingAddress->setSaveInAddressBook($saveInAddressBook); } } elseif ($quote->getCustomerId()) { $address->setEmail($quote->getCustomerEmail()); } $address->setSaveInAddressBook($saveInAddressBook); $quote->setBillingAddress($address); if ($useForShipping) { $shippingAddress->setSameAsBilling(1); $shippingAddress->setCollectShippingRates(true); $quote->setShippingAddress($shippingAddress); } }
/** * {@inheritdoc} */ public function delete(\Magento\Quote\Api\Data\CartInterface $quote) { $quoteId = $quote->getId(); $customerId = $quote->getCustomerId(); $quote->delete(); unset($this->quotesById[$quoteId]); unset($this->quotesByCustomerId[$customerId]); }
/** * Get details for GetTaxRequest * * @param \Magento\Store\Api\Data\StoreInterface $store * @param $address \Magento\Quote\Api\Data\AddressInterface|\Magento\Sales\Api\Data\OrderAddressInterface * @param \Magento\Quote\Api\Data\CartInterface|\Magento\Sales\Api\Data\OrderInterface $object * @return array * @throws LocalizedException */ protected function retrieveGetTaxRequestFields(StoreInterface $store, $address, $object) { $customerId = $object->getCustomerId(); $customer = $this->getCustomerById($customerId); $storeId = $store->getId(); if ($this->config->getLiveMode() == Config::API_PROFILE_NAME_PROD) { $companyCode = $this->config->getCompanyCode($storeId); } else { $companyCode = $this->config->getDevelopmentCompanyCode($storeId); } $businessIdentificationNumber = $this->getBusinessIdentificationNumber($store, $address, $customer); $locationCode = $this->config->getLocationCode($store); return ['BusinessIdentificationNo' => $businessIdentificationNumber, 'CompanyCode' => $companyCode, 'LocationCode' => $locationCode, 'OriginAddress' => $this->address->getAddress($this->config->getOriginAddress($storeId))]; }