Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 0aa3191

Browse files
authored
Merge pull request #3500 from magento-tsg-csl3/2.3-develop-pr12
[TSG-CSL3] For 2.3 (pr12)
2 parents 5498231 + bf02806 commit 0aa3191

File tree

16 files changed

+602
-99
lines changed

16 files changed

+602
-99
lines changed

app/code/Magento/Catalog/Model/Category/Link/SaveHandler.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Catalog\Model\Category\Link;
77

88
use Magento\Catalog\Api\Data\CategoryLinkInterface;
9-
use Magento\Catalog\Model\Indexer\Product\Category;
109
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
1110

1211
/**
@@ -40,6 +39,8 @@ public function __construct(
4039
}
4140

4241
/**
42+
* Execute
43+
*
4344
* @param object $entity
4445
* @param array $arguments
4546
* @return object
@@ -78,6 +79,8 @@ public function execute($entity, $arguments = [])
7879
}
7980

8081
/**
82+
* Get category links positions
83+
*
8184
* @param object $entity
8285
* @return array
8386
*/
@@ -106,27 +109,19 @@ private function getCategoryLinksPositions($entity)
106109
*/
107110
private function mergeCategoryLinks($newCategoryPositions, $oldCategoryPositions)
108111
{
109-
$result = [];
110112
if (empty($newCategoryPositions)) {
111-
return $result;
113+
return [];
112114
}
113115

116+
$categoryPositions = array_combine(array_column($oldCategoryPositions, 'category_id'), $oldCategoryPositions);
114117
foreach ($newCategoryPositions as $newCategoryPosition) {
115-
$key = array_search(
116-
$newCategoryPosition['category_id'],
117-
array_column($oldCategoryPositions, 'category_id')
118-
);
119-
120-
if ($key === false) {
121-
$result[] = $newCategoryPosition;
122-
} elseif (isset($oldCategoryPositions[$key])
123-
&& $oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']
124-
) {
125-
$result[] = $newCategoryPositions[$key];
126-
unset($oldCategoryPositions[$key]);
118+
$categoryId = $newCategoryPosition['category_id'];
119+
if (!isset($categoryPositions[$categoryId])) {
120+
$categoryPositions[$categoryId] = ['category_id' => $categoryId];
127121
}
122+
$categoryPositions[$categoryId]['position'] = $newCategoryPosition['position'];
128123
}
129-
$result = array_merge($result, $oldCategoryPositions);
124+
$result = array_values($categoryPositions);
130125

131126
return $result;
132127
}

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Eraser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ public function removeDisabledProducts(array &$ids, $storeId)
118118
private function getSelectForProducts(array $ids)
119119
{
120120
$productTable = $this->productIndexerHelper->getTable('catalog_product_entity');
121-
$select = $this->connection->select()->from($productTable)
121+
$select = $this->connection->select()
122+
->from(['product_table' => $productTable])
122123
->columns('entity_id')
123-
->where('entity_id IN(?)', $ids);
124+
->where('product_table.entity_id IN(?)', $ids);
124125
return $select;
125126
}
126127

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Indexer.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Api\Data\ProductInterface;
1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Framework\EntityManager\MetadataPool;
12+
use Magento\Store\Model\Store;
1213

1314
/**
1415
* Class Indexer
@@ -84,7 +85,7 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
8485
[
8586
'entity_id' => 'e.entity_id',
8687
'attribute_id' => 't.attribute_id',
87-
'value' => $this->_connection->getIfNullSql('`t2`.`value`', '`t`.`value`'),
88+
'value' => 't.value'
8889
]
8990
);
9091

@@ -99,32 +100,30 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
99100
sprintf('e.%s = t.%s ', $linkField, $linkField) . $this->_connection->quoteInto(
100101
' AND t.attribute_id IN (?)',
101102
array_keys($ids)
102-
) . ' AND t.store_id = 0',
103-
[]
104-
)->joinLeft(
105-
['t2' => $tableName],
106-
sprintf('t.%s = t2.%s ', $linkField, $linkField) .
107-
' AND t.attribute_id = t2.attribute_id ' .
108-
$this->_connection->quoteInto(
109-
' AND t2.store_id = ?',
110-
$storeId
111-
),
103+
) . ' AND ' . $this->_connection->quoteInto('t.store_id IN(?)', [
104+
Store::DEFAULT_STORE_ID,
105+
$storeId
106+
]),
112107
[]
113108
)->where(
114109
'e.entity_id = ' . $productId
115-
);
110+
)->order('t.store_id ASC');
116111
$cursor = $this->_connection->query($select);
117112
while ($row = $cursor->fetch(\Zend_Db::FETCH_ASSOC)) {
118113
$updateData[$ids[$row['attribute_id']]] = $row['value'];
119114
$valueColumnName = $ids[$row['attribute_id']] . $valueFieldSuffix;
120115
if (isset($describe[$valueColumnName])) {
121-
$valueColumns[$row['value']] = $valueColumnName;
116+
$valueColumns[$row['attribute_id']] = [
117+
'value' => $row['value'],
118+
'column_name' => $valueColumnName
119+
];
122120
}
123121
}
124122

125123
//Update not simple attributes (eg. dropdown)
126124
if (!empty($valueColumns)) {
127-
$valueIds = array_keys($valueColumns);
125+
$valueIds = array_column($valueColumns, 'value');
126+
$optionIdToAttributeName = array_column($valueColumns, 'column_name', 'value');
128127

129128
$select = $this->_connection->select()->from(
130129
['t' => $this->_productIndexerHelper->getTable('eav_attribute_option_value')],
@@ -133,14 +132,14 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
133132
$this->_connection->quoteInto('t.option_id IN (?)', $valueIds)
134133
)->where(
135134
$this->_connection->quoteInto('t.store_id IN(?)', [
136-
\Magento\Store\Model\Store::DEFAULT_STORE_ID,
135+
Store::DEFAULT_STORE_ID,
137136
$storeId
138137
])
139138
)
140139
->order('t.store_id ASC');
141140
$cursor = $this->_connection->query($select);
142141
while ($row = $cursor->fetch(\Zend_Db::FETCH_ASSOC)) {
143-
$valueColumnName = $valueColumns[$row['option_id']];
142+
$valueColumnName = $optionIdToAttributeName[$row['option_id']];
144143
if (isset($describe[$valueColumnName])) {
145144
$updateData[$valueColumnName] = $row['value'];
146145
}
@@ -150,6 +149,7 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
150149
$columnNames = array_keys($columns);
151150
$columnNames[] = 'attribute_set_id';
152151
$columnNames[] = 'type_id';
152+
$columnNames[] = $linkField;
153153
$select->from(
154154
['e' => $entityTableName],
155155
$columnNames
@@ -159,6 +159,7 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
159159
$cursor = $this->_connection->query($select);
160160
$row = $cursor->fetch(\Zend_Db::FETCH_ASSOC);
161161
if (!empty($row)) {
162+
$linkFieldId = $linkField;
162163
foreach ($row as $columnName => $value) {
163164
$updateData[$columnName] = $value;
164165
}
@@ -170,7 +171,7 @@ public function write($storeId, $productId, $valueFieldSuffix = '')
170171
if (!empty($updateData)) {
171172
$updateData += ['entity_id' => $productId];
172173
if ($linkField !== $metadata->getIdentifierField()) {
173-
$updateData += [$linkField => $productId];
174+
$updateData += [$linkField => $linkFieldId];
174175
}
175176
$updateFields = [];
176177
foreach ($updateData as $key => $value) {

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Row.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,17 @@ public function execute($id = null)
9696
/* @var $status \Magento\Eav\Model\Entity\Attribute */
9797
$status = $this->_productIndexerHelper->getAttribute(ProductInterface::STATUS);
9898
$statusTable = $status->getBackend()->getTable();
99+
$catalogProductEntityTable = $this->_productIndexerHelper->getTable('catalog_product_entity');
99100
$statusConditions = [
100-
'store_id IN(0,' . (int)$store->getId() . ')',
101-
'attribute_id = ' . (int)$status->getId(),
102-
$linkField . ' = ' . (int)$id,
101+
's.store_id IN(0,' . (int)$store->getId() . ')',
102+
's.attribute_id = ' . (int)$status->getId(),
103+
'e.entity_id = ' . (int)$id,
103104
];
104105
$select = $this->_connection->select();
105-
$select->from($statusTable, ['value'])
106+
$select->from(['e' => $catalogProductEntityTable], ['s.value'])
106107
->where(implode(' AND ', $statusConditions))
107-
->order('store_id DESC')
108+
->joinLeft(['s' => $statusTable], "e.{$linkField} = s.{$linkField}", [])
109+
->order('s.store_id DESC')
108110
->limit(1);
109111
$result = $this->_connection->query($select);
110112
$status = $result->fetchColumn(0);

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public function saveCategoryLinks(ProductInterface $product, array $categoryLink
9393
}
9494

9595
/**
96+
* Get category link metadata
97+
*
9698
* @return \Magento\Framework\EntityManager\EntityMetadataInterface
9799
*/
98100
private function getCategoryLinkMetadata()
@@ -114,16 +116,16 @@ private function getCategoryLinkMetadata()
114116
private function processCategoryLinks($newCategoryPositions, &$oldCategoryPositions)
115117
{
116118
$result = ['changed' => [], 'updated' => []];
119+
120+
$oldCategoryPositions = array_values($oldCategoryPositions);
121+
$oldCategoryList = array_column($oldCategoryPositions, 'category_id');
117122
foreach ($newCategoryPositions as $newCategoryPosition) {
118-
$key = array_search(
119-
$newCategoryPosition['category_id'],
120-
array_column($oldCategoryPositions, 'category_id')
121-
);
123+
$key = array_search($newCategoryPosition['category_id'], $oldCategoryList);
122124

123125
if ($key === false) {
124126
$result['changed'][] = $newCategoryPosition;
125127
} elseif ($oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']) {
126-
$result['updated'][] = $newCategoryPositions[$key];
128+
$result['updated'][] = $newCategoryPosition;
127129
unset($oldCategoryPositions[$key]);
128130
}
129131
}
@@ -132,6 +134,8 @@ private function processCategoryLinks($newCategoryPositions, &$oldCategoryPositi
132134
}
133135

134136
/**
137+
* Update category links
138+
*
135139
* @param ProductInterface $product
136140
* @param array $insertLinks
137141
* @param bool $insert
@@ -175,6 +179,8 @@ private function updateCategoryLinks(ProductInterface $product, array $insertLin
175179
}
176180

177181
/**
182+
* Delete category links
183+
*
178184
* @param ProductInterface $product
179185
* @param array $deleteLinks
180186
* @return array

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Action/EraserTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ public function testRemoveDeletedProducts()
5353
{
5454
$productsToDeleteIds = [1, 2];
5555
$select = $this->createMock(\Magento\Framework\DB\Select::class);
56-
$select->expects($this->once())->method('from')->with('catalog_product_entity')->will($this->returnSelf());
56+
$select->expects($this->once())
57+
->method('from')
58+
->with(['product_table' => 'catalog_product_entity'])
59+
->will($this->returnSelf());
5760
$select->expects($this->once())->method('columns')->with('entity_id')->will($this->returnSelf());
58-
$select->expects($this->once())->method('where')->with('entity_id IN(?)', $productsToDeleteIds)
61+
$select->expects($this->once())
62+
->method('where')
63+
->with('product_table.entity_id IN(?)', $productsToDeleteIds)
5964
->will($this->returnSelf());
6065
$products = [['entity_id' => 2]];
6166
$statement = $this->createMock(\Zend_Db_Statement_Interface::class);

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Action/RowTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ protected function setUp()
100100
->disableOriginalConstructor()
101101
->getMock();
102102
$this->connection->expects($this->any())->method('select')->willReturn($selectMock);
103-
$selectMock->expects($this->any())->method('from')->with(
104-
$attributeTable,
105-
['value']
106-
)->willReturnSelf();
103+
$selectMock->method('from')
104+
->willReturnSelf();
105+
$selectMock->method('joinLeft')
106+
->willReturnSelf();
107107
$selectMock->expects($this->any())->method('where')->willReturnSelf();
108108
$selectMock->expects($this->any())->method('order')->willReturnSelf();
109109
$selectMock->expects($this->any())->method('limit')->willReturnSelf();

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ define([
7878
pricesCode = [],
7979
priceValue, origin, finalPrice;
8080

81-
this.cache.additionalPriceObject = this.cache.additionalPriceObject || {};
81+
if (typeof newPrices !== 'undefined' && newPrices.hasOwnProperty('prices')) {
82+
this.cache.additionalPriceObject = {};
83+
} else {
84+
this.cache.additionalPriceObject = this.cache.additionalPriceObject || {};
85+
}
8286

8387
if (newPrices) {
8488
$.extend(this.cache.additionalPriceObject, newPrices);

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ define([
3535
var checkoutConfig = window.checkoutConfig,
3636
validators = [],
3737
observedElements = [],
38+
postcodeElements = [],
3839
postcodeElementName = 'postcode';
3940

4041
validators.push(defaultValidator);
@@ -78,11 +79,7 @@ define([
7879
}
7980

8081
$.each(elements, function (index, field) {
81-
var elementBinding = self.doElementBinding.bind(self),
82-
fullPath = formPath + '.' + field,
83-
func = uiRegistry.async(fullPath);
84-
85-
func(elementBinding);
82+
uiRegistry.async(formPath + '.' + field)(self.doElementBinding.bind(self));
8683
});
8784
},
8885

@@ -104,6 +101,7 @@ define([
104101

105102
if (element.index === postcodeElementName) {
106103
this.bindHandler(element, delay);
104+
postcodeElements.push(element);
107105
}
108106
},
109107

@@ -138,7 +136,13 @@ define([
138136
if (!formPopUpState.isVisible()) {
139137
clearTimeout(self.validateAddressTimeout);
140138
self.validateAddressTimeout = setTimeout(function () {
141-
self.postcodeValidation(element);
139+
if (element.index === postcodeElementName) {
140+
self.postcodeValidation(element);
141+
} else {
142+
$.each(postcodeElements, function (index, elem) {
143+
self.postcodeValidation(elem);
144+
});
145+
}
142146
self.validateFields();
143147
}, delay);
144148
}
@@ -151,7 +155,7 @@ define([
151155
* @return {*}
152156
*/
153157
postcodeValidation: function (postcodeElement) {
154-
var countryId = $('select[name="country_id"]').val(),
158+
var countryId = $('select[name="country_id"]:visible').val(),
155159
validationResult,
156160
warnMessage;
157161

0 commit comments

Comments
 (0)