Skip to content

Commit fb95956

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1344 from magento-engcom/develop-prs
Public Pull Requests #7742 #6990 #8999 #9796 #3129 #10259
2 parents 929a852 + d83e0e9 commit fb95956

File tree

16 files changed

+170
-80
lines changed

16 files changed

+170
-80
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ public function execute()
8282
{
8383
$collection = $this->filter->getCollection($this->collectionFactory->create());
8484
$productIds = $collection->getAllIds();
85-
$storeId = (int) $this->getRequest()->getParam('store', 0);
85+
$requestStoreId = $storeId = $this->getRequest()->getParam('store', null);
86+
$filterRequest = $this->getRequest()->getParam('filters', null);
8687
$status = (int) $this->getRequest()->getParam('status');
87-
$filters = (array)$this->getRequest()->getParam('filters', []);
8888

89-
if (isset($filters['store_id'])) {
90-
$storeId = (int)$filters['store_id'];
89+
if (null !== $storeId && null !== $filterRequest) {
90+
$storeId = (isset($filterRequest['store_id'])) ? (int) $filterRequest['store_id'] : 0;
9191
}
9292

9393
try {
9494
$this->_validateMassStatus($productIds, $status);
9595
$this->_objectManager->get(\Magento\Catalog\Model\Product\Action::class)
96-
->updateAttributes($productIds, ['status' => $status], $storeId);
96+
->updateAttributes($productIds, ['status' => $status], (int) $storeId);
9797
$this->messageManager->addSuccess(__('A total of %1 record(s) have been updated.', count($productIds)));
9898
$this->_productPriceIndexerProcessor->reindexList($productIds);
9999
} catch (\Magento\Framework\Exception\LocalizedException $e) {
@@ -104,6 +104,6 @@ public function execute()
104104

105105
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
106106
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
107-
return $resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
107+
return $resultRedirect->setPath('catalog/*/', ['store' => $requestStoreId]);
108108
}
109109
}

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/MassStatusTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected function setUp()
123123

124124
public function testMassStatusAction()
125125
{
126-
$storeId = 1;
126+
$storeId = 2;
127127
$status = \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED;
128128
$filters = [
129129
'store_id' => 2,
@@ -138,7 +138,7 @@ public function testMassStatusAction()
138138
$this->request->expects($this->exactly(3))
139139
->method('getParam')
140140
->willReturnMap([
141-
['store', 0, $storeId],
141+
['store', null, $storeId],
142142
['status', null, $status],
143143
['filters', [], $filters]
144144
]);

app/code/Magento/Config/Block/System/Config/Form.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -427,21 +427,21 @@ private function getFieldData(\Magento\Config\Model\Config\Structure\Element\Fie
427427
if ($data === null) {
428428
if (array_key_exists($path, $this->_configData)) {
429429
$data = $this->_configData[$path];
430-
431-
if ($field->hasBackendModel()) {
432-
$backendModel = $field->getBackendModel();
433-
$backendModel->setPath($path)
434-
->setValue($data)
435-
->setWebsite($this->getWebsiteCode())
436-
->setStore($this->getStoreCode())
437-
->afterLoad();
438-
$data = $backendModel->getValue();
439-
}
440430
} elseif ($field->getConfigPath() !== null) {
441431
$data = $this->getConfigValue($field->getConfigPath());
442432
} else {
443433
$data = $this->getConfigValue($path);
444434
}
435+
436+
if ($field->hasBackendModel()) {
437+
$backendModel = $field->getBackendModel();
438+
$backendModel->setPath($path)
439+
->setValue($data)
440+
->setWebsite($this->getWebsiteCode())
441+
->setStore($this->getStoreCode())
442+
->afterLoad();
443+
$data = $backendModel->getValue();
444+
}
445445
}
446446

447447
return $data;

app/code/Magento/Config/Test/Unit/Block/System/Config/FormTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ public function initFieldsDataProvider()
676676
true,
677677
'Config Value',
678678
null,
679-
0,
679+
1,
680680
true,
681681
false,
682682
true

app/code/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionsProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public function getProducts(ProductInterface $product)
6363
);
6464

6565
$this->linkedProductMap[$product->getId()] = $this->collectionFactory->create()
66-
->addAttributeToSelect(['price', 'special_price', 'special_from_date', 'special_to_date'])
66+
->addAttributeToSelect(
67+
['price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id']
68+
)
6769
->addIdFilter($productIds)
6870
->getItems();
6971
}

app/code/Magento/ConfigurableProduct/Test/Unit/Pricing/Price/LowestPriceOptionsProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testGetProducts()
9090
$this->productCollection
9191
->expects($this->once())
9292
->method('addAttributeToSelect')
93-
->with(['price', 'special_price', 'special_from_date', 'special_to_date'])
93+
->with(['price', 'special_price', 'special_from_date', 'special_to_date', 'tax_class_id'])
9494
->willReturnSelf();
9595
$this->productCollection->expects($this->once())->method('addIdFilter')->willReturnSelf();
9696
$this->productCollection->expects($this->once())->method('getItems')->willReturn($linkedProducts);

app/code/Magento/Customer/Block/CustomerScopeData.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Customer\Block;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Serialize\Serializer\Json;
10+
811
/**
912
* Class CustomerScopeData provide scope (website, store or store_group) information on front
1013
* Can be used, for example, on store front, in order to determine
@@ -20,23 +23,27 @@ class CustomerScopeData extends \Magento\Framework\View\Element\Template
2023
private $storeManager;
2124

2225
/**
23-
* @var \Magento\Framework\Json\EncoderInterface
26+
* @var Json
2427
*/
25-
private $jsonEncoder;
28+
private $serializer;
2629

2730
/**
2831
* @param \Magento\Framework\View\Element\Template\Context $context
2932
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
3033
* @param array $data
34+
* @param Json|null $serializer
35+
* @throws \RuntimeException
36+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3137
*/
3238
public function __construct(
3339
\Magento\Framework\View\Element\Template\Context $context,
3440
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
35-
array $data = []
41+
array $data = [],
42+
Json $serializer = null
3643
) {
3744
parent::__construct($context, $data);
3845
$this->storeManager = $context->getStoreManager();
39-
$this->jsonEncoder = $jsonEncoder;
46+
$this->serializer = $serializer?: ObjectManager::getInstance()->get(Json::class);
4047
}
4148

4249
/**
@@ -50,4 +57,16 @@ public function getWebsiteId()
5057
{
5158
return (int)$this->_storeManager->getStore()->getWebsiteId();
5259
}
60+
61+
/**
62+
* Encode invalidation rules.
63+
*
64+
* @param array $configuration
65+
* @return bool|string
66+
* @throws \InvalidArgumentException
67+
*/
68+
public function encodeConfiguration(array $configuration)
69+
{
70+
return $this->serializer->serialize($configuration);
71+
}
5372
}

app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Store\Api\Data\StoreInterface;
1111
use Magento\Store\Model\StoreManagerInterface;
1212
use Magento\Customer\Block\CustomerScopeData;
13-
use Magento\Framework\Json\EncoderInterface;
1413

1514
class CustomerScopeDataTest extends \PHPUnit_Framework_TestCase
1615
{
@@ -29,6 +28,9 @@ class CustomerScopeDataTest extends \PHPUnit_Framework_TestCase
2928
/** @var \Magento\Framework\Json\EncoderInterface|\PHPUnit_Framework_MockObject_MockObject */
3029
private $encoderMock;
3130

31+
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
32+
private $serializerMock;
33+
3234
protected function setUp()
3335
{
3436
$this->contextMock = $this->getMockBuilder(Context::class)
@@ -41,7 +43,10 @@ protected function setUp()
4143
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
4244
->getMock();
4345

44-
$this->encoderMock = $this->getMockBuilder(EncoderInterface::class)
46+
$this->encoderMock = $this->getMockBuilder(\Magento\Framework\Json\EncoderInterface::class)
47+
->getMock();
48+
49+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
4550
->getMock();
4651

4752
$this->contextMock->expects($this->exactly(2))
@@ -55,7 +60,8 @@ protected function setUp()
5560
$this->model = new CustomerScopeData(
5661
$this->contextMock,
5762
$this->encoderMock,
58-
[]
63+
[],
64+
$this->serializerMock
5965
);
6066
}
6167

@@ -78,4 +84,33 @@ public function testGetWebsiteId()
7884

7985
$this->assertEquals($storeId, $this->model->getWebsiteId());
8086
}
87+
88+
public function testEncodeConfiguration()
89+
{
90+
$rules = [
91+
'*' => [
92+
'Magento_Customer/js/invalidation-processor' => [
93+
'invalidationRules' => [
94+
'website-rule' => [
95+
'Magento_Customer/js/invalidation-rules/website-rule' => [
96+
'scopeConfig' => [
97+
'websiteId' => 1,
98+
]
99+
]
100+
]
101+
]
102+
]
103+
],
104+
];
105+
106+
$this->serializerMock->expects($this->any())
107+
->method('serialize')
108+
->with($rules)
109+
->willReturn(json_encode($rules));
110+
111+
$this->assertEquals(
112+
json_encode($rules),
113+
$this->model->encodeConfiguration($rules)
114+
);
115+
}
81116
}

