Group.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Model\Entity\Attribute;
  7. use Magento\Framework\Api\AttributeValueFactory;
  8. /**
  9. * @api
  10. * @method int getSortOrder()
  11. * @method \Magento\Eav\Model\Entity\Attribute\Group setSortOrder(int $value)
  12. * @method int getDefaultId()
  13. * @method \Magento\Eav\Model\Entity\Attribute\Group setDefaultId(int $value)
  14. * @method string getAttributeGroupCode()
  15. * @method \Magento\Eav\Model\Entity\Attribute\Group setAttributeGroupCode(string $value)
  16. * @method string getTabGroupCode()
  17. * @method \Magento\Eav\Model\Entity\Attribute\Group setTabGroupCode(string $value)
  18. * @since 100.0.2
  19. */
  20. class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
  21. \Magento\Eav\Api\Data\AttributeGroupInterface
  22. {
  23. /**
  24. * @var \Magento\Framework\Filter\Translit
  25. */
  26. private $translitFilter;
  27. /**
  28. * @param \Magento\Framework\Model\Context $context
  29. * @param \Magento\Framework\Registry $registry
  30. * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
  31. * @param AttributeValueFactory $customAttributeFactory
  32. * @param \Magento\Framework\Filter\Translit $translitFilter
  33. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  34. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  35. * @param array $data
  36. */
  37. public function __construct(
  38. \Magento\Framework\Model\Context $context,
  39. \Magento\Framework\Registry $registry,
  40. \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
  41. AttributeValueFactory $customAttributeFactory,
  42. \Magento\Framework\Filter\Translit $translitFilter,
  43. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  44. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  45. array $data = []
  46. ) {
  47. parent::__construct(
  48. $context,
  49. $registry,
  50. $extensionFactory,
  51. $customAttributeFactory,
  52. $resource,
  53. $resourceCollection,
  54. $data
  55. );
  56. $this->translitFilter = $translitFilter;
  57. }
  58. /**
  59. * Resource initialization
  60. *
  61. * @return void
  62. * @codeCoverageIgnore
  63. */
  64. protected function _construct()
  65. {
  66. $this->_init(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Group::class);
  67. }
  68. /**
  69. * Checks if current attribute group exists
  70. *
  71. * @return bool
  72. * @codeCoverageIgnore
  73. */
  74. public function itemExists()
  75. {
  76. return $this->_getResource()->itemExists($this);
  77. }
  78. /**
  79. * Delete groups
  80. *
  81. * @return $this
  82. * @codeCoverageIgnore
  83. */
  84. public function deleteGroups()
  85. {
  86. return $this->_getResource()->deleteGroups($this);
  87. }
  88. /**
  89. * Processing object before save data
  90. *
  91. * @return $this
  92. */
  93. public function beforeSave()
  94. {
  95. if (!$this->getAttributeGroupCode()) {
  96. $groupName = $this->getAttributeGroupName();
  97. if ($groupName) {
  98. $attributeGroupCode = trim(
  99. preg_replace(
  100. '/[^a-z0-9]+/',
  101. '-',
  102. $this->translitFilter->filter(strtolower($groupName))
  103. ),
  104. '-'
  105. );
  106. if (empty($attributeGroupCode)) {
  107. // in the following code md5 is not used for security purposes
  108. $attributeGroupCode = md5($groupName);
  109. }
  110. $this->setAttributeGroupCode($attributeGroupCode);
  111. }
  112. }
  113. return parent::beforeSave();
  114. }
  115. /**
  116. * {@inheritdoc}
  117. * @codeCoverageIgnoreStart
  118. */
  119. public function getAttributeGroupId()
  120. {
  121. return $this->getData(self::GROUP_ID);
  122. }
  123. /**
  124. * {@inheritdoc}
  125. */
  126. public function getAttributeGroupName()
  127. {
  128. return $this->getData(self::GROUP_NAME);
  129. }
  130. /**
  131. * {@inheritdoc}
  132. */
  133. public function getAttributeSetId()
  134. {
  135. return $this->getData(self::ATTRIBUTE_SET_ID);
  136. }
  137. /**
  138. * {@inheritdoc}
  139. */
  140. public function setAttributeGroupId($attributeGroupId)
  141. {
  142. return $this->setData(self::GROUP_ID, $attributeGroupId);
  143. }
  144. /**
  145. * {@inheritdoc}
  146. */
  147. public function setAttributeGroupName($attributeGroupName)
  148. {
  149. return $this->setData(self::GROUP_NAME, $attributeGroupName);
  150. }
  151. /**
  152. * {@inheritdoc}
  153. */
  154. public function setAttributeSetId($attributeSetId)
  155. {
  156. return $this->setData(self::ATTRIBUTE_SET_ID, $attributeSetId);
  157. }
  158. /**
  159. * {@inheritdoc}
  160. *
  161. * @return \Magento\Eav\Api\Data\AttributeGroupExtensionInterface|null
  162. */
  163. public function getExtensionAttributes()
  164. {
  165. return $this->_getExtensionAttributes();
  166. }
  167. /**
  168. * {@inheritdoc}
  169. *
  170. * @param \Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes
  171. * @return $this
  172. */
  173. public function setExtensionAttributes(
  174. \Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes
  175. ) {
  176. return $this->_setExtensionAttributes($extensionAttributes);
  177. }
  178. //@codeCoverageIgnoreEnd
  179. }