本文整理汇总了PHP中Magento\Quote\Model\Quote::addCustomerAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP Quote::addCustomerAddress方法的具体用法?PHP Quote::addCustomerAddress怎么用?PHP Quote::addCustomerAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Quote\Model\Quote
的用法示例。
在下文中一共展示了Quote::addCustomerAddress方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _prepareCustomerQuote
/**
* Prepare quote for customer order submit
*
* @param Quote $quote
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function _prepareCustomerQuote($quote)
{
/** @var Quote $quote */
$billing = $quote->getBillingAddress();
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
$customer = $this->customerRepository->getById($quote->getCustomerId());
$hasDefaultBilling = (bool) $customer->getDefaultBilling();
$hasDefaultShipping = (bool) $customer->getDefaultShipping();
if ($shipping && !$shipping->getSameAsBilling() && (!$shipping->getCustomerId() || $shipping->getSaveInAddressBook())) {
$shippingAddress = $shipping->exportCustomerAddress();
if (!$hasDefaultShipping) {
//Make provided address as default shipping address
$shippingAddress->setIsDefaultShipping(true);
$hasDefaultShipping = true;
}
$quote->addCustomerAddress($shippingAddress);
$shipping->setCustomerAddressData($shippingAddress);
}
if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) {
$billingAddress = $billing->exportCustomerAddress();
if (!$hasDefaultBilling) {
//Make provided address as default shipping address
if (!$hasDefaultShipping) {
//Make provided address as default shipping address
$billingAddress->setIsDefaultShipping(true);
}
$billingAddress->setIsDefaultBilling(true);
}
$quote->addCustomerAddress($billingAddress);
$billing->setCustomerAddressData($billingAddress);
}
if ($shipping && !$shipping->getCustomerId() && !$hasDefaultBilling) {
$shipping->setIsDefaultBilling(true);
}
}
示例2: prepareRegisteredCustomerQuote
/**
* @param \Magento\Quote\Model\Quote $quote
* @param int|null $customerId
* @return \Magento\Quote\Model\Quote
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function prepareRegisteredCustomerQuote(\Magento\Quote\Model\Quote $quote, $customerId)
{
$billing = $quote->getBillingAddress();
$shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
$customer = $this->customerRepository->getById($customerId);
$isBillingAddressDefaultBilling = !$customer->getDefaultBilling();
$isBillingAddressDefaultShipping = false;
$isShippingAddressDefaultShipping = false;
if ($shipping && !$customer->getDefaultShipping()) {
$isShippingAddressDefaultShipping = true;
} elseif (!$customer->getDefaultShipping()) {
$isBillingAddressDefaultShipping = true;
}
if ($shipping && $shipping->getTelephone() && !$shipping->getSameAsBilling() && (!$shipping->getCustomerId() || $shipping->getSaveInAddressBook() || !$customer->getDefaultShipping())) {
$address = $shipping->exportCustomerAddress();
$address->setIsDefaultShipping($isShippingAddressDefaultShipping);
$quote->addCustomerAddress($address);
}
if ($billing && $billing->getTelephone() && (!$customer->getDefaultBilling() || $billing->getSaveInAddressBook())) {
$address = $billing->exportCustomerAddress();
$address->setIsDefaultBilling($isBillingAddressDefaultBilling);
$address->setIsDefaultShipping($isBillingAddressDefaultShipping);
$quote->addCustomerAddress($address);
}
return $quote;
}