Skip to content

Commit a0fc088

Browse files
author
Yaroslav Onischenko
committed
Merge remote-tracking branch 'mainline/develop' into develop
2 parents b40eaad + 0611634 commit a0fc088

File tree

42 files changed

+584
-258
lines changed

Some content is hidden

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

42 files changed

+584
-258
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ public function execute()
4949
$productId = (int) $this->getRequest()->getParam('id');
5050
$product = $this->productBuilder->build($this->getRequest());
5151

52-
if ($productId && !$product->getEntityId()) {
53-
$this->messageManager->addError(__('This product no longer exists.'));
52+
if (($productId && !$product->getEntityId())) {
5453
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
5554
$resultRedirect = $this->resultRedirectFactory->create();
55+
$this->messageManager->addError(__('This product doesn\'t exist.'));
56+
return $resultRedirect->setPath('catalog/*/');
57+
} else if ($productId === 0) {
58+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
59+
$resultRedirect = $this->resultRedirectFactory->create();
60+
$this->messageManager->addError(__('Invalid product id. Should be numeric value greater than 0'));
5661
return $resultRedirect->setPath('catalog/*/');
5762
}
5863

app/code/Magento/Catalog/Cron/RefreshSpecialPrices.php

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
namespace Magento\Catalog\Cron;
77

88
use Magento\Framework\App\ResourceConnection;
9+
use Magento\Catalog\Api\Data\CategoryInterface;
10+
use Magento\Framework\EntityManager\MetadataPool;
11+
use Magento\Framework\App\ObjectManager;
912

1013
class RefreshSpecialPrices
1114
{
@@ -44,6 +47,11 @@ class RefreshSpecialPrices
4447
*/
4548
protected $_connection;
4649

50+
/**
51+
* @var MetadataPool
52+
*/
53+
private $metadataPool;
54+
4755
/**
4856
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4957
* @param ResourceConnection $resource
@@ -131,22 +139,50 @@ protected function _refreshSpecialPriceByStore($storeId, $attrCode, $attrConditi
131139
$attribute = $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attrCode);
132140
$attributeId = $attribute->getAttributeId();
133141

142+
$linkField = $this->getMetadataPool()->getMetadata(CategoryInterface::class)->getLinkField();
143+
$identifierField = $this->getMetadataPool()->getMetadata(CategoryInterface::class)->getIdentifierField();
144+
134145
$connection = $this->_getConnection();
135146

136147
$select = $connection->select()->from(
137-
$this->_resource->getTableName(['catalog_product_entity', 'datetime']),
138-
['entity_id']
148+
['attr' => $this->_resource->getTableName(['catalog_product_entity', 'datetime'])],
149+
[
150+
$identifierField => 'cat.' . $identifierField,
151+
]
152+
)->joinLeft(
153+
['cat' => $this->_resource->getTableName('catalog_product_entity')],
154+
'cat.' . $linkField . '= attr.' . $linkField,
155+
''
139156
)->where(
140-
'attribute_id = ?',
157+
'attr.attribute_id = ?',
141158
$attributeId
142159
)->where(
143-
'store_id = ?',
160+
'attr.store_id = ?',
144161
$storeId
145162
)->where(
146-
'value = ?',
163+
'attr.value = ?',
147164
$attrConditionValue
148165
);
149166

150-
$this->_processor->getIndexer()->reindexList($connection->fetchCol($select, ['entity_id']));
167+
$selectData = $connection->fetchCol($select, $identifierField);
168+
169+
if (!empty($selectData)) {
170+
$this->_processor->getIndexer()->reindexList($selectData);
171+
}
172+
173+
}
174+
175+
/**
176+
* Get MetadataPool instance
177+
* @return MetadataPool
178+
*
179+
* @deprecated
180+
*/
181+
private function getMetadataPool()
182+
{
183+
if (null === $this->metadataPool) {
184+
$this->metadataPool = ObjectManager::getInstance()->get(MetadataPool::class);
185+
}
186+
return $this->metadataPool;
151187
}
152188
}

app/code/Magento/Catalog/Test/Unit/Cron/RefreshSpecialPricesTest.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Catalog\Test\Unit\Cron;
77

88
use Magento\Framework\App\ResourceConnection;
9+
use Magento\Framework\EntityManager\MetadataPool;
910

1011
class RefreshSpecialPricesTest extends \PHPUnit_Framework_TestCase
1112
{
@@ -49,6 +50,16 @@ class RefreshSpecialPricesTest extends \PHPUnit_Framework_TestCase
4950
*/
5051
protected $_priceProcessorMock;
5152

53+
/**
54+
* @var MetadataPool|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
protected $metadataPool;
57+
58+
/**
59+
* @var \Magento\Framework\EntityManager\EntityMetadata|\PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
protected $metadataMock;
62+
5263
protected function setUp()
5364
{
5465
$this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -72,6 +83,8 @@ protected function setUp()
7283
false
7384
);
7485

86+
$this->metadataMock = $this->getMock(\Magento\Framework\EntityManager\EntityMetadata::class, [], [], '', false);
87+
7588
$this->_model = $this->_objectManager->getObject(
7689
'Magento\Catalog\Cron\RefreshSpecialPrices',
7790
[
@@ -83,14 +96,30 @@ protected function setUp()
8396
'processor' => $this->_priceProcessorMock
8497
]
8598
);
99+
100+
$this->metadataPool = $this->getMock(MetadataPool::class, [], [], '', false);
101+
102+
$reflection = new \ReflectionClass(get_class($this->_model));
103+
$reflectionProperty = $reflection->getProperty('metadataPool');
104+
$reflectionProperty->setAccessible(true);
105+
$reflectionProperty->setValue($this->_model, $this->metadataPool);
86106
}
87107

88108
public function testRefreshSpecialPrices()
89109
{
90110
$idsToProcess = [1, 2, 3];
91111

112+
$this->metadataPool->expects($this->atLeastOnce())
113+
->method('getMetadata')
114+
->willReturn($this->metadataMock);
115+
116+
$this->metadataMock->expects($this->atLeastOnce())->method('getLinkField')->willReturn('row_id');
117+
118+
$this->metadataMock->expects($this->atLeastOnce())->method('getIdentifierField')->willReturn('entity_id');
119+
92120
$selectMock = $this->getMock('Magento\Framework\DB\Select', [], [], '', false);
93121
$selectMock->expects($this->any())->method('from')->will($this->returnSelf());
122+
$selectMock->expects($this->any())->method('joinLeft')->will($this->returnSelf());
94123
$selectMock->expects($this->any())->method('where')->will($this->returnSelf());
95124

96125
$connectionMock = $this->getMock('Magento\Framework\DB\Adapter\AdapterInterface', [], [], '', false);
@@ -99,12 +128,10 @@ public function testRefreshSpecialPrices()
99128
$this->any()
100129
)->method(
101130
'fetchCol'
102-
)->with(
103-
$selectMock,
104-
['entity_id']
105131
)->will(
106132
$this->returnValue($idsToProcess)
107133
);
134+
108135
$this->_resourceMock->expects(
109136
$this->once()
110137
)->method(
@@ -113,6 +140,14 @@ public function testRefreshSpecialPrices()
113140
$this->returnValue($connectionMock)
114141
);
115142

143+
$this->_resourceMock->expects(
144+
$this->any()
145+
)->method(
146+
'getTableName'
147+
)->will(
148+
$this->returnValue('category')
149+
);
150+
116151
$storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
117152
$storeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
118153

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ protected function getIsDeleteFieldConfig($sortOrder)
812812
'config' => [
813813
'componentType' => ActionDelete::NAME,
814814
'fit' => true,
815-
'sortOrder' => $sortOrder,
815+
'sortOrder' => $sortOrder
816816
],
817817
],
818818
],

app/code/Magento/Catalog/view/base/web/js/price-options.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ define([
2828
$.widget('mage.priceOptions', {
2929
options: globalOptions,
3030

31+
/**
32+
* @private
33+
*/
34+
_init: function initPriceBundle() {
35+
$(this.options.optionsSelector, this.element).trigger('change');
36+
},
37+
3138
/**
3239
* Widget creating method.
3340
* Triggered once.

app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ class Rule extends \Magento\Rule\Model\ResourceModel\AbstractResource
9191
* @param \Psr\Log\LoggerInterface $logger
9292
* @param \Magento\Framework\Stdlib\DateTime $dateTime
9393
* @param PriceCurrencyInterface $priceCurrency
94-
* @param \Magento\Framework\EntityManager\EntityManager $entityManager
95-
* @param array $associatedEntitiesMap
9694
* @param null $connectionName
9795
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9896
*/
@@ -107,8 +105,6 @@ public function __construct(
107105
\Psr\Log\LoggerInterface $logger,
108106
\Magento\Framework\Stdlib\DateTime $dateTime,
109107
PriceCurrencyInterface $priceCurrency,
110-
\Magento\Framework\EntityManager\EntityManager $entityManager,
111-
array $associatedEntitiesMap = [],
112108
$connectionName = null
113109
) {
114110
$this->_storeManager = $storeManager;
@@ -120,8 +116,7 @@ public function __construct(
120116
$this->_logger = $logger;
121117
$this->dateTime = $dateTime;
122118
$this->priceCurrency = $priceCurrency;
123-
$this->entityManager = $entityManager;
124-
$this->_associatedEntitiesMap = $associatedEntitiesMap;
119+
$this->_associatedEntitiesMap = $this->getAssociatedEntitiesMap();
125120
parent::__construct($context, $connectionName);
126121
}
127122

@@ -232,7 +227,7 @@ public function getRulesFromProduct($date, $websiteId, $customerGroupId, $produc
232227
*/
233228
public function load(\Magento\Framework\Model\AbstractModel $object, $value, $field = null)
234229
{
235-
$this->entityManager->load($object, $value, \Magento\CatalogRule\Api\Data\RuleInterface::class);
230+
$this->getEntityManager()->load($object, $value, \Magento\CatalogRule\Api\Data\RuleInterface::class);
236231
return $this;
237232
}
238233

@@ -243,7 +238,7 @@ public function load(\Magento\Framework\Model\AbstractModel $object, $value, $fi
243238
*/
244239
public function save(\Magento\Framework\Model\AbstractModel $object)
245240
{
246-
$this->entityManager->save(
241+
$this->getEntityManager()->save(
247242
$object,
248243
\Magento\CatalogRule\Api\Data\RuleInterface::class
249244
);
@@ -259,7 +254,34 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
259254
*/
260255
public function delete(AbstractModel $object)
261256
{
262-
$this->entityManager->delete($object, \Magento\CatalogRule\Api\Data\RuleInterface::class);
257+
$this->getEntityManager()->delete($object, \Magento\CatalogRule\Api\Data\RuleInterface::class);
263258
return $this;
264259
}
260+
261+
/**
262+
* @return array
263+
* @deprecated
264+
*/
265+
private function getAssociatedEntitiesMap()
266+
{
267+
if (!$this->_associatedEntitiesMap) {
268+
$this->_associatedEntitiesMap = \Magento\Framework\App\ObjectManager::getInstance()
269+
->get('Magento\CatalogRule\Model\ResourceModel\Rule\AssociatedEntityMap')
270+
->getData();
271+
}
272+
return $this->_associatedEntitiesMap;
273+
}
274+
275+
/**
276+
* @return \Magento\Framework\EntityManager\EntityManager
277+
* @deprecated
278+
*/
279+
private function getEntityManager()
280+
{
281+
if (null === $this->entityManager) {
282+
$this->entityManager = \Magento\Framework\App\ObjectManager::getInstance()
283+
->get(\Magento\Framework\EntityManager\EntityManager::class);
284+
}
285+
return $this->entityManager;
286+
}
265287
}

app/code/Magento/CatalogRule/Model/ResourceModel/Rule/Collection.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,24 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr
1515
protected $_associatedEntitiesMap;
1616

1717
/**
18+
* Collection constructor.
1819
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
1920
* @param \Psr\Log\LoggerInterface $logger
2021
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
2122
* @param \Magento\Framework\Event\ManagerInterface $eventManager
22-
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
23-
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
24-
* @param array $associatedEntitiesMap
23+
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
24+
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
2525
*/
2626
public function __construct(
2727
\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
2828
\Psr\Log\LoggerInterface $logger,
2929
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
3030
\Magento\Framework\Event\ManagerInterface $eventManager,
3131
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
32-
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null,
33-
array $associatedEntitiesMap = []
32+
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
3433
) {
35-
parent::__construct(
36-
$entityFactory,
37-
$logger,
38-
$fetchStrategy,
39-
$eventManager,
40-
$connection,
41-
$resource
42-
);
43-
$this->_associatedEntitiesMap = $associatedEntitiesMap;
34+
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
35+
$this->_associatedEntitiesMap = $this->getAssociatedEntitiesMap();
4436
}
4537

4638
/**
@@ -137,4 +129,18 @@ public function addCustomerGroupFilter($customerGroupId)
137129
}
138130
return $this;
139131
}
132+
133+
/**
134+
* @return array
135+
* @deprecated
136+
*/
137+
private function getAssociatedEntitiesMap()
138+
{
139+
if (!$this->_associatedEntitiesMap) {
140+
$this->_associatedEntitiesMap = \Magento\Framework\App\ObjectManager::getInstance()
141+
->get('Magento\CatalogRule\Model\ResourceModel\Rule\AssociatedEntityMap')
142+
->getData();
143+
}
144+
return $this->_associatedEntitiesMap;
145+
}
140146
}

app/code/Magento/CatalogRule/Model/Rule.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ class Rule extends \Magento\Rule\Model\AbstractModel implements \Magento\Catalog
138138
* Rule constructor.
139139
* @param \Magento\Framework\Model\Context $context
140140
* @param \Magento\Framework\Registry $registry
141-
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
142-
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
143141
* @param \Magento\Framework\Data\FormFactory $formFactory
144142
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
145143
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
@@ -163,8 +161,6 @@ class Rule extends \Magento\Rule\Model\AbstractModel implements \Magento\Catalog
163161
public function __construct(
164162
\Magento\Framework\Model\Context $context,
165163
\Magento\Framework\Registry $registry,
166-
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
167-
\Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
168164
\Magento\Framework\Data\FormFactory $formFactory,
169165
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
170166
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
@@ -199,8 +195,6 @@ public function __construct(
199195
parent::__construct(
200196
$context,
201197
$registry,
202-
$extensionFactory,
203-
$customAttributeFactory,
204198
$formFactory,
205199
$localeDate,
206200
$resource,
@@ -775,12 +769,13 @@ public function setExtensionAttributes(\Magento\CatalogRule\Api\Data\RuleExtensi
775769

776770
/**
777771
* @return Data\Condition\Converter
772+
* @deprecated
778773
*/
779774
private function getRuleConditionConverter()
780775
{
781776
if (null === $this->ruleConditionConverter) {
782777
$this->ruleConditionConverter = \Magento\Framework\App\ObjectManager::getInstance()
783-
->get('Magento\CatalogRule\Model\Data\Condition\Converter');
778+
->get(\Magento\CatalogRule\Model\Data\Condition\Converter::class);
784779
}
785780
return $this->ruleConditionConverter;
786781
}

0 commit comments

Comments
 (0)