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


PHP GroupRepositoryInterface::getById方法代碼示例

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


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

示例1: execute

 /**
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute(Observer $observer)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && $this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
         /** @var \Magento\Customer\Model\Data\Customer $customer */
         $customer = $observer->getData('customer');
         $customerGroupId = $customer->getGroupId();
         $customerGroup = $this->groupRepository->getById($customerGroupId);
         $customerTaxClassId = $customerGroup->getTaxClassId();
         $this->customerSession->setCustomerTaxClassId($customerTaxClassId);
         /** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
         $addresses = $customer->getAddresses();
         if (isset($addresses)) {
             $defaultShippingFound = false;
             $defaultBillingFound = false;
             foreach ($addresses as $address) {
                 if ($address->isDefaultBilling()) {
                     $defaultBillingFound = true;
                     $this->customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
                 }
                 if ($address->isDefaultShipping()) {
                     $defaultShippingFound = true;
                     $this->customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
                 }
                 if ($defaultShippingFound && $defaultBillingFound) {
                     break;
                 }
             }
         }
     }
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:35,代碼來源:CustomerLoggedInObserver.php

示例2: prepareDataSource

 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return void
  */
 public function prepareDataSource(array &$dataSource)
 {
     if (isset($dataSource['data']['items'])) {
         foreach ($dataSource['data']['items'] as &$item) {
             $item[$this->getData('name')] = $this->groupRepository->getById($item[$this->getData('name')])->getCode();
         }
     }
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:14,代碼來源:CustomerGroup.php

示例3: loadSource

 /**
  * @return \Magento\Customer\Api\Data\GroupInterface
  */
 protected function loadSource()
 {
     if ($this->isBackendOrder()) {
         // For backend orders
         $customerGroupId = $this->objectManager->get('Magento\\Backend\\Model\\Session\\Quote')->getQuote()->getCustomerGroupId();
     } else {
         $customerGroupId = $this->objectManager->get('Magento\\Customer\\Model\\Session')->getCustomerGroupId();
     }
     return $this->groupRepository->getById($customerGroupId);
 }
開發者ID:owebia,項目名稱:module-shipping-core,代碼行數:13,代碼來源:CustomerGroup.php

示例4: setCustomerGroupValue

 /**
  * Update customer group value
  * Method set group code instead id value
  * @return void
  */
 private function setCustomerGroupValue()
 {
     $value = $this->getData(self::$customerGroupAttributeCode);
     try {
         $group = $this->groupRepository->getById($value);
         $this->setCustomAttribute(self::$customerGroupAttributeCode, $group->getCode());
     } catch (NoSuchEntityException $e) {
         $this->setCustomAttribute(self::$customerGroupAttributeCode, 'N/A');
     }
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:15,代碼來源:Document.php

示例5: getHeaderText

 /**
  * Retrieve the header text, either editing an existing group or creating a new one.
  *
  * @return \Magento\Framework\Phrase
  */
 public function getHeaderText()
 {
     $groupId = $this->coreRegistry->registry(RegistryConstants::CURRENT_GROUP_ID);
     if ($groupId === null) {
         return __('New Customer Group');
     } else {
         $group = $this->groupRepository->getById($groupId);
         return __('Edit Customer Group "%1"', $this->escapeHtml($group->getCode()));
     }
 }
開發者ID:tingyeeh,項目名稱:magento2,代碼行數:15,代碼來源:Edit.php

示例6: testGetDefaultRateRequest

 public function testGetDefaultRateRequest()
 {
     $customerDataSet = $this->customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
     $address = $this->addressRepository->getById(self::FIXTURE_ADDRESS_ID);
     $rateRequest = $this->_model->getRateRequest(null, null, null, null, $customerDataSet->getId());
     $this->assertNotNull($rateRequest);
     $this->assertEquals($address->getCountryId(), $rateRequest->getCountryId());
     $this->assertEquals($address->getRegion()->getRegionId(), $rateRequest->getRegionId());
     $this->assertEquals($address->getPostcode(), $rateRequest->getPostcode());
     $customerTaxClassId = $this->groupRepository->getById($customerDataSet->getGroupId())->getTaxClassId();
     $this->assertEquals($customerTaxClassId, $rateRequest->getCustomerClassId());
 }
開發者ID:andrewhowdencom,項目名稱:m2onk8s,代碼行數:12,代碼來源:CalculationTest.php

示例7: prepareDataSource

 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return array
  */
 public function prepareDataSource(array $dataSource)
 {
     if (isset($dataSource['data']['items'])) {
         foreach ($dataSource['data']['items'] as &$item) {
             try {
                 $item[$this->getData('name')] = $this->groupRepository->getById($item[$this->getData('name')])->getCode();
             } catch (NoSuchEntityException $exception) {
                 $item[$this->getData('name')] = __('Group was removed');
             } catch (\Exception $exception) {
                 $item[$this->getData('name')] = '';
             }
         }
     }
     return $dataSource;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:21,代碼來源:CustomerGroup.php

示例8: testDelete

 /**
  * @magentoDbIsolation enabled
  */
 public function testDelete()
 {
     $group = $this->groupFactory->create()->setId(null)->setCode('New Group')->setTaxClassId(3);
     $groupId = $this->groupRepository->save($group)->getId();
     $newGroup = $this->groupRepository->getById($groupId);
     $this->assertTrue($this->groupRepository->delete($newGroup));
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:10,代碼來源:GroupRepositoryTest.php

示例9: _getCustomerGroupById

 /**
  * Get Customer Group By Id
  *
  * @param int $customerGroupId
  * @param null $allGroups
  * @return string
  */
 protected function _getCustomerGroupById($customerGroupId, $allGroups = null)
 {
     if ($allGroups) {
         return ImportAdvancedPricing::VALUE_ALL_GROUPS;
     } else {
         return $this->_groupRepository->getById($customerGroupId)->getCode();
     }
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:15,代碼來源:AdvancedPricing.php

示例10: getGroup

 /**
  * Retrieve customer group by id
  *
  * @param int $groupId
  * @return \Magento\Customer\Api\Data\GroupInterface|null
  */
 private function getGroup($groupId)
 {
     try {
         $group = $this->groupRepository->getById($groupId);
     } catch (NoSuchEntityException $e) {
         $group = null;
     }
     return $group;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:15,代碼來源:PersonalInfo.php

示例11: testSaveActionNewGroupWithoutGroupCode

 /**
  * @magentoDataFixture Magento/Customer/_files/customer_group.php
  */
 public function testSaveActionNewGroupWithoutGroupCode()
 {
     $groupId = $this->findGroupIdWithCode(self::CUSTOMER_GROUP_CODE);
     $originalCode = $this->groupRepository->getById($groupId)->getCode();
     $this->getRequest()->setParam('tax_class', self::TAX_CLASS_ID);
     $this->dispatch('backend/customer/group/save');
     $this->assertSessionMessages($this->equalTo(['code is a required field.']), MessageInterface::TYPE_ERROR);
     $this->assertSessionMessages($this->isEmpty(), MessageInterface::TYPE_SUCCESS);
     $this->assertEquals($originalCode, $this->groupRepository->getById($groupId)->getCode());
     $this->assertRedirect($this->stringStartsWith(self::BASE_CONTROLLER_URL . 'edit/'));
     $this->assertEquals('', $this->session->getCustomerGroupData()['customer_group_code']);
     $this->assertEquals(self::TAX_CLASS_ID, $this->session->getCustomerGroupData()['tax_class_id']);
 }
開發者ID:andrewhowdencom,項目名稱:m2onk8s,代碼行數:16,代碼來源:GroupTest.php

示例12: _prepareLayout

 /**
  * Prepare form for render
  *
  * @return void
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $groupId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_GROUP_ID);
     /** @var \Magento\Customer\Api\Data\GroupInterface $customerGroup */
     if ($groupId === null) {
         $customerGroup = $this->groupDataFactory->create();
         $defaultCustomerTaxClass = $this->_taxHelper->getDefaultCustomerTaxClass();
     } else {
         $customerGroup = $this->_groupRepository->getById($groupId);
         $defaultCustomerTaxClass = $customerGroup->getTaxClassId();
     }
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Group Information')]);
     $validateClass = sprintf('required-entry validate-length maximum-length-%d', \Magento\Customer\Model\GroupManagement::GROUP_CODE_MAX_LENGTH);
     $name = $fieldset->addField('customer_group_code', 'text', ['name' => 'code', 'label' => __('Group Name'), 'title' => __('Group Name'), 'note' => __('Maximum length must be less then %1 symbols', \Magento\Customer\Model\GroupManagement::GROUP_CODE_MAX_LENGTH), 'class' => $validateClass, 'required' => true]);
     if ($customerGroup->getId() == 0 && $customerGroup->getCode()) {
         $name->setDisabled(true);
     }
     $fieldset->addField('tax_class_id', 'select', ['name' => 'tax_class', 'label' => __('Tax Class'), 'title' => __('Tax Class'), 'class' => 'required-entry', 'required' => true, 'values' => $this->_taxCustomer->toOptionArray()]);
     if ($customerGroup->getId() !== null) {
         // If edit add id
         $form->addField('id', 'hidden', ['name' => 'id', 'value' => $customerGroup->getId()]);
     }
     if ($this->_backendSession->getCustomerGroupData()) {
         $form->addValues($this->_backendSession->getCustomerGroupData());
         $this->_backendSession->setCustomerGroupData(null);
     } else {
         // TODO: need to figure out how the DATA can work with forms
         $form->addValues(['id' => $customerGroup->getId(), 'customer_group_code' => $customerGroup->getCode(), 'tax_class_id' => $defaultCustomerTaxClass]);
     }
     $form->setUseContainer(true);
     $form->setId('edit_form');
     $form->setAction($this->getUrl('customer/*/save'));
     $form->setMethod('post');
     $this->setForm($form);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:43,代碼來源:Form.php

示例13: getAvataxTaxCodeForCustomer

 /**
  * Get AvaTax Customer Usage Type for customer
  *
  * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  * @return null|string
  */
 public function getAvataxTaxCodeForCustomer(\Magento\Customer\Api\Data\CustomerInterface $customer)
 {
     $customerGroupId = $customer->getGroupId();
     if (!$customerGroupId) {
         return null;
     }
     try {
         $customerGroup = $this->customerGroupRepository->getById($customerGroupId);
         $taxClassId = $customerGroup->getTaxClassId();
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return null;
     }
     return $this->getAvaTaxTaxCode($taxClassId);
 }
開發者ID:classyllama,項目名稱:ClassyLlama_AvaTax,代碼行數:20,代碼來源:TaxClass.php

示例14: getCustomerGroupName

 /**
  * Return name of the customer group.
  *
  * @return string
  */
 public function getCustomerGroupName()
 {
     if ($this->getOrder()) {
         $customerGroupId = $this->getOrder()->getCustomerGroupId();
         try {
             if ($customerGroupId !== null) {
                 return $this->groupRepository->getById($customerGroupId)->getCode();
             }
         } catch (NoSuchEntityException $e) {
             return '';
         }
     }
     return '';
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:19,代碼來源:Info.php

示例15: add

 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function add($sku, $customerGroupId, $price)
 {
     if (!\Zend_Validate::is($price, 'Float') || $price <= 0 || !\Zend_Validate::is($price, 'Float')) {
         throw new InputException(__('Please provide valid data'));
     }
     $customerGroup = $this->groupRepository->getById($customerGroupId);
     $product = $this->productRepository->get($sku, true);
     $groupPrices = $product->getData('group_price');
     $websiteIdentifier = 0;
     $value = $this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE);
     if ($value != 0) {
         $websiteIdentifier = $this->storeManager->getWebsite()->getId();
     }
     $found = false;
     foreach ($groupPrices as &$currentPrice) {
         if (intval($currentPrice['cust_group']) === $customerGroupId && intval($currentPrice['website_id']) === intval($websiteIdentifier)) {
             $currentPrice['price'] = $price;
             $found = true;
             break;
         }
     }
     if (!$found) {
         $groupPrices[] = ['cust_group' => $customerGroup->getId(), 'website_id' => $websiteIdentifier, 'price' => $price];
     }
     $product->setData('group_price', $groupPrices);
     $errors = $product->validate();
     if (is_array($errors) && count($errors)) {
         $errorAttributeCodes = implode(', ', array_keys($errors));
         throw new InputException(__('Values of following attributes are invalid: %1', $errorAttributeCodes));
     }
     try {
         $this->productRepository->save($product);
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not save group price'));
     }
     return true;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:42,代碼來源:GroupPriceManagement.php


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