public function toOptionArray()
 {
     if (!$this->_options) {
         $this->_options = $this->groupFactory->create()->getCollection()->loadData()->toOptionArray();
     }
     return $this->_options;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function isReadonly($groupId)
 {
     /** @var \Magento\Customer\Model\Group $group */
     $group = $this->groupFactory->create();
     $group->load($groupId);
     if ($group->getId() === null) {
         throw NoSuchEntityException::singleField('groupId', $groupId);
     }
     return $groupId == self::NOT_LOGGED_IN_ID || $group->usesAsDefault();
 }
Пример #3
0
 /**
  * Get instance of the Group Model identified by an id
  *
  * @param int $groupId
  * @return Group
  * @throws NoSuchEntityException
  */
 public function retrieve($groupId)
 {
     if (isset($this->registry[$groupId])) {
         return $this->registry[$groupId];
     }
     $group = $this->groupFactory->create();
     $group->load($groupId);
     if ($group->getId() === null || $group->getId() != $groupId) {
         throw NoSuchEntityException::singleField(GroupInterface::ID, $groupId);
     }
     $this->registry[$groupId] = $group;
     return $group;
 }
Пример #4
0
 /**
  * Get instance of the Group Model identified by an id
  *
  * @param int $groupId
  * @return Group
  * @throws NoSuchEntityException
  */
 public function retrieve($groupId)
 {
     if (isset($this->registry[$groupId])) {
         return $this->registry[$groupId];
     }
     $group = $this->groupFactory->create();
     $group->load($groupId);
     if (is_null($group->getId())) {
         throw NoSuchEntityException::singleField('groupId', $groupId);
     }
     $this->registry[$groupId] = $group;
     return $group;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     /** @var \Magento\Customer\Model\Resource\Group\Collection $collection */
     $collection = $this->groupFactory->create()->getCollection();
     $collection->addTaxClass();
     //Add filters from root filter group to the collection
     /** @var FilterGroup $group */
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     /** @var \Magento\Framework\Api\SortOrder $sortOrder */
     if ($sortOrders) {
         foreach ($searchCriteria->getSortOrders() as $sortOrder) {
             $field = $this->translateField($sortOrder->getField());
             $collection->addOrder($field, $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     /** @var \Magento\Customer\Api\Data\GroupInterface[] $groups */
     $groups = [];
     /** @var \Magento\Customer\Model\Group $group */
     foreach ($collection as $group) {
         $groupDataObject = $this->groupDataFactory->create()->setId($group->getId())->setCode($group->getCode())->setTaxClassId($group->getTaxClassId())->setTaxClassName($group->getTaxClassName());
         $groups[] = $groupDataObject;
     }
     return $searchResults->setItems($groups);
 }
Пример #6
0
 public function getCustomerGroupDetails($request)
 {
     $code = $this->getCustomerGroupId($request->getAllItems());
     $group = $this->groupFactory->create()->load($code);
     $custGroupDetails = $this->customerDetailsFactory->create(['customerGroup' => $group->getCustomerGroupCode()]);
     return $custGroupDetails;
 }
Пример #7
0
 /**
  * @return array
  */
 public function getGroupIds()
 {
     $groupsIds = [];
     $collection = $this->groupFactory->create()->getCollection();
     foreach ($collection as $group) {
         $groupsIds[] = $group->getId();
     }
     return $groupsIds;
 }
 public function _getCustomerGroup()
 {
     $groupId = $this->customer->getGroupId();
     $groupModel = $this->groupFactory->create()->load($groupId);
     if ($groupModel) {
         return $groupModel->getCode();
     }
     return '';
 }
 /**
  * {@inheritdoc}
  */
 public function deleteGroup($groupId)
 {
     if (!$this->canDelete($groupId)) {
         throw new StateException('Cannot delete group.');
     }
     // Get group so we can throw an exception if it doesn't exist
     $this->getGroup($groupId);
     $customerGroup = $this->_groupFactory->create();
     $customerGroup->setId($groupId);
     $customerGroup->delete();
     $this->_groupRegistry->remove($groupId);
     return true;
 }
Пример #10
0
 /**
  * {@inheritdoc}
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     /** @var \Magento\Customer\Model\Resource\Group\Collection $collection */
     $collection = $this->groupFactory->create()->getCollection();
     $groupInterfaceName = 'Magento\\Customer\\Api\\Data\\GroupInterface';
     $this->extensionAttributesJoinProcessor->process($collection, $groupInterfaceName);
     $collection->addTaxClass();
     //Add filters from root filter group to the collection
     /** @var FilterGroup $group */
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $sortOrders = $searchCriteria->getSortOrders();
     /** @var \Magento\Framework\Api\SortOrder $sortOrder */
     if ($sortOrders) {
         foreach ($searchCriteria->getSortOrders() as $sortOrder) {
             $field = $this->translateField($sortOrder->getField());
             $collection->addOrder($field, $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
         }
     } else {
         // set a default sorting order since this method is used constantly in many
         // different blocks
         $field = $this->translateField('id');
         $collection->addOrder($field, 'ASC');
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     /** @var \Magento\Customer\Api\Data\GroupInterface[] $groups */
     $groups = [];
     /** @var \Magento\Customer\Model\Group $group */
     foreach ($collection as $group) {
         /** @var \Magento\Customer\Api\Data\GroupInterface $groupDataObject */
         $groupDataObject = $this->groupDataFactory->create()->setId($group->getId())->setCode($group->getCode())->setTaxClassId($group->getTaxClassId())->setTaxClassName($group->getTaxClassName());
         $data = $group->getData();
         $data = $this->extensionAttributesJoinProcessor->extractExtensionAttributes($groupInterfaceName, $data);
         if (isset($data[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]) && $data[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY] instanceof GroupExtensionInterface) {
             $groupDataObject->setExtensionAttributes($data[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
         }
         $groups[] = $groupDataObject;
     }
     $searchResults->setTotalCount($collection->getSize());
     return $searchResults->setItems($groups);
 }
Пример #11
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetListWithoutSortOrder()
 {
     $groupId = 86;
     $groupExtension = $this->getMock('Magento\\Customer\\Api\\Data\\GroupExtensionInterface', [], [], '', false);
     $filterGroup = $this->getMock('Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
     $filter = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
     $collection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Group\\Collection', [], [], '', false);
     $searchCriteria = $this->getMockForAbstractClass('Magento\\Framework\\Api\\SearchCriteriaInterface', [], '', false);
     $searchResults = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressSearchResultsInterface', [], '', false);
     $this->searchResultsFactory->expects($this->once())->method('create')->willReturn($searchResults);
     $searchResults->expects($this->once())->method('setSearchCriteria')->with($searchCriteria);
     $this->groupFactory->expects($this->once())->method('create')->willReturn($this->groupModel);
     $this->groupModel->expects($this->once())->method('getCollection')->willReturn($collection);
     $this->extensionAttributesJoinProcessor->expects($this->once())->method('process')->with($collection, 'Magento\\Customer\\Api\\Data\\GroupInterface');
     $collection->expects($this->once())->method('addTaxClass');
     $searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
     $filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
     $filter->expects($this->once())->method('getConditionType')->willReturn(false);
     $filter->expects($this->once())->method('getField')->willReturn('Field');
     $filter->expects($this->atLeastOnce())->method('getValue')->willReturn('Value');
     $collection->expects($this->once())->method('addFieldToFilter')->with(['Field'], [['eq' => 'Value']]);
     $searchCriteria->expects($this->once())->method('getCurrentPage')->willReturn(1);
     $collection->expects($this->once())->method('setCurPage')->with(1);
     $searchCriteria->expects($this->once())->method('getPageSize')->willReturn(10);
     $collection->expects($this->once())->method('setPageSize')->with(10);
     $collection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$this->groupModel]));
     $this->groupDataFactory->expects($this->once())->method('create')->willReturn($this->group);
     $this->group->expects($this->once())->method('setId')->with($groupId)->willReturnSelf();
     $this->group->expects($this->once())->method('setCode')->with('Code')->willReturnSelf();
     $this->group->expects($this->once())->method('setTaxClassId')->with(234)->willReturnSelf();
     $this->group->expects($this->once())->method('setTaxClassName')->with('Tax class name')->willReturnSelf();
     $this->groupModel->expects($this->atLeastOnce())->method('getId')->willReturn($groupId);
     $this->groupModel->expects($this->atLeastOnce())->method('getCode')->willReturn('Code');
     $this->groupModel->expects($this->atLeastOnce())->method('getTaxClassId')->willReturn(234);
     $this->groupModel->expects($this->atLeastOnce())->method('getTaxClassName')->willReturn('Tax class name');
     $this->groupModel->expects($this->once())->method('getData')->willReturn([]);
     $this->extensionAttributesJoinProcessor->expects($this->once())->method('extractExtensionAttributes')->with('Magento\\Customer\\Api\\Data\\GroupInterface', [])->willReturn(['extension_attributes' => $groupExtension]);
     $this->group->expects($this->once())->method('setExtensionAttributes')->with($groupExtension);
     $collection->expects($this->once())->method('getSize')->willReturn(9);
     $searchResults->expects($this->once())->method('setTotalCount')->with(9);
     $searchResults->expects($this->once())->method('setItems')->with([$this->group])->willReturnSelf();
     $collection->expects($this->once())->method('addOrder')->with('customer_group_id', 'ASC');
     $this->assertSame($searchResults, $this->model->getList($searchCriteria));
 }