当前位置: 首页>>代码示例>>PHP>>正文


PHP AccountManagementInterface::getDefaultShippingAddress方法代码示例

本文整理汇总了PHP中Magento\Customer\Api\AccountManagementInterface::getDefaultShippingAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP AccountManagementInterface::getDefaultShippingAddress方法的具体用法?PHP AccountManagementInterface::getDefaultShippingAddress怎么用?PHP AccountManagementInterface::getDefaultShippingAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Api\AccountManagementInterface的用法示例。


在下文中一共展示了AccountManagementInterface::getDefaultShippingAddress方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSaveActionExistingCustomerAndExistingAddressData

 /**
  * @magentoDataFixture Magento/Customer/_files/customer_sample.php
  */
 public function testSaveActionExistingCustomerAndExistingAddressData()
 {
     $post = ['customer' => ['entity_id' => '1', 'middlename' => 'test middlename', 'group_id' => 1, 'website_id' => 1, 'firstname' => 'test firstname', 'lastname' => 'test lastname', 'email' => 'customer@example.com', 'new_password' => 'auto', 'sendemail_store_id' => '1', 'sendemail' => '1', 'created_at' => '2000-01-01 00:00:00', 'default_shipping' => '_item1', 'default_billing' => 1], 'address' => ['1' => ['firstname' => 'update firstname', 'lastname' => 'update lastname', 'street' => ['update street'], 'city' => 'update city', 'region_id' => 10, 'country_id' => 'US', 'postcode' => '01001', 'telephone' => '+7000000001', 'default_billing' => 'true'], '_item1' => ['firstname' => 'new firstname', 'lastname' => 'new lastname', 'street' => ['new street'], 'city' => 'new city', 'region_id' => 10, 'country_id' => 'US', 'postcode' => '01001', 'telephone' => '+7000000001', 'default_shipping' => 'true'], '_template_' => ['firstname' => '', 'lastname' => '', 'street' => [], 'city' => '', 'region_id' => 10, 'country_id' => 'US', 'postcode' => '', 'telephone' => '']], 'subscription' => ''];
     $this->getRequest()->setPostValue($post);
     $this->getRequest()->setParam('id', 1);
     $this->dispatch('backend/customer/index/save');
     /** Check that success message is set */
     $this->assertSessionMessages($this->equalTo(['You saved the customer.']), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS);
     /** Check that customer id set and addresses saved */
     $registry = $this->objectManager->get('Magento\\Framework\\Registry');
     $customerId = $registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
     $customer = $this->customerRepository->getById($customerId);
     $this->assertEquals('test firstname', $customer->getFirstname());
     /**
      * Addresses should be removed by
      * \Magento\Customer\Model\ResourceModel\Customer::_saveAddresses during _afterSave
      * addressOne - updated
      * addressTwo - removed
      * addressThree - removed
      * _item1 - new address
      */
     $addresses = $customer->getAddresses();
     $this->assertEquals(2, count($addresses));
     $updatedAddress = $this->addressRepository->getById(1);
     $this->assertEquals('update firstname', $updatedAddress->getFirstname());
     $newAddress = $this->accountManagement->getDefaultShippingAddress($customerId);
     $this->assertEquals('new firstname', $newAddress->getFirstname());
     /** @var \Magento\Newsletter\Model\Subscriber $subscriber */
     $subscriber = $this->objectManager->get('Magento\\Newsletter\\Model\\SubscriberFactory')->create();
     $this->assertEmpty($subscriber->getId());
     $subscriber->loadByCustomerId($customerId);
     $this->assertNotEmpty($subscriber->getId());
     $this->assertEquals(1, $subscriber->getStatus());
     $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'index/key/'));
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:38,代码来源:IndexTest.php

