Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Group.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Customer\Model;
7 
19 {
20  const NOT_LOGGED_IN_ID = 0;
21 
22  const CUST_GROUP_ALL = 32000;
23 
24  const ENTITY = 'customer_group';
25 
27 
33  protected $_eventPrefix = 'customer_group';
34 
42  protected $_eventObject = 'object';
43 
47  protected $_storesConfig;
48 
53 
57  protected $classModelFactory;
58 
72  public function __construct(
73  \Magento\Framework\Model\Context $context,
74  \Magento\Framework\Registry $registry,
75  \Magento\Store\Model\StoresConfig $storesConfig,
76  \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor,
77  \Magento\Tax\Model\ClassModelFactory $classModelFactory,
78  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
79  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
80  array $data = []
81  ) {
82  $this->_storesConfig = $storesConfig;
83  $this->dataObjectProcessor = $dataObjectProcessor;
84  $this->classModelFactory = $classModelFactory;
85  parent::__construct(
86  $context,
87  $registry,
88  $resource,
89  $resourceCollection,
90  $data
91  );
92  }
93 
97  protected function _construct()
98  {
99  $this->_init(\Magento\Customer\Model\ResourceModel\Group::class);
100  }
101 
108  public function setCode($value)
109  {
110  return $this->setCustomerGroupCode($value);
111  }
112 
118  public function getCode()
119  {
120  return $this->getCustomerGroupCode();
121  }
122 
128  public function getTaxClassName()
129  {
130  $taxClassName = $this->getData('tax_class_name');
131  if ($taxClassName) {
132  return $taxClassName;
133  }
134  $classModel = $this->classModelFactory->create();
135  $classModel->load($this->getTaxClassId());
136  $taxClassName = $classModel->getClassName();
137  $this->setData('tax_class_name', $taxClassName);
138  return $taxClassName;
139  }
140 
146  public function usesAsDefault()
147  {
148  $data = $this->_storesConfig->getStoresConfigByPath(
150  );
151  if (in_array($this->getId(), $data)) {
152  return true;
153  }
154  return false;
155  }
156 
162  public function beforeSave()
163  {
164  $this->_prepareData();
165  return parent::beforeSave();
166  }
167 
173  protected function _prepareData()
174  {
175  $this->setCode(substr($this->getCode(), 0, self::GROUP_CODE_MAX_LENGTH));
176  return $this;
177  }
178 }
getData($key='', $index=null)
Definition: DataObject.php:119
$resource
Definition: bulk.php:12
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Store\Model\StoresConfig $storesConfig, \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor, \Magento\Tax\Model\ClassModelFactory $classModelFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Group.php:72
$value
Definition: gender.phtml:16