app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
*/
66

77
// @codingStandardsIgnoreFile
8-
?>
9-
<?php
108
/* @var $block \Magento\Customer\Block\CustomerScopeData */
119
?>
1210
<script type="text/x-magento-init">
13-
<?php
14-
/* @noEscape */
15-
echo \Zend_Json::encode([
11+
<?= /* @noEscape */ $block->encodeConfiguration([
1612
'*' => ['Magento_Customer/js/invalidation-processor' => [
1713
'invalidationRules' => [
1814
'website-rule' => [
@@ -25,5 +21,5 @@
2521
]
2622
]],
2723
]);
28-
?>
24+
?>
2925
</script>

app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
189189
*
190190
* @param int $storeId
191191
* @param string $attributeCode
192+
* @param string $column Add attribute value to given column
192193
* @return void
193194
*/
194-
protected function _joinAttribute($storeId, $attributeCode)
195+
protected function _joinAttribute($storeId, $attributeCode, $column = null)
195196
{
196197
$connection = $this->getConnection();
197198
$attribute = $this->_getAttribute($attributeCode);
@@ -204,6 +205,8 @@ protected function _joinAttribute($storeId, $attributeCode)
204205
. ' AND ' . $connection->quoteInto($attrTableAlias . '.attribute_id = ?', $attribute['attribute_id']),
205206
[]
206207
);
208+
// Global scope attribute value
209+
$columnValue = 't1_' . $attributeCode . '.value';
207210

208211
if (!$attribute['is_global']) {
209212
$attrTableAlias2 = 't2_' . $attributeCode;
@@ -214,6 +217,15 @@ protected function _joinAttribute($storeId, $attributeCode)
214217
. ' AND ' . $connection->quoteInto($attrTableAlias2 . '.store_id = ?', $storeId),
215218
[]
216219
);
220+
// Store scope attribute value
221+
$columnValue = $this->getConnection()->getIfNullSql('t2_' . $attributeCode . '.value', $columnValue);
222+
}
223+
224+
// Add attribute value to result set if needed
225+
if (isset($column)) {
226+
$this->_select->columns([
227+
$column => $columnValue
228+
]);
217229
}
218230
}
219231

@@ -282,30 +294,15 @@ public function getCollection($storeId)
282294
// Join product images required attributes
283295
$imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId());
284296
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_NONE != $imageIncludePolicy) {
285-
$this->_joinAttribute($store->getId(), 'name');
286-
$this->_select->columns(
287-
['name' => $this->getConnection()->getIfNullSql('t2_name.value', 't1_name.value')]
288-
);
289-
297+
$this->_joinAttribute($store->getId(), 'name', 'name');
290298
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) {
291-
$this->_joinAttribute($store->getId(), 'thumbnail');
292-
$this->_select->columns(
293-
[
294-
'thumbnail' => $this->getConnection()->getIfNullSql(
295-
't2_thumbnail.value',
296-
't1_thumbnail.value'
297-
),
298-
]
299-
);
299+
$this->_joinAttribute($store->getId(), 'thumbnail', 'thumbnail');
300300
} elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy) {
301-
$this->_joinAttribute($store->getId(), 'image');
302-
$this->_select->columns(
303-
['image' => $this->getConnection()->getIfNullSql('t2_image.value', 't1_image.value')]
304-
);
301+
$this->_joinAttribute($store->getId(), 'image', 'image');
305302
}
306303
}
307304

308-
$query = $connection->query($this->_select);
305+
$query = $connection->query($this->prepareSelectStatement($this->_select));
309306
while ($row = $query->fetch()) {
310307
$product = $this->_prepareProduct($row, $store->getId());
311308
$products[$product->getId()] = $product;
@@ -422,6 +419,17 @@ protected function _getMediaConfig()
422419
return $this->_mediaConfig;
423420
}
424421

422+
/**
423+
* Allow to modify select statement with plugins
424+
*
425+
* @param \Magento\Framework\DB\Select $select
426+
* @return \Magento\Framework\DB\Select
427+
*/
428+
public function prepareSelectStatement(\Magento\Framework\DB\Select $select)
429+
{
430+
return $select;
431+
}
432+
425433
/**
426434
* Get product image URL from image filename and path
427435
*

0 commit comments

Comments
 (0)