示例2: getPrimaryAddresses

 /**
  * Retrieve the customer's primary addresses (i.e. default billing and shipping).
  *
  * @return \Magento\Customer\Api\Data\AddressInterface[]|bool
  */
 public function getPrimaryAddresses()
 {
     $addresses = [];
     $customerId = $this->getCustomer()->getId();
     if ($defaultBilling = $this->customerAccountManagement->getDefaultBillingAddress($customerId)) {
         $addresses[] = $defaultBilling;
     }
     if ($defaultShipping = $this->customerAccountManagement->getDefaultShippingAddress($customerId)) {
         if ($defaultBilling) {
             if ($defaultBilling->getId() != $defaultShipping->getId()) {
                 $addresses[] = $defaultShipping;
             }
         } else {
             $addresses[] = $defaultShipping;
         }
     }
     return empty($addresses) ? false : $addresses;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:23,代码来源:Dashboard.php

示例3: getProductWeeeAttributes

 /**
  * @param Product $product
  * @param null|false|\Magento\Quote\Model\Quote\Address $shipping
  * @param null|false|\Magento\Quote\Model\Quote\Address $billing
  * @param Website $website
  * @param bool $calculateTax
  * @param bool $round
  * @return \Magento\Framework\DataObject[]
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTax = null, $round = true)
 {
     $result = [];
     $websiteId = $this->_storeManager->getWebsite($website)->getId();
     /** @var \Magento\Store\Model\Store $store */
     $store = $this->_storeManager->getWebsite($website)->getDefaultGroup()->getDefaultStore();
     $allWeee = $this->getWeeeTaxAttributeCodes($store);
     if (!$allWeee) {
         return $result;
     }
     /** @var \Magento\Tax\Model\Calculation $calculator */
     $calculator = $this->_calculationFactory->create();
     $customerId = $this->_customerSession->getCustomerId();
     if ($shipping && $shipping->getCountryId()) {
         $customerTaxClass = $shipping->getQuote()->getCustomerTaxClassId();
     } else {
         // if customer logged use it default shipping and billing address
         if ($customerId) {
             $shipping = $this->accountManagement->getDefaultShippingAddress($customerId);
             $billing = $this->accountManagement->getDefaultBillingAddress($customerId);
             $customerTaxClass = null;
         } else {
             $shippingAddressArray = $this->_customerSession->getDefaultTaxShippingAddress();
             $billingAddressArray = $this->_customerSession->getDefaultTaxBillingAddress();
             if (!empty($billingAddressArray)) {
                 $billing = new \Magento\Framework\DataObject($billingAddressArray);
             }
             if (!empty($shippingAddressArray)) {
                 $shipping = new \Magento\Framework\DataObject($shippingAddressArray);
             }
             $customerTaxClass = $this->_customerSession->getCustomerTaxClassId();
         }
     }
     $rateRequest = $calculator->getRateRequest($shipping, $billing, $customerTaxClass, $store, $customerId);
     $defaultRateRequest = $calculator->getDefaultRateRequest($store);
     $productAttributes = $this->getResource()->fetchWeeeTaxCalculationsByEntity($rateRequest->getCountryId(), $rateRequest->getRegionId(), $websiteId, $store->getId(), $product->getId());
     foreach ($productAttributes as $attribute) {
         $value = $attribute['weee_value'];
         if ($value) {
             $taxAmount = $amount = 0;
             $amount = $value;
             $amountExclTax = $value;
             if ($calculateTax && $this->weeeConfig->isTaxable($store)) {
                 /** @var \Magento\Tax\Model\Calculation $calculator */
                 $defaultPercent = $calculator->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId()));
                 $currentPercent = $calculator->getRate($rateRequest->setProductClassId($product->getTaxClassId()));
                 if ($this->_taxData->priceIncludesTax($store)) {
                     $amountInclTax = $value / (100 + $defaultPercent) * (100 + $currentPercent);
                     if ($round) {
                         $amountInclTax = $this->priceCurrency->round($amountInclTax);
                     }
                     $taxAmount = $amountInclTax - $amountInclTax / (100 + $currentPercent) * 100;
                     if ($round) {
                         $taxAmount = $this->priceCurrency->round($taxAmount);
                     }
                     $amountExclTax = $amountInclTax - $taxAmount;
                 } else {
                     $appliedRates = $this->_calculationFactory->create()->getAppliedRates($rateRequest);
                     if (count($appliedRates) > 1) {
                         $taxAmount = 0;
                         foreach ($appliedRates as $appliedRate) {
                             $taxRate = $appliedRate['percent'];
                             if ($round) {
                                 $taxAmount += $this->priceCurrency->round($value * $taxRate / 100);
                             } else {
                                 $taxAmount += $value * $taxRate / 100;
                             }
                         }
                     } else {
                         if ($round) {
                             $taxAmount = $this->priceCurrency->round($value * $currentPercent / 100);
                         } else {
                             $taxAmount = $value * $currentPercent / 100;
                         }
                     }
                 }
             }
             $one = new \Magento\Framework\DataObject();
             $one->setName($attribute['label_value'] ? __($attribute['label_value']) : __($attribute['frontend_label']))->setAmount($amount)->setTaxAmount($taxAmount)->setAmountExclTax($amountExclTax)->setCode($attribute['attribute_code']);
             $result[] = $one;
         }
     }
     return $result;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:96,代码来源:Tax.php

