Beispiel #1
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);
 }
Beispiel #2
0
 /**
  * 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);
 }
Beispiel #3
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);
 }
 /**
  * {@inheritdoc}
  */
 public function getAllCustomersGroup()
 {
     $groupDataObject = $this->groupDataFactory->create();
     $groupDataObject->setId(self::CUST_GROUP_ALL);
     return $groupDataObject;
 }
 /**
  * @magentoDbIsolation enabled
  */
 public function testDeleteById()
 {
     $group = $this->groupFactory->create()->setId(null)->setCode('New Group')->setTaxClassId(3);
     $groupId = $this->groupRepository->save($group)->getId();
     $this->assertTrue($this->groupRepository->deleteById($groupId));
 }