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


PHP Observer::getQuoteAddress方法代碼示例

本文整理匯總了PHP中Magento\Framework\Event\Observer::getQuoteAddress方法的典型用法代碼示例。如果您正苦於以下問題:PHP Observer::getQuoteAddress方法的具體用法?PHP Observer::getQuoteAddress怎麽用?PHP Observer::getQuoteAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Framework\Event\Observer的用法示例。


在下文中一共展示了Observer::getQuoteAddress方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: dispatch

 /**
  * Handle customer VAT number if needed on collect_totals_before event of quote address
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function dispatch(\Magento\Framework\Event\Observer $observer)
 {
     /** @var \Magento\Sales\Model\Quote\Address $quoteAddress */
     $quoteAddress = $observer->getQuoteAddress();
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = $quoteAddress->getQuote();
     $customerData = $quote->getCustomerData();
     $storeId = $customerData->getStoreId();
     if ($customerData->getCustomAttribute('disable_auto_group_change') && $customerData->getCustomAttribute('disable_auto_group_change')->getValue() || false == $this->vatValidator->isEnabled($quoteAddress, $storeId)) {
         return;
     }
     $customerCountryCode = $quoteAddress->getCountryId();
     $customerVatNumber = $quoteAddress->getVatId();
     $groupId = null;
     if (empty($customerVatNumber) || false == $this->customerHelper->isCountryInEU($customerCountryCode)) {
         $groupId = $customerData->getId() ? $this->customerHelper->getDefaultCustomerGroupId($storeId) : \Magento\Customer\Service\V1\CustomerGroupServiceInterface::NOT_LOGGED_IN_ID;
     } else {
         // Magento always has to emulate group even if customer uses default billing/shipping address
         $groupId = $this->customerHelper->getCustomerGroupIdBasedOnVatNumber($customerCountryCode, $this->vatValidator->validate($quoteAddress, $storeId), $storeId);
     }
     if ($groupId) {
         $quoteAddress->setPrevQuoteCustomerGroupId($quote->getCustomerGroupId());
         $quote->setCustomerGroupId($groupId);
         $customerData = $this->customerBuilder->mergeDataObjectWithArray($customerData, array('group_id' => $groupId));
         $quote->setCustomerData($customerData);
     }
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:33,代碼來源:CollectTotals.php

示例2: dispatch

 /**
  * Handle customer VAT number if needed on collect_totals_before event of quote address
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function dispatch(\Magento\Framework\Event\Observer $observer)
 {
     /** @var \Magento\Quote\Model\Quote\Address $quoteAddress */
     $quoteAddress = $observer->getQuoteAddress();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $quoteAddress->getQuote();
     $customer = $quote->getCustomer();
     $storeId = $customer->getStoreId();
     if ($customer->getCustomAttribute('disable_auto_group_change') && $customer->getCustomAttribute('disable_auto_group_change')->getValue() || false == $this->vatValidator->isEnabled($quoteAddress, $storeId)) {
         return;
     }
     $customerCountryCode = $quoteAddress->getCountryId();
     $customerVatNumber = $quoteAddress->getVatId();
     $groupId = null;
     if (empty($customerVatNumber) || false == $this->customerVat->isCountryInEU($customerCountryCode)) {
         $groupId = $customer->getId() ? $this->groupManagement->getDefaultGroup($storeId)->getId() : $this->groupManagement->getNotLoggedInGroup()->getId();
     } else {
         // Magento always has to emulate group even if customer uses default billing/shipping address
         $groupId = $this->customerVat->getCustomerGroupIdBasedOnVatNumber($customerCountryCode, $this->vatValidator->validate($quoteAddress, $storeId), $storeId);
     }
     if ($groupId) {
         $quoteAddress->setPrevQuoteCustomerGroupId($quote->getCustomerGroupId());
         $quote->setCustomerGroupId($groupId);
         $customer->setGroupId($groupId);
         $quote->setCustomer($customer);
     }
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:33,代碼來源:CollectTotals.php

示例3: execute

 /**
  * Restore initial customer group ID in quote if needed on collect_totals_after event of quote address
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute($observer)
 {
     $quoteAddress = $observer->getQuoteAddress();
     $configAddressType = $this->customerAddressHelper->getTaxCalculationAddressType();
     // Restore initial customer group ID in quote only if VAT is calculated based on shipping address
     if ($quoteAddress->hasPrevQuoteCustomerGroupId() && $configAddressType == \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING) {
         $quoteAddress->getQuote()->setCustomerGroupId($quoteAddress->getPrevQuoteCustomerGroupId());
         $quoteAddress->unsPrevQuoteCustomerGroupId();
     }
 }
開發者ID:pavelnovitsky,項目名稱:magento2,代碼行數:16,代碼來源:RestoreCustomerGroupId.php


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