/** * @param Address $address * @return mixed */ public function getShippingAddressTotals($address) { $totals = $address->getTotals(); foreach ($totals as $total) { if ($total->getCode() == 'grand_total') { if ($address->getAddressType() == Address::TYPE_BILLING) { $total->setTitle(__('Total')); } else { $total->setTitle(__('Total for this address')); } } } return $totals; }
/** * Convert quote address to order address * * @param \Magento\Sales\Model\Quote\Address $address * @return \Magento\Sales\Model\Order\Address */ public function addressToOrderAddress(\Magento\Sales\Model\Quote\Address $address) { $orderAddress = $this->_orderAddressFactory->create()->setStoreId($address->getStoreId())->setAddressType($address->getAddressType())->setCustomerId($address->getCustomerId())->setCustomerAddressId($address->getCustomerAddressId()); $this->_objectCopyService->copyFieldsetToTarget('sales_convert_quote_address', 'to_order_address', $address, $orderAddress); $this->_eventManager->dispatch('sales_convert_quote_address_to_order_address', array('address' => $address, 'order_address' => $orderAddress)); return $orderAddress; }
/** * Create customerAddressDataObject and save it in the Model\Quote so that it can be used to persist later. * * @param CustomerDataObject $customerDataObject * @param \Magento\Sales\Model\Quote\Address $quoteCustomerAddress * @return void * @throws \InvalidArgumentException */ protected function _prepareCustomerAddress($customerDataObject, $quoteCustomerAddress) { // Possible that customerId is null for new customers $customerId = $customerDataObject->getId(); $quoteCustomerAddress->setCustomerId($customerId); $customerAddressDataObject = $quoteCustomerAddress->exportCustomerAddressData(); $quoteAddressId = $quoteCustomerAddress->getCustomerAddressId(); $addressType = $quoteCustomerAddress->getAddressType(); if ($quoteAddressId) { /** Update existing address */ $existingAddressDataObject = $this->_customerAddressService->getAddress($quoteAddressId); /** Update customer address data */ $customerAddressDataObject = $this->_customerAddressBuilder->mergeDataObjects($existingAddressDataObject, $customerAddressDataObject); } elseif ($addressType == CustomerAddressDataObject::ADDRESS_TYPE_SHIPPING) { try { $billingAddressDataObject = $this->_customerAddressService->getDefaultBillingAddress($customerId); } catch (\Exception $e) { /** Billing address does not exist. */ } $isShippingAsBilling = $quoteCustomerAddress->getSameAsBilling(); if (isset($billingAddressDataObject) && $isShippingAsBilling) { /** Set existing billing address as default shipping */ $customerAddressDataObject = $this->_customerAddressBuilder->populate($billingAddressDataObject)->setDefaultShipping(true)->create(); } } switch ($addressType) { case CustomerAddressDataObject::ADDRESS_TYPE_BILLING: if (is_null($customerDataObject->getDefaultBilling())) { $customerAddressDataObject = $this->_customerAddressBuilder->populate($customerAddressDataObject)->setDefaultBilling(true)->create(); } break; case CustomerAddressDataObject::ADDRESS_TYPE_SHIPPING: if (is_null($customerDataObject->getDefaultShipping())) { $customerAddressDataObject = $this->_customerAddressBuilder->populate($customerAddressDataObject)->setDefaultShipping(true)->create(); } break; default: throw new \InvalidArgumentException('Customer address type is invalid.'); } $this->getQuote()->addCustomerAddressData($customerAddressDataObject); }
/** * Check whether VAT ID validation is enabled * * @param \Magento\Sales\Model\Quote\Address $quoteAddress * @param \Magento\Store\Model\Store|int $store * @return bool */ public function isEnabled(\Magento\Sales\Model\Quote\Address $quoteAddress, $store) { $configAddressType = $this->customerAddress->getTaxCalculationAddressType($store); // When VAT is based on billing address then Magento have to handle only billing addresses $additionalBillingAddressCondition = $configAddressType == \Magento\Customer\Model\Address\AbstractAddress::TYPE_BILLING ? $configAddressType != $quoteAddress->getAddressType() : false; // Handle only addresses that corresponds to VAT configuration if (!$this->customerAddress->isVatValidationEnabled($store) || $additionalBillingAddressCondition) { return false; } return true; }