當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Quote::addCustomerAddress方法代碼示例

本文整理匯總了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);
     }
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:43,代碼來源:QuoteManagement.php

示例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;
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:33,代碼來源:Quote.php


注:本文中的Magento\Quote\Model\Quote::addCustomerAddress方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。