Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
GroupManagement Class Reference
Inheritance diagram for GroupManagement:
GroupManagementInterface

Public Member Functions

 __construct (StoreManagerInterface $storeManager, ScopeConfigInterface $scopeConfig, GroupFactory $groupFactory, GroupRepositoryInterface $groupRepository, GroupInterfaceFactory $groupDataFactory, SearchCriteriaBuilder $searchCriteriaBuilder, FilterBuilder $filterBuilder)
 
 getDefaultGroup ($storeId=null)
 
 getNotLoggedInGroup ()
 
 getLoggedInGroups ()
 
 getAllCustomersGroup ()
 
- Public Member Functions inherited from GroupManagementInterface
 isReadonly ($id)
 

Data Fields

const XML_PATH_DEFAULT_ID = 'customer/create_account/default_group'
 
const NOT_LOGGED_IN_ID = 0
 
const CUST_GROUP_ALL = 32000
 
const GROUP_CODE_MAX_LENGTH = 32
 

Protected Attributes

 $storeManager
 
 $scopeConfig
 
 $groupFactory
 
 $groupRepository
 
 $groupDataFactory
 
 $searchCriteriaBuilder
 
 $filterBuilder
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 23 of file GroupManagement.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( StoreManagerInterface  $storeManager,
ScopeConfigInterface  $scopeConfig,
GroupFactory  $groupFactory,
GroupRepositoryInterface  $groupRepository,
GroupInterfaceFactory  $groupDataFactory,
SearchCriteriaBuilder  $searchCriteriaBuilder,
FilterBuilder  $filterBuilder 
)
Parameters
StoreManagerInterface$storeManager
ScopeConfigInterface$scopeConfig
GroupFactory$groupFactory
GroupRepositoryInterface$groupRepository
GroupInterfaceFactory$groupDataFactory
SearchCriteriaBuilder$searchCriteriaBuilder
FilterBuilder$filterBuilder

Definition at line 77 of file GroupManagement.php.

85  {
86  $this->storeManager = $storeManager;
87  $this->scopeConfig = $scopeConfig;
88  $this->groupFactory = $groupFactory;
89  $this->groupRepository = $groupRepository;
90  $this->groupDataFactory = $groupDataFactory;
91  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
92  $this->filterBuilder = $filterBuilder;
93  }

Member Function Documentation

◆ getAllCustomersGroup()

getAllCustomersGroup ( )

{Get customer group representing all customers.

Returns
\Magento\Customer\Api\Data\GroupInterface
Exceptions
}

Implements GroupManagementInterface.

Definition at line 168 of file GroupManagement.php.

169  {
170  $groupDataObject = $this->groupDataFactory->create();
171  $groupDataObject->setId(self::CUST_GROUP_ALL);
172  return $groupDataObject;
173  }
$groupDataObject

◆ getDefaultGroup()

getDefaultGroup (   $storeId = null)

{Get default customer group.

Parameters
int$storeId
Returns
\Magento\Customer\Api\Data\GroupInterface
Exceptions
}

Implements GroupManagementInterface.

Definition at line 112 of file GroupManagement.php.

113  {
114  if ($storeId === null) {
115  $storeId = $this->storeManager->getStore()->getCode();
116  }
117  try {
118  $groupId = $this->scopeConfig->getValue(
119  self::XML_PATH_DEFAULT_ID,
120  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
121  $storeId
122  );
123  } catch (\Magento\Framework\Exception\State\InitException $e) {
125  } catch (NoSuchEntityException $e) {
127  }
128  try {
129  return $this->groupRepository->getById($groupId);
130  } catch (NoSuchEntityException $e) {
131  throw NoSuchEntityException::doubleField('groupId', $groupId, 'storeId', $storeId);
132  }
133  }
static doubleField($fieldName, $fieldValue, $secondFieldName, $secondFieldValue)

◆ getLoggedInGroups()

getLoggedInGroups ( )

{Get all customer groups except group representing customers not logged in.

Returns
\Magento\Customer\Api\Data\GroupInterface[]
Exceptions
}

Implements GroupManagementInterface.

Definition at line 146 of file GroupManagement.php.

147  {
148  $notLoggedInFilter[] = $this->filterBuilder
149  ->setField(GroupInterface::ID)
150  ->setConditionType('neq')
151  ->setValue(self::NOT_LOGGED_IN_ID)
152  ->create();
153  $groupAll[] = $this->filterBuilder
154  ->setField(GroupInterface::ID)
155  ->setConditionType('neq')
156  ->setValue(self::CUST_GROUP_ALL)
157  ->create();
158  $searchCriteria = $this->searchCriteriaBuilder
159  ->addFilters($notLoggedInFilter)
160  ->addFilters($groupAll)
161  ->create();
162  return $this->groupRepository->getList($searchCriteria)->getItems();
163  }
$searchCriteria

◆ getNotLoggedInGroup()

getNotLoggedInGroup ( )

{Get customer group representing customers not logged in.

Returns
\Magento\Customer\Api\Data\GroupInterface
Exceptions
}

Implements GroupManagementInterface.

Definition at line 138 of file GroupManagement.php.

139  {
140  return $this->groupRepository->getById(self::NOT_LOGGED_IN_ID);
141  }

Field Documentation

◆ $filterBuilder

$filterBuilder
protected

Definition at line 66 of file GroupManagement.php.

◆ $groupDataFactory

$groupDataFactory
protected

Definition at line 56 of file GroupManagement.php.

◆ $groupFactory

$groupFactory
protected

Definition at line 46 of file GroupManagement.php.

◆ $groupRepository

$groupRepository
protected

Definition at line 51 of file GroupManagement.php.

◆ $scopeConfig

$scopeConfig
protected

Definition at line 41 of file GroupManagement.php.

◆ $searchCriteriaBuilder

$searchCriteriaBuilder
protected

Definition at line 61 of file GroupManagement.php.

◆ $storeManager

$storeManager
protected

Definition at line 36 of file GroupManagement.php.

◆ CUST_GROUP_ALL

const CUST_GROUP_ALL = 32000

Definition at line 29 of file GroupManagement.php.

◆ GROUP_CODE_MAX_LENGTH

const GROUP_CODE_MAX_LENGTH = 32

Definition at line 31 of file GroupManagement.php.

◆ NOT_LOGGED_IN_ID

const NOT_LOGGED_IN_ID = 0

Definition at line 27 of file GroupManagement.php.

◆ XML_PATH_DEFAULT_ID

const XML_PATH_DEFAULT_ID = 'customer/create_account/default_group'

Definition at line 25 of file GroupManagement.php.


The documentation for this class was generated from the following file: