Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Group Class Reference
Inheritance diagram for Group:
AbstractExtensibleModel IdentityInterface GroupInterface ScopeInterface AbstractModel CustomAttributesDataInterface ExtensibleDataInterface DataObject ExtensibleDataInterface

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Config\Model\ResourceModel\Config\Data $configDataResource, \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeListFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], \Magento\Framework\Event\ManagerInterface $eventManager=null)
 
 setStores ($stores)
 
 getStoreCollection ()
 
 getStores ()
 
 getStoreIds ()
 
 getStoreCodes ()
 
 getStoresCount ()
 
 getDefaultStore ()
 
 getDefaultStoreByLocale ($locale)
 
 getStoresByLocale ($locale)
 
 setWebsite (Website $website)
 
 getWebsite ()
 
 isCanDelete ()
 
 getDefaultStoreId ()
 
 setDefaultStoreId ($defaultStoreId)
 
 getRootCategoryId ()
 
 setRootCategoryId ($rootCategoryId)
 
 getWebsiteId ()
 
 setWebsiteId ($websiteId)
 
 beforeDelete ()
 
 afterDelete ()
 
 afterSave ()
 
 isReadOnly ($value=null)
 
 getIdentities ()
 
 getName ()
 
 setName ($name)
 
 getCode ()
 
 setCode ($code)
 
 getExtensionAttributes ()
 
 setExtensionAttributes (\Magento\Store\Api\Data\GroupExtensionInterface $extensionAttributes)
 
 getScopeType ()
 
 getScopeTypeName ()
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from GroupInterface
 getId ()
 
 setId ($id)
 
 setExtensionAttributes (\Magento\Store\Api\Data\GroupExtensionInterface $extensionAttributes)
 
- Public Member Functions inherited from ScopeInterface
 getId ()
 

Data Fields

const ENTITY = 'store_group'
 
const CACHE_TAG = 'store_group'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 
- Data Fields inherited from ScopeInterface
const SCOPE_DEFAULT = 'default'
 

Protected Member Functions

 _construct ()
 
 _loadStores ()
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_cacheTag = true
 
 $_eventPrefix = 'store_group'
 
 $_eventObject = 'store_group'
 
 $_stores
 
 $_storeIds = []
 
 $_storeCodes = []
 
 $_storesCount = 0
 
 $_defaultStore
 
 $_configDataResource
 
 $_storeListFactory
 
 $_storeManager
 
- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Class Group

@api @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 19 of file Group.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Api\ExtensionAttributesFactory  $extensionFactory,
\Magento\Framework\Api\AttributeValueFactory  $customAttributeFactory,
\Magento\Config\Model\ResourceModel\Config\Data  $configDataResource,
\Magento\Store\Model\ResourceModel\Store\CollectionFactory  $storeListFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [],
\Magento\Framework\Event\ManagerInterface  $eventManager = null 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Api\ExtensionAttributesFactory$extensionFactory
\Magento\Framework\Api\AttributeValueFactory$customAttributeFactory
\Magento\Config\Model\ResourceModel\Config\Data$configDataResource
\Magento\Store\Model\Store$store
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data
\Magento\Framework\Event\ManagerInterface | null$eventManager@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 117 of file Group.php.

129  {
130  $this->_configDataResource = $configDataResource;
131  $this->_storeListFactory = $storeListFactory;
132  $this->_storeManager = $storeManager;
133  $this->eventManager = $eventManager ?: \Magento\Framework\App\ObjectManager::getInstance()
134  ->get(\Magento\Framework\Event\ManagerInterface::class);
135  parent::__construct(
136  $context,
137  $registry,
138  $extensionFactory,
140  $resource,
141  $resourceCollection,
142  $data
143  );
144  }
$storeManager
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _construct()

_construct ( )
protected

Init model

Returns
void

Definition at line 151 of file Group.php.

152  {
153  $this->_init(\Magento\Store\Model\ResourceModel\Group::class);
154  }

◆ _loadStores()

_loadStores ( )
protected

Load store collection and set internal data

Returns
void

Definition at line 161 of file Group.php.

162  {
163  $this->_stores = [];
164  $this->_storesCount = 0;
165  foreach ($this->getStoreCollection() as $store) {
166  $this->_stores[$store->getId()] = $store;
167  $this->_storeIds[$store->getId()] = $store->getId();
168  $this->_storeCodes[$store->getId()] = $store->getCode();
169  if ($this->getDefaultStoreId() == $store->getId()) {
170  $this->_defaultStore = $store;
171  }
172  $this->_storesCount++;
173  }
174  }

◆ afterDelete()

afterDelete ( )
Since
100.1.0

Definition at line 415 of file Group.php.

416  {
417  $group = $this;
418  $this->getResource()->addCommitCallback(function () use ($group) {
419  $this->_storeManager->reinitStores();
420  $this->eventManager->dispatch($this->_eventPrefix . '_delete', ['group' => $group]);
421  });
422  $result = parent::afterDelete();
423 
424  if ($this->getId() === $this->getWebsite()->getDefaultGroupId()) {
425  $ids = $this->getWebsite()->getGroupIds();
426  if (!empty($ids) && count($ids) > 1) {
427  unset($ids[$this->getId()]);
428  $defaultId = current($ids);
429  } else {
430  $defaultId = null;
431  }
432  $this->getWebsite()->setDefaultGroupId($defaultId);
433  $this->getWebsite()->save();
434  }
435  return $result;
436  }
$group
Definition: sections.phtml:16

◆ afterSave()

afterSave ( )
Since
100.2.5

Definition at line 442 of file Group.php.

443  {
444  $group = $this;
445  $this->getResource()->addCommitCallback(function () use ($group) {
446  $this->_storeManager->reinitStores();
447  $this->eventManager->dispatch($this->_eventPrefix . '_save', ['group' => $group]);
448  });
449  return parent::afterSave();
450  }
$group
Definition: sections.phtml:16

◆ beforeDelete()

beforeDelete ( )
Returns
$this

Definition at line 402 of file Group.php.

403  {
404  $this->_configDataResource->clearScopeData(
406  $this->getStoreIds()
407  );
408  return parent::beforeDelete();
409  }

◆ getCode()

getCode ( )

Retrieve scope code

Returns
string

Since
100.1.0

Implements ScopeInterface.

Definition at line 496 of file Group.php.

497  {
498  return $this->getData('code');
499  }

◆ getDefaultStore()

getDefaultStore ( )

Retrieve default store model

Returns
\Magento\Store\Model\Store

Definition at line 262 of file Group.php.

263  {
264  if (!$this->hasDefaultStoreId()) {
265  return false;
266  }
267  if ($this->_stores === null) {
268  $this->_loadStores();
269  }
270  return $this->_defaultStore;
271  }

◆ getDefaultStoreByLocale()

getDefaultStoreByLocale (   $locale)

Get most suitable store by locale If no store with given locale is found - default store is returned If group has no stores - null is returned

Parameters
string$locale
Returns
\Magento\Store\Model\Store|null

Definition at line 281 of file Group.php.

282  {
283  if ($this->getDefaultStore() && $this->getDefaultStore()->getLocaleCode() == $locale) {
284  return $this->getDefaultStore();
285  } else {
286  $stores = $this->getStoresByLocale($locale);
287  if (count($stores)) {
288  return $stores[0];
289  } else {
290  return $this->getDefaultStore() ? $this->getDefaultStore() : null;
291  }
292  }
293  }
getStoresByLocale($locale)
Definition: Group.php:301

◆ getDefaultStoreId()

getDefaultStoreId ( )
Returns
mixed

Implements GroupInterface.

Definition at line 354 of file Group.php.

355  {
356  return $this->_getData('default_store_id');
357  }

◆ getExtensionAttributes()

getExtensionAttributes ( )

{Retrieve existing extension attributes object or create a new one.

Returns
\Magento\Store\Api\Data\GroupExtensionInterface|null
}

Implements GroupInterface.

Definition at line 513 of file Group.php.

◆ getIdentities()

getIdentities ( )

Get identities

Returns
array

Implements IdentityInterface.

Definition at line 471 of file Group.php.

472  {
473  return [self::CACHE_TAG];
474  }

◆ getName()

getName ( )

{Get scope name

Returns
string
Since
100.1.0
}

Implements ScopeInterface.

Definition at line 479 of file Group.php.

480  {
481  return $this->getData('name');
482  }

◆ getRootCategoryId()

getRootCategoryId ( )
Returns
mixed

Implements GroupInterface.

Definition at line 370 of file Group.php.

371  {
372  return $this->_getData('root_category_id');
373  }

◆ getScopeType()

getScopeType ( )

{Get scope type

Returns
string
Since
100.1.0
}

Since
100.1.0

Implements ScopeInterface.

Definition at line 531 of file Group.php.

◆ getScopeTypeName()

getScopeTypeName ( )

{Get scope type name

Returns
string
Since
100.1.0
}

Since
100.1.0

Implements ScopeInterface.

Definition at line 540 of file Group.php.

541  {
542  return 'Store';
543  }

◆ getStoreCodes()

getStoreCodes ( )

Retrieve website store codes

Returns
array

Definition at line 238 of file Group.php.

239  {
240  if ($this->_stores === null) {
241  $this->_loadStores();
242  }
243  return $this->_storeCodes;
244  }

◆ getStoreCollection()

getStoreCollection ( )

Retrieve new (not loaded) Store collection object with group filter

Returns
\Magento\Store\Model\ResourceModel\Store\Collection

Definition at line 202 of file Group.php.

203  {
204  return $this->_storeListFactory->create()->addGroupFilter($this->getId());
205  }

◆ getStoreIds()

getStoreIds ( )

Retrieve website store ids

Returns
int[]

Definition at line 225 of file Group.php.

226  {
227  if ($this->_stores === null) {
228  $this->_loadStores();
229  }
230  return $this->_storeIds;
231  }

◆ getStores()

getStores ( )

Retrieve website store objects

Returns
\Magento\Store\Model\ResourceModel\Store\Collection[]

Definition at line 212 of file Group.php.

213  {
214  if ($this->_stores === null) {
215  $this->_loadStores();
216  }
217  return $this->_stores;
218  }

◆ getStoresByLocale()

getStoresByLocale (   $locale)

Retrieve list of stores with given locale

Parameters
string$locale
Returns
\Magento\Store\Model\Store[]

Definition at line 301 of file Group.php.

302  {
303  $stores = [];
304  foreach ($this->getStores() as $store) {
305  /* @var $store \Magento\Store\Model\Store */
306  if ($store->getLocaleCode() == $locale) {
307  $stores[] = $store;
308  }
309  }
310  return $stores;
311  }

◆ getStoresCount()

getStoresCount ( )
Returns
int

Definition at line 249 of file Group.php.

250  {
251  if ($this->_stores === null) {
252  $this->_loadStores();
253  }
254  return $this->_storesCount;
255  }

◆ getWebsite()

getWebsite ( )

Retrieve website model

Returns
Website|bool

Definition at line 329 of file Group.php.

330  {
331  if ($this->getWebsiteId() === null) {
332  return false;
333  }
334  return $this->_storeManager->getWebsite($this->getWebsiteId());
335  }

◆ getWebsiteId()

getWebsiteId ( )
Returns
mixed

Implements GroupInterface.

Definition at line 386 of file Group.php.

387  {
388  return $this->_getData('website_id');
389  }

◆ isCanDelete()

isCanDelete ( )

Is can delete group

Returns
bool

Definition at line 342 of file Group.php.

343  {
344  if (!$this->getId()) {
345  return false;
346  }
347 
348  return $this->getWebsite()->getGroupsCount() > 1;
349  }

◆ isReadOnly()

