Skip to content

Commit 0cd6b3a

Browse files
committed
Merge pull request #470 from magento-tango/MAGETWO-50698
[Tango] Service Layer Refactoring
2 parents 066493c + 721c151 commit 0cd6b3a

File tree

6 files changed

+43
-138
lines changed

6 files changed

+43
-138
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/AddAttributeToTemplate.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Framework\Api\SortOrderBuilder;
2020
use Magento\Framework\Exception\LocalizedException;
2121
use Psr\Log\LoggerInterface;
22+
use Magento\Framework\Api\ExtensionAttributesFactory;
2223

2324
/**
2425
* Class AddAttributeToTemplate
@@ -72,6 +73,11 @@ class AddAttributeToTemplate extends \Magento\Catalog\Controller\Adminhtml\Produ
7273
*/
7374
protected $logger;
7475

76+
/**
77+
* @var ExtensionAttributesFactory
78+
*/
79+
protected $extensionAttributesFactory;
80+
7581
/**
7682
* @param \Magento\Backend\App\Action\Context $context
7783
* @param Builder $productBuilder
@@ -84,6 +90,7 @@ class AddAttributeToTemplate extends \Magento\Catalog\Controller\Adminhtml\Produ
8490
* @param SortOrderBuilder $sortOrderBuilder
8591
* @param AttributeManagementInterface $attributeManagement
8692
* @param LoggerInterface $logger
93+
* @param ExtensionAttributesFactory $extensionAttributesFactory
8794
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8895
*/
8996
public function __construct(
@@ -97,7 +104,8 @@ public function __construct(
97104
SearchCriteriaBuilder $searchCriteriaBuilder,
98105
SortOrderBuilder $sortOrderBuilder,
99106
AttributeManagementInterface $attributeManagement,
100-
LoggerInterface $logger
107+
LoggerInterface $logger,
108+
ExtensionAttributesFactory $extensionAttributesFactory
101109
) {
102110
parent::__construct($context, $productBuilder);
103111
$this->resultJsonFactory = $resultJsonFactory;
@@ -109,6 +117,7 @@ public function __construct(
109117
$this->sortOrderBuilder = $sortOrderBuilder;
110118
$this->attributeManagement = $attributeManagement;
111119
$this->logger = $logger;
120+
$this->extensionAttributesFactory = $extensionAttributesFactory;
112121
}
113122

114123
/**
@@ -153,10 +162,14 @@ public function execute()
153162
$attributeGroup = $this->attributeGroupFactory->create();
154163
}
155164

156-
$attributeGroup->setAttributeGroupCode($groupCode);
157-
$attributeGroup->setSortOrder($groupSortOrder);
165+
$extensionAttributes = $attributeGroup->getExtensionAttributes()
166+
?: $this->extensionAttributesFactory->create(AttributeGroupInterface::class);
167+
168+
$extensionAttributes->setAttributeGroupCode($groupCode);
169+
$extensionAttributes->setSortOrder($groupSortOrder);
158170
$attributeGroup->setAttributeGroupName($groupName);
159171
$attributeGroup->setAttributeSetId($attributeSet->getAttributeSetId());
172+
$attributeGroup->setExtensionAttributes($extensionAttributes);
160173

161174
$this->attributeGroupRepository->save($attributeGroup);
162175

app/code/Magento/Eav/Api/Data/AttributeGroupInterface.php

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
interface AttributeGroupInterface extends ExtensibleDataInterface
1111
{
1212
const GROUP_ID = 'attribute_group_id';
13+
1314
const GROUP_NAME = 'attribute_group_name';
15+
1416
const ATTRIBUTE_SET_ID = 'attribute_set_id';
15-
const SORT_ORDER = 'sort_order';
16-
const DEFAULT_ID = 'default_id';
17-
const ATTRIBUTE_GROUP_CODE = 'attribute_group_code';
18-
const SCOPE_CODE = 'tab_group_code';
1917

2018
/**
2119
* Retrieve id
@@ -62,66 +60,6 @@ public function getAttributeSetId();
6260
*/
6361
public function setAttributeSetId($attributeSetId);
6462

65-
/**
66-
* Retrieve sort order
67-
*
68-
* @return int
69-
*/
70-
public function getSortOrder();
71-
72-
/**
73-
* Set sort order
74-
*
75-
* @param int $sortOrder
76-
* @return $this
77-
*/
78-
public function setSortOrder($sortOrder);
79-
80-
/**
81-
* Retrieve default ID
82-
*
83-
* @return int
84-
*/
85-
public function getDefaultId();
86-
87-
/**
88-
* Set default ID
89-
*
90-
* @param int $defaultId
91-
* @return $this
92-
*/
93-
public function setDefaultId($defaultId);
94-
95-
/**
96-
* Retrieve attribute group code
97-
*
98-
* @return string
99-
*/
100-
public function getAttributeGroupCode();
101-
102-
/**
103-
* Set attribute group code
104-
*
105-
* @param string $attributeGroupCode
106-
* @return $this
107-
*/
108-
public function setAttributeGroupCode($attributeGroupCode);
109-
110-
/**
111-
* Retrieve scope code
112-
*
113-
* @return string
114-
*/
115-
public function getScopeCode();
116-
117-
/**
118-
* Set scope code
119-
*
120-
* @param string $scopeCode
121-
* @return $this
122-
*/
123-
public function setScopeCode($scopeCode);
124-
12563
/**
12664
* Retrieve existing extension attributes object.
12765
*

app/code/Magento/Eav/Model/Attribute/GroupRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ protected function retrieveAttributeSetIdFromSearchCriteria(
199199
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
200200
* @return null|string
201201
*/
202-
protected function retrieveAttributeGroupCodeFromSearchCriteria(
202+
private function retrieveAttributeGroupCodeFromSearchCriteria(
203203
\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
204204
) {
205205
foreach ($searchCriteria->getFilterGroups() as $group) {
206206
foreach ($group->getFilters() as $filter) {
207-
if ($filter->getField() == 'attribute_group_code') {
207+
if ($filter->getField() === 'attribute_group_code') {
208208
return $filter->getValue();
209209
}
210210
}

app/code/Magento/Eav/Model/Entity/Attribute/Group.php

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
*
1414
* @method \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group _getResource()
1515
* @method \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group getResource()
16+
* @method int getSortOrder()
17+
* @method \Magento\Eav\Model\Entity\Attribute\Group setSortOrder(int $value)
18+
* @method int getDefaultId()
19+
* @method \Magento\Eav\Model\Entity\Attribute\Group setDefaultId(int $value)
20+
* @method string getAttributeGroupCode()
21+
* @method \Magento\Eav\Model\Entity\Attribute\Group setAttributeGroupCode(string $value)
22+
* @method string getTabGroupCode()
23+
* @method \Magento\Eav\Model\Entity\Attribute\Group setTabGroupCode(string $value)
1624
*/
1725
class Group extends \Magento\Framework\Model\AbstractExtensibleModel implements
1826
\Magento\Eav\Api\Data\AttributeGroupInterface
@@ -164,70 +172,6 @@ public function setAttributeSetId($attributeSetId)
164172
return $this->setData(self::ATTRIBUTE_SET_ID, $attributeSetId);
165173
}
166174

167-
/**
168-
* {@inheritdoc}
169-
*/
170-
public function getSortOrder()
171-
{
172-
return $this->getData(self::SORT_ORDER);
173-
}
174-
175-
/**
176-
* {@inheritdoc}
177-
*/
178-
public function setSortOrder($sortOrder)
179-
{
180-
return $this->setData(self::SORT_ORDER, $sortOrder);
181-
}
182-
183-
/**
184-
* {@inheritdoc}
185-
*/
186-
public function getDefaultId()
187-
{
188-
return $this->getData(self::DEFAULT_ID);
189-
}
190-
191-
/**
192-
* {@inheritdoc}
193-
*/
194-
public function setDefaultId($defaultId)
195-
{
196-
return $this->setData(self::DEFAULT_ID, $defaultId);
197-
}
198-
199-
/**
200-
* {@inheritdoc}
201-
*/
202-
public function getAttributeGroupCode()
203-
{
204-
return $this->getData(self::ATTRIBUTE_GROUP_CODE);
205-
}
206-
207-
/**
208-
* {@inheritdoc}
209-
*/
210-
public function setAttributeGroupCode($attributeGroupCode)
211-
{
212-
return $this->setData(self::ATTRIBUTE_GROUP_CODE, $attributeGroupCode);
213-
}
214-
215-
/**
216-
* {@inheritdoc}
217-
*/
218-
public function getScopeCode()
219-
{
220-
return $this->getData(self::SCOPE_CODE);
221-
}
222-
223-
/**
224-
* {@inheritdoc}
225-
*/
226-
public function setScopeCode($scopeCode)
227-
{
228-
return $this->setData(self::SCOPE_CODE, $scopeCode);
229-
}
230-
231175
/**
232176
* {@inheritdoc}
233177
*
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
10+
<extension_attributes for="Magento\Eav\Api\Data\AttributeGroupInterface">
11+
<attribute code="attribute_group_code" type="string" />
12+
<attribute code="sort_order" type="string" />
13+
</extension_attributes>
14+
</config>

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductAttributeGroupRepositoryTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,7 @@ protected function createGroupData($attributeSetId)
165165
{
166166
return [
167167
'attribute_group_name' => 'empty_attribute_group',
168-
'attribute_set_id' => $attributeSetId,
169-
'sort_order' => 10,
170-
'default_id' => 5,
171-
'attribute_group_code' => 'empty_attribute_group',
172-
'scope_code' => 'default_tab',
168+
'attribute_set_id' => $attributeSetId
173169
];
174170
}
175171

0 commit comments

Comments
 (0)