Skip to content

Commit 3b7548a

Browse files
author
Ganin, Roman(rganin)
committed
Merge pull request #490 from magento-troll/MAGETWO-50542
MAGETWO-50542 Revert backward incompatible changes for Catalog module
2 parents 155d659 + 39b67cb commit 3b7548a

File tree

93 files changed

+1500
-500
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1500
-500
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ protected function _prepareBundlePriceByType($priceType, $entityIds = null)
157157
'=?',
158158
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
159159
);
160-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
160+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
161161
$this->_addAttributeToSelect($select, 'status', "e.$linkField", 'cs.store_id', $statusCond, true);
162162
if ($this->moduleManager->isEnabled('Magento_Tax')) {
163163
$taxClassId = $this->_addAttributeToSelect($select, 'tax_class_id', "e.$linkField", 'cs.store_id');
@@ -404,7 +404,7 @@ protected function _calculateBundleSelectionPrice($priceType)
404404
);
405405
}
406406

407-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
407+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
408408
$select = $connection->select()->from(
409409
['i' => $this->_getBundlePriceTable()],
410410
['entity_id', 'customer_group_id', 'website_id']
@@ -484,7 +484,7 @@ protected function _prepareBundlePrice($entityIds = null)
484484
protected function _prepareTierPriceIndex($entityIds = null)
485485
{
486486
$connection = $this->getConnection();
487-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
487+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
488488
// remove index by bundle products
489489
$select = $connection->select()->from(
490490
['i' => $this->_getTierPriceIndexTable()],

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected function _getBundleOptionTable()
4747
protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryTable = false)
4848
{
4949
$this->_cleanBundleOptionStockData();
50-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
50+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
5151
$idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable();
5252
$connection = $this->getConnection();
5353
$select = $connection->select()->from(
@@ -118,7 +118,7 @@ protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryT
118118
protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false)
119119
{
120120
$this->_prepareBundleOptionStockData($entityIds, $usePrimaryTable);
121-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
121+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
122122
$connection = $this->getConnection();
123123
$select = $connection->select()->from(
124124
['e' => $this->getTable('catalog_product_entity')],

app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@ class Edit extends \Magento\Catalog\Controller\Adminhtml\Category
2828
* @param \Magento\Backend\App\Action\Context $context
2929
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
3030
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
31-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
3231
*/
3332
public function __construct(
3433
\Magento\Backend\App\Action\Context $context,
3534
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
36-
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
37-
\Magento\Store\Model\StoreManagerInterface $storeManager
35+
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
3836
) {
3937
parent::__construct($context);
4038
$this->resultPageFactory = $resultPageFactory;
4139
$this->resultJsonFactory = $resultJsonFactory;
42-
$this->storeManager = $storeManager;
4340
}
4441

4542
/**
@@ -52,20 +49,20 @@ public function __construct(
5249
public function execute()
5350
{
5451
$storeId = (int)$this->getRequest()->getParam('store');
55-
$store = $this->storeManager->getStore($storeId);
56-
$this->storeManager->setCurrentStore($store->getCode());
52+
$store = $this->getStoreManager()->getStore($storeId);
53+
$this->getStoreManager()->setCurrentStore($store->getCode());
5754

5855
$categoryId = (int)$this->getRequest()->getParam('id');
5956

6057
if (!$categoryId) {
6158
if ($storeId) {
62-
$categoryId = (int)$this->storeManager->getStore($storeId)->getRootCategoryId();
59+
$categoryId = (int)$this->getStoreManager()->getStore($storeId)->getRootCategoryId();
6360
} else {
64-
$defaultStoreView = $this->storeManager->getDefaultStoreView();
61+
$defaultStoreView = $this->getStoreManager()->getDefaultStoreView();
6562
if ($defaultStoreView) {
6663
$categoryId = (int)$defaultStoreView->getRootCategoryId();
6764
} else {
68-
$stores = $this->storeManager->getStores();
65+
$stores = $this->getStoreManager()->getStores();
6966
if (count($stores)) {
7067
$store = reset($stores);
7168
$categoryId = (int)$store->getRootCategoryId();
@@ -114,4 +111,16 @@ public function execute()
114111

115112
return $resultPage;
116113
}
114+
115+
/**
116+
* @return \Magento\Store\Model\StoreManagerInterface
117+
*/
118+
private function getStoreManager()
119+
{
120+
if (null === $this->storeManager) {
121+
$this->storeManager = \Magento\Framework\App\ObjectManager::getInstance()
122+
->get('Magento\Store\Model\StoreManagerInterface');
123+
}
124+
return $this->storeManager;
125+
}
117126
}

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

Lines changed: 121 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class AddAttributeToTemplate extends \Magento\Catalog\Controller\Adminhtml\Produ
6464
protected $attributeGroupFactory;
6565

6666
/**
67-
* @var AttributeManagementInterfaces
67+
* @var AttributeManagementInterface
6868
*/
6969
protected $attributeManagement;
7070

@@ -82,42 +82,15 @@ class AddAttributeToTemplate extends \Magento\Catalog\Controller\Adminhtml\Produ
8282
* @param \Magento\Backend\App\Action\Context $context
8383
* @param Builder $productBuilder
8484
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
85-
* @param AttributeRepositoryInterface $attributeRepository
86-
* @param AttributeSetRepositoryInterface $attributeSetRepository
87-
* @param AttributeGroupRepositoryInterface $attributeGroupRepository
88-
* @param AttributeGroupInterfaceFactory $attributeGroupFactory
89-
* @param SearchCriteriaBuilder $searchCriteriaBuilder
90-
* @param SortOrderBuilder $sortOrderBuilder
91-
* @param AttributeManagementInterface $attributeManagement
92-
* @param LoggerInterface $logger
93-
* @param ExtensionAttributesFactory $extensionAttributesFactory
9485
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9586
*/
9687
public function __construct(
9788
\Magento\Backend\App\Action\Context $context,
9889
\Magento\Catalog\Controller\Adminhtml\Product\Builder $productBuilder,
99-
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
100-
AttributeRepositoryInterface $attributeRepository,
101-
AttributeSetRepositoryInterface $attributeSetRepository,
102-
AttributeGroupRepositoryInterface $attributeGroupRepository,
103-
AttributeGroupInterfaceFactory $attributeGroupFactory,
104-
SearchCriteriaBuilder $searchCriteriaBuilder,
105-
SortOrderBuilder $sortOrderBuilder,
106-
AttributeManagementInterface $attributeManagement,
107-
LoggerInterface $logger,
108-
ExtensionAttributesFactory $extensionAttributesFactory
90+
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
10991
) {
11092
parent::__construct($context, $productBuilder);
11193
$this->resultJsonFactory = $resultJsonFactory;
112-
$this->attributeRepository = $attributeRepository;
113-
$this->attributeSetRepository = $attributeSetRepository;
114-
$this->attributeGroupRepository = $attributeGroupRepository;
115-
$this->attributeGroupFactory = $attributeGroupFactory;
116-
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
117-
$this->sortOrderBuilder = $sortOrderBuilder;
118-
$this->attributeManagement = $attributeManagement;
119-
$this->logger = $logger;
120-
$this->extensionAttributesFactory = $extensionAttributesFactory;
12194
}
12295

12396
/**
@@ -133,22 +106,22 @@ public function execute()
133106

134107
try {
135108
/** @var AttributeSetInterface $attributeSet */
136-
$attributeSet = $this->attributeSetRepository->get($request->getParam('templateId'));
109+
$attributeSet = $this->getAttributeSetRepository()->get($request->getParam('templateId'));
137110
$groupCode = $request->getParam('groupCode');
138111
$groupName = $request->getParam('groupName');
139112
$groupSortOrder = $request->getParam('groupSortOrder');
140113

141114
$attributeSearchCriteria = $this->getBasicAttributeSearchCriteriaBuilder()->create();
142-
$attributeGroupSearchCriteria = $this->searchCriteriaBuilder
115+
$attributeGroupSearchCriteria = $this->getSearchCriteriaBuilder()
143116
->addFilter('attribute_set_id', $attributeSet->getAttributeSetId())
144117
->addFilter('attribute_group_code', $groupCode)
145-
->addSortOrder($this->sortOrderBuilder->setAscendingDirection()->create())
118+
->addSortOrder($this->getSortOrderBuilder()->setAscendingDirection()->create())
146119
->setPageSize(1)
147120
->create();
148121

149122
try {
150123
/** @var AttributeGroupInterface[] $attributeGroupItems */
151-
$attributeGroupItems = $this->attributeGroupRepository->getList($attributeGroupSearchCriteria)
124+
$attributeGroupItems = $this->getAttributeGroupRepository()->getList($attributeGroupSearchCriteria)
152125
->getItems();
153126

154127
if (!$attributeGroupItems) {
@@ -159,28 +132,28 @@ public function execute()
159132
$attributeGroup = reset($attributeGroupItems);
160133
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
161134
/** @var AttributeGroupInterface $attributeGroup */
162-
$attributeGroup = $this->attributeGroupFactory->create();
135+
$attributeGroup = $this->getAttributeGroupFactory()->create();
163136
}
164137

165138
$extensionAttributes = $attributeGroup->getExtensionAttributes()
166-
?: $this->extensionAttributesFactory->create(AttributeGroupInterface::class);
139+
?: $this->getExtensionAttributesFactory()->create(AttributeGroupInterface::class);
167140

168141
$extensionAttributes->setAttributeGroupCode($groupCode);
169142
$extensionAttributes->setSortOrder($groupSortOrder);
170143
$attributeGroup->setAttributeGroupName($groupName);
171144
$attributeGroup->setAttributeSetId($attributeSet->getAttributeSetId());
172145
$attributeGroup->setExtensionAttributes($extensionAttributes);
173146

174-
$this->attributeGroupRepository->save($attributeGroup);
147+
$this->getAttributeGroupRepository()->save($attributeGroup);
175148

176149
/** @var AttributeInterface[] $attributesItems */
177-
$attributesItems = $this->attributeRepository->getList(
150+
$attributesItems = $this->getAttributeRepository()->getList(
178151
ProductAttributeInterface::ENTITY_TYPE_CODE,
179152
$attributeSearchCriteria
180153
)->getItems();
181154

182155
array_walk($attributesItems, function (AttributeInterface $attribute) use ($attributeSet, $attributeGroup) {
183-
$this->attributeManagement->assign(
156+
$this->getAttributeManagement()->assign(
184157
ProductAttributeInterface::ENTITY_TYPE_CODE,
185158
$attributeSet->getAttributeSetId(),
186159
$attributeGroup->getAttributeGroupId(),
@@ -192,7 +165,7 @@ public function execute()
192165
$response->setError(true);
193166
$response->setMessage($e->getMessage());
194167
} catch (\Exception $e) {
195-
$this->logger->critical($e);
168+
$this->getLogger()->critical($e);
196169
$response->setError(true);
197170
$response->setMessage(__('Unable to add attribute'));
198171
}
@@ -214,8 +187,116 @@ private function getBasicAttributeSearchCriteriaBuilder()
214187
throw new LocalizedException(__('Please, specify attributes'));
215188
}
216189

217-
return $this->searchCriteriaBuilder
190+
return $this->getSearchCriteriaBuilder()
218191
->addFilter('attribute_set_id', new \Zend_Db_Expr('null'), 'is')
219192
->addFilter('attribute_id', [$attributeIds['selected']], 'in');
220193
}
194+
195+
/**
196+
* @return AttributeRepositoryInterface
197+
*/
198+
private function getAttributeRepository()
199+
{
200+
if (null === $this->attributeRepository) {
201+
$this->attributeRepository = \Magento\Framework\App\ObjectManager::getInstance()
202+
->get('Magento\Eav\Api\AttributeRepositoryInterface');
203+
}
204+
return $this->attributeRepository;
205+
}
206+
207+
/**
208+
* @return AttributeSetRepositoryInterface
209+
*/
210+
private function getAttributeSetRepository()
211+
{
212+
if (null === $this->attributeSetRepository) {
213+
$this->attributeSetRepository = \Magento\Framework\App\ObjectManager::getInstance()
214+
->get('Magento\Catalog\Api\AttributeSetRepositoryInterface');
215+
}
216+
return $this->attributeSetRepository;
217+
}
218+
219+
/**
220+
* @return AttributeGroupRepositoryInterface
221+
*/
222+
private function getAttributeGroupRepository()
223+
{
224+
if (null === $this->attributeGroupRepository) {
225+
$this->attributeGroupRepository = \Magento\Framework\App\ObjectManager::getInstance()
226+
->get('Magento\Eav\Api\AttributeGroupRepositoryInterface');
227+
}
228+
return $this->attributeGroupRepository;
229+
}
230+
231+
/**
232+
* @return AttributeGroupInterfaceFactory
233+
*/
234+
private function getAttributeGroupFactory()
235+
{
236+
if (null === $this->attributeGroupFactory) {
237+
$this->attributeGroupFactory = \Magento\Framework\App\ObjectManager::getInstance()
238+
->get('Magento\Eav\Api\Data\AttributeGroupInterfaceFactory');
239+
}
240+
return $this->attributeGroupFactory;
241+
}
242+
243+
/**
244+
* @return SearchCriteriaBuilder
245+
*/
246+
private function getSearchCriteriaBuilder()
247+
{
248+
if (null === $this->searchCriteriaBuilder) {
249+
$this->searchCriteriaBuilder = \Magento\Framework\App\ObjectManager::getInstance()
250+
->get('Magento\Framework\Api\SearchCriteriaBuilder');
251+
}
252+
return $this->searchCriteriaBuilder;
253+
}
254+
255+
/**
256+
* @return SortOrderBuilder
257+
*/
258+
private function getSortOrderBuilder()
259+
{
260+
if (null === $this->sortOrderBuilder) {
261+
$this->sortOrderBuilder = \Magento\Framework\App\ObjectManager::getInstance()
262+
->get('Magento\Framework\Api\SortOrderBuilder');
263+
}
264+
return $this->sortOrderBuilder;
265+
}
266+
267+
/**
268+
* @return AttributeManagementInterface
269+
*/
270+
private function getAttributeManagement()
271+
{
272+
if (null === $this->attributeManagement) {
273+
$this->attributeManagement = \Magento\Framework\App\ObjectManager::getInstance()
274+
->get('Magento\Eav\Api\AttributeManagementInterface');
275+
}
276+
return $this->attributeManagement;
277+
}
278+
279+
/**
280+
* @return LoggerInterface
281+
*/
282+
private function getLogger()
283+
{
284+
if (null === $this->logger) {
285+
$this->logger = \Magento\Framework\App\ObjectManager::getInstance()
286+
->get('Psr\Log\LoggerInterface');
287+
}
288+
return $this->logger;
289+
}
290+
291+
/**
292+
* @return ExtensionAttributesFactory
293+
*/
294+
private function getExtensionAttributesFactory()
295+
{
296+
if (null === $this->extensionAttributesFactory) {
297+
$this->extensionAttributesFactory = \Magento\Framework\App\ObjectManager::getInstance()
298+
->get('Magento\Framework\Api\ExtensionAttributesFactory');
299+
}
300+
return $this->extensionAttributesFactory;
301+
}
221302
}

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,17 @@ class Builder
4545
* @param Logger $logger
4646
* @param Registry $registry
4747
* @param WysiwygModel\Config $wysiwygConfig
48-
* @param StoreFactory $storeFactory
4948
*/
5049
public function __construct(
5150
ProductFactory $productFactory,
5251
Logger $logger,
5352
Registry $registry,
54-
WysiwygModel\Config $wysiwygConfig,
55-
StoreFactory $storeFactory
53+
WysiwygModel\Config $wysiwygConfig
5654
) {
5755
$this->productFactory = $productFactory;
5856
$this->logger = $logger;
5957
$this->registry = $registry;
6058
$this->wysiwygConfig = $wysiwygConfig;
61-
$this->storeFactory = $storeFactory;
6259
}
6360

6461
/**
@@ -73,7 +70,7 @@ public function build(RequestInterface $request)
7370
/** @var $product \Magento\Catalog\Model\Product */
7471
$product = $this->productFactory->create();
7572
$product->setStoreId($request->getParam('store', 0));
76-
$store = $this->storeFactory->create();
73+
$store = $this->getStoreFactory()->create();
7774
$store->load($request->getParam('store', 0));
7875

7976
$typeId = $request->getParam('type');
@@ -102,4 +99,16 @@ public function build(RequestInterface $request)
10299
$this->wysiwygConfig->setStoreId($request->getParam('store'));
103100
return $product;
104101
}
102+
103+
/**
104+
* @return StoreFactory
105+
*/
106+
private function getStoreFactory()
107+
{
108+
if (null === $this->storeFactory) {
109+
$this->storeFactory = \Magento\Framework\App\ObjectManager::getInstance()
110+
->get('Magento\Store\Model\StoreFactory');
111+
}
112+
return $this->storeFactory;
113+
}
105114
}

0 commit comments

Comments
 (0)