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


PHP GroupManagementInterface::getDefaultGroup方法代码示例

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


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

示例2: execute

 /**
  * Handle customer VAT number if needed on collect_totals_before event of quote address
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment */
     $shippingAssignment = $observer->getShippingAssignment();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $observer->getQuote();
     /** @var \Magento\Quote\Model\Quote\Address $address */
     $address = $shippingAssignment->getShipping()->getAddress();
     $customer = $quote->getCustomer();
     $storeId = $customer->getStoreId();
     if ($customer->getDisableAutoGroupChange() || false == $this->vatValidator->isEnabled($address, $storeId)) {
         return;
     }
     $customerCountryCode = $address->getCountryId();
     $customerVatNumber = $address->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($address, $storeId), $storeId);
     }
     if ($groupId) {
         $address->setPrevQuoteCustomerGroupId($quote->getCustomerGroupId());
         $quote->setCustomerGroupId($groupId);
         $customer->setGroupId($groupId);
         $quote->setCustomer($customer);
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:35,代码来源:CollectTotalsObserver.php

示例3: testDeleteButtonNotExistInDefaultGroup

 /**
  * Verify that the Delete button does not exist for the default group.
  * @magentoAppIsolation enabled
  */
 public function testDeleteButtonNotExistInDefaultGroup()
 {
     $groupId = $this->groupManagement->getDefaultGroup(0)->getId();
     $this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $groupId);
     $this->getRequest()->setParam('id', $groupId);
     /** @var $block Edit */
     $block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Group\\Edit', 'block');
     $buttonsHtml = $block->getButtonsHtml();
     $this->assertNotContains('delete', $buttonsHtml);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:EditTest.php

示例4: _afterDelete

 /**
  * Method set default group id to the customers collection
  *
  * @param \Magento\Framework\Model\AbstractModel $group
  * @return $this
  */
 protected function _afterDelete(\Magento\Framework\Model\AbstractModel $group)
 {
     $customerCollection = $this->_createCustomersCollection()->addAttributeToFilter('group_id', $group->getId())->load();
     foreach ($customerCollection as $customer) {
         /** @var $customer \Magento\Customer\Model\Customer */
         $customer->load($customer->getId());
         $defaultGroupId = $this->_groupManagement->getDefaultGroup($customer->getStoreId())->getId();
         $customer->setGroupId($defaultGroupId);
         $customer->save();
     }
     return parent::_afterDelete($group);
 }
开发者ID:shazal,项目名称:magento2,代码行数:18,代码来源:Group.php

示例5: convertAttribute

 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Product $product
  * @param Entry $entry
  * @return Entry
  */
 public function convertAttribute($product, $entry)
 {
     $product->setWebsiteId($this->_storeManager->getStore($product->getStoreId())->getWebsiteId());
     $defaultCustomerGroup = $this->groupManagement->getDefaultGroup($product->getStoreId());
     $product->setCustomerGroupId($defaultCustomerGroup->getId());
     /** @var \Magento\Store\Model\Store $store */
     $store = $this->_storeManager->getStore($product->getStoreId());
     $isSalePriceAllowed = $this->_config->getTargetCountry($product->getStoreId()) == 'US';
     // get tax settings
     $priceDisplayType = $this->_taxData->getPriceDisplayType($product->getStoreId());
     $inclTax = $priceDisplayType == Config::DISPLAY_TYPE_INCLUDING_TAX;
     $finalPrice = $this->_getFinalPrice($product, $store, $inclTax, $isSalePriceAllowed);
     // calculate price attribute value
     $price = $this->_getPrice($product, $store, $priceDisplayType, $inclTax, $isSalePriceAllowed);
     if ($isSalePriceAllowed) {
         // set sale_price and effective dates for it
         if ($price && $price - $finalPrice > 0.0001) {
             $this->_setAttributePrice($entry, $product, $price);
             $this->_setAttributePrice($entry, $product, $finalPrice, 'sale_price');
             $this->_setEffectiveDate($product, $entry);
         } else {
             $this->_setAttributePrice($entry, $product, $finalPrice);
             $entry->removeContentAttribute('sale_price_effective_date');
             $entry->removeContentAttribute('sale_price');
         }
         // calculate taxes
         $tax = $this->getGroupAttributeTax();
         if (!$inclTax && !is_null($tax)) {
             $tax->convertAttribute($product, $entry);
         }
     } else {
         $this->_setAttributePrice($entry, $product, $price);
     }
     return $entry;
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:42,代码来源:Price.php

示例6: extract

 /**
  * @param string $formCode
  * @param RequestInterface $request
  * @return \Magento\Customer\Api\Data\CustomerInterface
  */
 public function extract($formCode, RequestInterface $request)
 {
     $customerForm = $this->formFactory->create('customer', $formCode);
     $customerData = $customerForm->extractData($request);
     $allowedAttributes = $customerForm->getAllowedAttributes();
     $isGroupIdEmpty = isset($allowedAttributes['group_id']);
     $customerDataObject = $this->customerFactory->create();
     $this->dataObjectHelper->populateWithArray($customerDataObject, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $store = $this->storeManager->getStore();
     if ($isGroupIdEmpty) {
         $customerDataObject->setGroupId($this->customerGroupManagement->getDefaultGroup($store->getId())->getId());
     }
     $customerDataObject->setWebsiteId($store->getWebsiteId());
     $customerDataObject->setStoreId($store->getId());
     return $customerDataObject;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:21,代码来源:CustomerExtractor.php

示例7: afterAddressSave

 /**
  * Address after save event handler
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function afterAddressSave($observer)
 {
     /** @var $customerAddress Address */
     $customerAddress = $observer->getCustomerAddress();
     $customer = $customerAddress->getCustomer();
     if (!$this->_customerAddress->isVatValidationEnabled($customer->getStore()) || $this->_coreRegistry->registry(self::VIV_PROCESSED_FLAG) || !$this->_canProcessAddress($customerAddress)) {
         return;
     }
     try {
         $this->_coreRegistry->register(self::VIV_PROCESSED_FLAG, true);
         if ($customerAddress->getVatId() == '' || !$this->_customerVat->isCountryInEU($customerAddress->getCountry())) {
             $defaultGroupId = $this->_groupManagement->getDefaultGroup($customer->getStore())->getId();
             if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $defaultGroupId) {
                 $customer->setGroupId($defaultGroupId);
                 $customer->save();
             }
         } else {
             $result = $this->_customerVat->checkVatNumber($customerAddress->getCountryId(), $customerAddress->getVatId());
             $newGroupId = $this->_customerVat->getCustomerGroupIdBasedOnVatNumber($customerAddress->getCountryId(), $result, $customer->getStore());
             if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $newGroupId) {
                 $customer->setGroupId($newGroupId);
                 $customer->save();
             }
             $customerAddress->setVatValidationResult($result);
         }
     } catch (\Exception $e) {
         $this->_coreRegistry->register(self::VIV_PROCESSED_FLAG, false, true);
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:36,代码来源:Observer.php

示例8: getQuote

 /**
  * Retrieve quote model object
  *
  * @return \Magento\Quote\Model\Quote
  */
 public function getQuote()
 {
     if ($this->_quote === null) {
         $this->_quote = $this->quoteFactory->create();
         if ($this->getStoreId()) {
             if (!$this->getQuoteId()) {
                 $this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId());
                 $this->_quote->setIsActive(false);
                 $this->_quote->setStoreId($this->getStoreId());
                 $this->quoteRepository->save($this->_quote);
                 $this->setQuoteId($this->_quote->getId());
                 $this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
             } else {
                 $this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
                 $this->_quote->setStoreId($this->getStoreId());
             }
             if ($this->getCustomerId() && $this->getCustomerId() != $this->_quote->getCustomerId()) {
                 $customer = $this->customerRepository->getById($this->getCustomerId());
                 $this->_quote->assignCustomer($customer);
                 $this->quoteRepository->save($this->_quote);
             }
         }
         $this->_quote->setIgnoreOldQty(true);
         $this->_quote->setIsSuperMode(true);
     }
     return $this->_quote;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:32,代码来源:Quote.php

示例9: assertDefaultGroupMatches

 /**
  * @param $testGroup
  * @param $storeId
  */
 private function assertDefaultGroupMatches($testGroup, $storeId)
 {
     $group = $this->groupManagement->getDefaultGroup($storeId);
     $this->assertEquals($testGroup['id'], $group->getId());
     $this->assertEquals($testGroup['code'], $group->getCode());
     $this->assertEquals($testGroup['tax_class_id'], $group->getTaxClassId());
     $this->assertEquals($testGroup['tax_class_name'], $group->getTaxClassName());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:GroupManagementTest.php

示例10: testGetForm

 /**
  * Test retrieving a valid group form.
  */
 public function testGetForm()
 {
     $this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $this->groupManagement->getDefaultGroup(0)->getId());
     /** @var $block Form */
     $block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Group\\Edit\\Form', 'block');
     $form = $block->getForm();
     $this->assertEquals('edit_form', $form->getId());
     $this->assertEquals('post', $form->getMethod());
     $baseFieldSet = $form->getElement('base_fieldset');
     $this->assertNotNull($baseFieldSet);
     $groupCodeElement = $form->getElement('customer_group_code');
     $this->assertNotNull($groupCodeElement);
     $taxClassIdElement = $form->getElement('tax_class_id');
     $this->assertNotNull($taxClassIdElement);
     $idElement = $form->getElement('id');
     $this->assertNotNull($idElement);
     $this->assertEquals('1', $idElement->getValue());
     $this->assertEquals('3', $taxClassIdElement->getValue());
     /** @var \Magento\Tax\Model\TaxClass\Source\Customer $taxClassCustomer */
     $taxClassCustomer = Bootstrap::getObjectManager()->get('Magento\\Tax\\Model\\TaxClass\\Source\\Customer');
     $this->assertEquals($taxClassCustomer->toOptionArray(false), $taxClassIdElement->getData('values'));
     $this->assertEquals('General', $groupCodeElement->getValue());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:26,代码来源:FormTest.php

示例11: execute

 /**
  * Address after save event handler
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var $customerAddress Address */
     $customerAddress = $observer->getCustomerAddress();
     $customer = $customerAddress->getCustomer();
     if (!$this->_customerAddress->isVatValidationEnabled($customer->getStore()) || $this->_coreRegistry->registry(self::VIV_PROCESSED_FLAG) || !$this->_canProcessAddress($customerAddress)) {
         return;
     }
     try {
         $this->_coreRegistry->register(self::VIV_PROCESSED_FLAG, true);
         if ($customerAddress->getVatId() == '' || !$this->_customerVat->isCountryInEU($customerAddress->getCountry())) {
             $defaultGroupId = $this->_groupManagement->getDefaultGroup($customer->getStore())->getId();
             if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $defaultGroupId) {
                 $customer->setGroupId($defaultGroupId);
                 $customer->save();
                 $this->customerSession->setCustomerGroupId($defaultGroupId);
             }
         } else {
             $result = $this->_customerVat->checkVatNumber($customerAddress->getCountryId(), $customerAddress->getVatId());
             $newGroupId = $this->_customerVat->getCustomerGroupIdBasedOnVatNumber($customerAddress->getCountryId(), $result, $customer->getStore());
             if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $newGroupId) {
                 $customer->setGroupId($newGroupId);
                 $customer->save();
                 $this->customerSession->setCustomerGroupId($newGroupId);
             }
             $customerAddress->setVatValidationResult($result);
             if ($this->appState->getAreaCode() == Area::AREA_FRONTEND) {
                 if ($result->getIsValid()) {
                     $this->addValidMessage($customerAddress, $result);
                 } elseif ($result->getRequestSuccess()) {
                     $this->addInvalidMessage($customerAddress);
                 } else {
                     $this->addErrorMessage($customerAddress);
                 }
             }
         }
     } catch (\Exception $e) {
         $this->_coreRegistry->register(self::VIV_PROCESSED_FLAG, false, true);
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:47,代码来源:AfterAddressSaveObserver.php

示例12: getDefaultCustomerTaxClass

 /**
  * Fetch default customer tax class
  *
  * @param null|Store|string|int $store
  * @return int
  */
 public function getDefaultCustomerTaxClass($store = null)
 {
     if ($this->_defaultCustomerTaxClass === null) {
         //Not catching the exception here since default group is expected
         $defaultCustomerGroup = $this->customerGroupManagement->getDefaultGroup($store);
         $this->_defaultCustomerTaxClass = $defaultCustomerGroup->getTaxClassId();
     }
     return $this->_defaultCustomerTaxClass;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:Calculation.php


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