示例4: testGetDefaultAddressesForNonExistentAddress

 /**
  * @magentoDataFixture  Magento/Customer/_files/customer.php
  */
 public function testGetDefaultAddressesForNonExistentAddress()
 {
     $customerId = 1;
     $this->assertNull($this->accountManagement->getDefaultBillingAddress($customerId));
     $this->assertNull($this->accountManagement->getDefaultShippingAddress($customerId));
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:9,代码来源:AccountManagementTest.php

示例5: getProductWeeeAttributes

 /**
  * @param Product $product
  * @param null|false|\Magento\Quote\Model\Quote\Address $shipping
  * @param null|false|\Magento\Quote\Model\Quote\Address $billing
  * @param Website $website
  * @param bool $calculateTax
  * @return \Magento\Framework\Object[]
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTax = null)
 {
     $result = [];
     $websiteId = $this->_storeManager->getWebsite($website)->getId();
     /** @var \Magento\Store\Model\Store $store */
     $store = $this->_storeManager->getWebsite($website)->getDefaultGroup()->getDefaultStore();
     $allWeee = $this->getWeeeTaxAttributeCodes($store);
     if (!$allWeee) {
         return $result;
     }
     /** @var \Magento\Tax\Model\Calculation $calculator */
     $calculator = $this->_calculationFactory->create();
     if ($shipping && $shipping->getCountryId()) {
         $customerTaxClass = $shipping->getQuote()->getCustomerTaxClassId();
     } else {
         // if customer logged use it default shipping and billing address
         if ($customerId = $this->_customerSession->getCustomerId()) {
             $shipping = $this->accountManagement->getDefaultShippingAddress($customerId);
             $billing = $this->accountManagement->getDefaultBillingAddress($customerId);
             $customerTaxClass = null;
         } else {
             $shippingAddressArray = $this->_customerSession->getDefaultTaxShippingAddress();
             $billingAddressArray = $this->_customerSession->getDefaultTaxBillingAddress();
             if (!empty($billingAddressArray)) {
                 $billing = new \Magento\Framework\Object($billingAddressArray);
             }
             if (!empty($shippingAddressArray)) {
                 $shipping = new \Magento\Framework\Object($shippingAddressArray);
             }
             $customerTaxClass = $this->_customerSession->getCustomerTaxClassId();
         }
     }
     $rateRequest = $calculator->getRateRequest($shipping, $billing, $customerTaxClass, $store);
     $defaultRateRequest = $calculator->getDefaultRateRequest($store);
     $productAttributes = $product->getTypeInstance()->getSetAttributes($product);
     foreach ($productAttributes as $code => $attribute) {
         if (in_array($code, $allWeee)) {
             $attributeSelect = $this->getResource()->getReadConnection()->select();
             $attributeSelect->from($this->getResource()->getTable('weee_tax'), 'value')->where('attribute_id = ?', (int) $attribute->getId())->where('website_id IN(?)', [$websiteId, 0])->where('country = ?', $rateRequest->getCountryId())->where('state IN(?)', [$rateRequest->getRegionId(), 0])->where('entity_id = ?', (int) $product->getId())->limit(1);
             $order = ['state ' . \Magento\Framework\DB\Select::SQL_DESC, 'website_id ' . \Magento\Framework\DB\Select::SQL_DESC];
             $attributeSelect->order($order);
             $value = $this->getResource()->getReadConnection()->fetchOne($attributeSelect);
             if ($value) {
                 $taxAmount = $amount = 0;
                 $amount = $value;
                 if ($calculateTax && $this->weeeConfig->isTaxable($store)) {
                     /** @var \Magento\Tax\Model\Calculation $calculator */
                     $defaultPercent = $calculator->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId()));
                     $currentPercent = $calculator->getRate($rateRequest->setProductClassId($product->getTaxClassId()));
                     if ($this->_taxData->priceIncludesTax($store)) {
                         $amountInclTax = $value / (100 + $defaultPercent) * (100 + $currentPercent);
                         //round the "golden price"
                         $amountInclTax = $this->priceCurrency->round($amountInclTax);
                         $taxAmount = $amountInclTax - $amountInclTax / (100 + $currentPercent) * 100;
                         $taxAmount = $this->priceCurrency->round($taxAmount);
                     } else {
                         $appliedRates = $this->_calculationFactory->create()->getAppliedRates($rateRequest);
                         if (count($appliedRates) > 1) {
                             $taxAmount = 0;
                             foreach ($appliedRates as $appliedRate) {
                                 $taxRate = $appliedRate['percent'];
                                 $taxAmount += $this->priceCurrency->round($value * $taxRate / 100);
                             }
                         } else {
                             $taxAmount = $this->priceCurrency->round($value * $currentPercent / 100);
                         }
                         $taxAmount = $this->priceCurrency->round($value * $currentPercent / 100);
                     }
                 }
                 $one = new \Magento\Framework\Object();
                 $one->setName(__($attribute->getFrontend()->getLabel()))->setAmount($amount)->setTaxAmount($taxAmount)->setCode($attribute->getAttributeCode());
                 $result[] = $one;
             }
         }
     }
     return $result;
 }
开发者ID:vasiljok,项目名称:magento2,代码行数:87,代码来源:Tax.php

示例6: getRateRequest

 /**
  * Get request object with information necessary for getting tax rate
  *
  * Request object contain:
  *  country_id (->getCountryId())
  *  region_id (->getRegionId())
  *  postcode (->getPostcode())
  *  customer_class_id (->getCustomerClassId())
  *  store (->getStore())
  *
  * @param null|bool|\Magento\Framework\Object|CustomerAddress $shippingAddress
  * @param null|bool|\Magento\Framework\Object|CustomerAddress $billingAddress
  * @param null|int $customerTaxClass
  * @param null|int|\Magento\Store\Model\Store $store
  * @param int $customerId
  * @return  \Magento\Framework\Object
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function getRateRequest($shippingAddress = null, $billingAddress = null, $customerTaxClass = null, $store = null, $customerId = null)
 {
     if ($shippingAddress === false && $billingAddress === false && $customerTaxClass === false) {
         return $this->getRateOriginRequest($store);
     }
     $address = new \Magento\Framework\Object();
     $basedOn = $this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_BASED_ON, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
     if ($shippingAddress === false && $basedOn == 'shipping' || $billingAddress === false && $basedOn == 'billing') {
         $basedOn = 'default';
     } else {
         if (($billingAddress === null || !$billingAddress->getCountryId()) && $basedOn == 'billing' || ($shippingAddress === null || !$shippingAddress->getCountryId()) && $basedOn == 'shipping') {
             if ($customerId) {
                 try {
                     $defaultBilling = $this->customerAccountManagement->getDefaultBillingAddress($customerId);
                 } catch (NoSuchEntityException $e) {
                 }
                 try {
                     $defaultShipping = $this->customerAccountManagement->getDefaultShippingAddress($customerId);
                 } catch (NoSuchEntityException $e) {
                 }
                 if ($basedOn == 'billing' && isset($defaultBilling) && $defaultBilling->getCountryId()) {
                     $billingAddress = $defaultBilling;
                 } elseif ($basedOn == 'shipping' && isset($defaultShipping) && $defaultShipping->getCountryId()) {
                     $shippingAddress = $defaultShipping;
                 } else {
                     $basedOn = 'default';
                 }
             } else {
                 $basedOn = 'default';
             }
         }
     }
     switch ($basedOn) {
         case 'billing':
             $address = $billingAddress;
             break;
         case 'shipping':
             $address = $shippingAddress;
             break;
         case 'origin':
             $address = $this->getRateOriginRequest($store);
             break;
         case 'default':
             $address->setCountryId($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store))->setRegionId($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store))->setPostcode($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store));
             break;
         default:
             break;
     }
     if ($customerTaxClass === null || $customerTaxClass === false) {
         if ($customerId) {
             $customerData = $this->customerRepository->getById($customerId);
             $customerTaxClass = $this->customerGroupRepository->getById($customerData->getGroupId())->getTaxClassId();
         } else {
             $customerTaxClass = $this->customerGroupManagement->getNotLoggedInGroup()->getTaxClassId();
         }
     }
     $request = new \Magento\Framework\Object();
     //TODO: Address is not completely refactored to use Data objects
     if ($address->getRegion() instanceof AddressRegion) {
         $regionId = $address->getRegion()->getRegionId();
     } else {
         $regionId = $address->getRegionId();
     }
     $request->setCountryId($address->getCountryId())->setRegionId($regionId)->setPostcode($address->getPostcode())->setStore($store)->setCustomerClassId($customerTaxClass);
     return $request;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:86,代码来源:Calculation.php

示例7: getDefaultShippingAddress

 /**
  * Returns default shipping address for current customer
  *
  * @return AddressInterface|null
  */
 public function getDefaultShippingAddress()
 {
     return $this->accountManagement->getDefaultShippingAddress($this->currentCustomer->getCustomerId());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:9,代码来源:CurrentCustomerAddress.php


注:本文中的Magento\Customer\Api\AccountManagementInterface::getDefaultShippingAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。