isReadOnly (   $value = null)

Get/Set isReadOnly flag

Parameters
bool$value
Returns
bool

Definition at line 458 of file Group.php.

459  {
460  if (null !== $value) {
461  $this->_isReadOnly = (bool)$value;
462  }
463  return $this->_isReadOnly;
464  }
$value
Definition: gender.phtml:16

◆ setCode()

setCode (   $code)

Sets group code.

Parameters
string$code
Returns
$this
Since
100.2.0

Since
100.2.0

Implements GroupInterface.

Definition at line 505 of file Group.php.

506  {
507  return $this->setData('code', $code);
508  }
$code
Definition: info.phtml:12

◆ setDefaultStoreId()

setDefaultStoreId (   $defaultStoreId)

Parameters
int$defaultStoreId
Returns
$this

Implements GroupInterface.

Definition at line 362 of file Group.php.

363  {
364  return $this->setData('default_store_id', $defaultStoreId);
365  }

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\Store\Api\Data\GroupExtensionInterface  $extensionAttributes)

{}

Definition at line 521 of file Group.php.

523  {
525  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)

◆ setName()

setName (   $name)

Parameters
string$name
Returns
$this

Implements GroupInterface.

Definition at line 487 of file Group.php.

488  {
489  return $this->setData('name', $name);
490  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setRootCategoryId()

setRootCategoryId (   $rootCategoryId)

Parameters
int$rootCategoryId
Returns
$this

Implements GroupInterface.

Definition at line 378 of file Group.php.

379  {
380  return $this->setData('root_category_id', $rootCategoryId);
381  }

◆ setStores()

setStores (   $stores)

Set website stores

Parameters

Definition at line 182 of file Group.php.

183  {
184  $this->_stores = [];
185  $this->_storesCount = 0;
186  foreach ($stores as $store) {
187  $this->_stores[$store->getId()] = $store;
188  $this->_storeIds[$store->getId()] = $store->getId();
189  $this->_storeCodes[$store->getId()] = $store->getCode();
190  if ($this->getDefaultStoreId() == $store->getId()) {
191  $this->_defaultStore = $store;
192  }
193  $this->_storesCount++;
194  }
195  }

◆ setWebsite()

setWebsite ( Website  $website)

Set relation to the website

Parameters
Website$website
Returns
void

Definition at line 319 of file Group.php.

320  {
321  $this->setWebsiteId($website->getId());
322  }
setWebsiteId($websiteId)
Definition: Group.php:394

◆ setWebsiteId()

setWebsiteId (   $websiteId)

Parameters
int$websiteId
Returns
$this

Implements GroupInterface.

Definition at line 394 of file Group.php.

395  {
396  return $this->setData('website_id', $websiteId);
397  }

Field Documentation

◆ $_cacheTag

$_cacheTag = true
protected

Definition at line 31 of file Group.php.

◆ $_configDataResource

$_configDataResource
protected

Definition at line 86 of file Group.php.

◆ $_defaultStore

$_defaultStore
protected

Definition at line 76 of file Group.php.

◆ $_eventObject

$_eventObject = 'store_group'
protected

Definition at line 41 of file Group.php.

◆ $_eventPrefix

$_eventPrefix = 'store_group'
protected

Definition at line 36 of file Group.php.

◆ $_storeCodes

$_storeCodes = []
protected

Definition at line 62 of file Group.php.

◆ $_storeIds

$_storeIds = []
protected

Definition at line 55 of file Group.php.

◆ $_storeListFactory

$_storeListFactory
protected

Definition at line 91 of file Group.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 96 of file Group.php.

◆ $_stores

$_stores
protected

Definition at line 48 of file Group.php.

◆ $_storesCount

$_storesCount = 0
protected

Definition at line 69 of file Group.php.

◆ CACHE_TAG

const CACHE_TAG = 'store_group'

Definition at line 26 of file Group.php.

◆ ENTITY

const ENTITY = 'store_group'

Definition at line 24 of file Group.php.


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