/** * Check whether VAT ID validation is enabled * * @param \Magento\Quote\Model\Quote\Address $quoteAddress * @param \Magento\Store\Model\Store|int $store * @return bool */ public function isEnabled(\Magento\Quote\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; }
/** * @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; }
/** * Create customer address and save it in the quote so that it can be used to persist later. * * @param \Magento\Customer\Api\Data\CustomerInterface $customer * @param \Magento\Quote\Model\Quote\Address $quoteCustomerAddress * @return void * @throws \InvalidArgumentException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _prepareCustomerAddress($customer, $quoteCustomerAddress) { // Possible that customerId is null for new customers $quoteCustomerAddress->setCustomerId($customer->getId()); $customerAddress = $quoteCustomerAddress->exportCustomerAddress(); $quoteAddressId = $quoteCustomerAddress->getCustomerAddressId(); $addressType = $quoteCustomerAddress->getAddressType(); if ($quoteAddressId) { /** Update existing address */ $existingAddressDataObject = $this->addressRepository->getById($quoteAddressId); /** Update customer address data */ $this->dataObjectHelper->mergeDataObjects(get_class($existingAddressDataObject), $existingAddressDataObject, $customerAddress); $customerAddress = $existingAddressDataObject; } elseif ($addressType == \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING) { try { $billingAddressDataObject = $this->accountManagement->getDefaultBillingAddress($customer->getId()); } catch (\Exception $e) { /** Billing address does not exist. */ } $isShippingAsBilling = $quoteCustomerAddress->getSameAsBilling(); if (isset($billingAddressDataObject) && $isShippingAsBilling) { /** Set existing billing address as default shipping */ $customerAddress = $billingAddressDataObject; $customerAddress->setIsDefaultShipping(true); } } switch ($addressType) { case \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_BILLING: if (is_null($customer->getDefaultBilling())) { $customerAddress->setIsDefaultBilling(true); } break; case \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING: if (is_null($customer->getDefaultShipping())) { $customerAddress->setIsDefaultShipping(true); } break; default: throw new \InvalidArgumentException('Customer address type is invalid.'); } $this->getQuote()->setCustomer($customer); $this->getQuote()->addCustomerAddress($customerAddress); }
/** * @param Address $address * @return string */ protected function getAddressId(Address $address) { if ($address == null) { return ''; } if (!$address->hasData('address_sales_rule_id')) { if ($address->hasData('address_id')) { $address->setData('address_sales_rule_id', $address->getData('address_id')); } else { $type = $address->getAddressType(); $tempId = $type . $this->counter++; $address->setData('address_sales_rule_id', $tempId); } } return $address->getData('address_sales_rule_id'); }
/** * 2016-07-27 * Адрес приобретает тип, только когда используется при оформлении заказа. * Пока же адрес просто принадлежит покупателю * @see \Magento\Customer\Model\Data\Address * @see \Magento\Customer\Api\Data\AddressInterface * а не используется в контексте оформления заказа, то такой адрес ещё типа не имеет, * и в будущем, в зависимости от контекста, * может использоваться и как адрес доставки, и как платёжный адрес. * * @uses \Magento\Quote\Model\Quote\Address::getAddressType() * @uses \Magento\Customer\Model\Address::getAddressType() * @param AA|CA|QA|OA $a * @return bool */ function df_address_is_billing($a) { return $a instanceof AA ? AA::TYPE_BILLING === $a['address_type'] : ($a instanceof OA ? OA::TYPE_BILLING === $a->getAddressType() : df_error("Invalid address class: «%s».", get_class($a))); }