Skip to content

Commit f726dac

Browse files
author
Alexander Akimov
authored
Merge pull request #2133 from magento-tsg/2.2-develop-pr20
[TSG] Backporting for 2.2 (pr20) (2.2.4)
2 parents 6f188ab + a9150c8 commit f726dac

File tree

20 files changed

+925
-76
lines changed

20 files changed

+925
-76
lines changed

app/code/Magento/Backend/Model/Url.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,33 +202,30 @@ public function getUrl($routePath = null, $routeParams = null)
202202
}
203203

204204
$cacheSecretKey = false;
205-
if (is_array($routeParams) && isset($routeParams['_cache_secret_key'])) {
205+
if (isset($routeParams['_cache_secret_key'])) {
206206
unset($routeParams['_cache_secret_key']);
207207
$cacheSecretKey = true;
208208
}
209209
$result = parent::getUrl($routePath, $routeParams);
210210
if (!$this->useSecretKey()) {
211211
return $result;
212212
}
213+
213214
$this->_setRoutePath($routePath);
214215
$routeName = $this->_getRouteName('*');
215216
$controllerName = $this->_getControllerName(self::DEFAULT_CONTROLLER_NAME);
216217
$actionName = $this->_getActionName(self::DEFAULT_ACTION_NAME);
217-
if ($cacheSecretKey) {
218-
$secret = [self::SECRET_KEY_PARAM_NAME => "\${$routeName}/{$controllerName}/{$actionName}\$"];
219-
} else {
220-
$secret = [
221-
self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($routeName, $controllerName, $actionName),
222-
];
223-
}
224-
if (is_array($routeParams)) {
225-
$routeParams = array_merge($secret, $routeParams);
226-
} else {
227-
$routeParams = $secret;
228-
}
229-
if (is_array($this->_getRouteParams())) {
230-
$routeParams = array_merge($this->_getRouteParams(), $routeParams);
218+
219+
if (!isset($routeParams[self::SECRET_KEY_PARAM_NAME])) {
220+
if (!is_array($routeParams)) {
221+
$routeParams = [];
222+
}
223+
$secretKey = $cacheSecretKey
224+
? "\${$routeName}/{$controllerName}/{$actionName}\$"
225+
: $this->getSecretKey($routeName, $controllerName, $actionName);
226+
$routeParams[self::SECRET_KEY_PARAM_NAME] = $secretKey;
231227
}
228+
232229
return parent::getUrl("{$routeName}/{$controllerName}/{$actionName}", $routeParams);
233230
}
234231

app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public function testGetCustomAttributes()
426426
$this->assertEquals("description", $this->category->getCustomAttribute($descriptionAttributeCode)->getValue());
427427

428428
//Change the attribute value, should reflect in getCustomAttribute
429-
$this->category->setData($descriptionAttributeCode, "new description");
429+
$this->category->setCustomAttribute($descriptionAttributeCode, "new description");
430430
$this->assertEquals(1, count($this->category->getCustomAttributes()));
431431
$this->assertNotNull($this->category->getCustomAttribute($descriptionAttributeCode));
432432
$this->assertEquals(

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ public function testGetCustomAttributes()
12981298
$this->assertEquals("red", $this->model->getCustomAttribute($colorAttributeCode)->getValue());
12991299

13001300
//Change the attribute value, should reflect in getCustomAttribute
1301-
$this->model->setData($colorAttributeCode, "blue");
1301+
$this->model->setCustomAttribute($colorAttributeCode, "blue");
13021302
$this->assertEquals(1, count($this->model->getCustomAttributes()));
13031303
$this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode));
13041304
$this->assertEquals("blue", $this->model->getCustomAttribute($colorAttributeCode)->getValue());

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ protected function _saveProducts()
16661666
$storeId = !empty($rowData[self::COL_STORE])
16671667
? $this->getStoreIdByCode($rowData[self::COL_STORE])
16681668
: Store::DEFAULT_STORE_ID;
1669-
if (isset($rowData['_media_is_disabled'])) {
1669+
if (isset($rowData['_media_is_disabled']) && strlen(trim($rowData['_media_is_disabled']))) {
16701670
$disabledImages = array_flip(
16711671
explode($this->getMultipleValueSeparator(), $rowData['_media_is_disabled'])
16721672
);

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public function prepareAttributesWithDefaultValueForSave(array $rowData, $withDe
503503
if ($attrParams['is_static']) {
504504
continue;
505505
}
506-
if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
506+
if (isset($rowData[$attrCode]) && strlen(trim($rowData[$attrCode]))) {
507507
if (in_array($attrParams['type'], ['select', 'boolean'])) {
508508
$resultAttrs[$attrCode] = $attrParams['options'][strtolower($rowData[$attrCode])];
509509
} elseif ('multiselect' == $attrParams['type']) {

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,20 @@ protected function _construct()
113113
}
114114

115115
/**
116-
* Lock Stock Item records
116+
* Lock Stock Item records.
117117
*
118118
* @param int[] $productIds
119119
* @param int $websiteId
120120
* @return array
121121
*/
122-
public function lockProductsStock($productIds, $websiteId)
122+
public function lockProductsStock(array $productIds, $websiteId)
123123
{
124124
if (empty($productIds)) {
125125
return [];
126126
}
127127
$itemTable = $this->getTable('cataloginventory_stock_item');
128128
$select = $this->getConnection()->select()->from(['si' => $itemTable])
129-
->where('website_id=?', $websiteId)
129+
->where('website_id = ?', $websiteId)
130130
->where('product_id IN(?)', $productIds)
131131
->forUpdate(true);
132132

@@ -136,12 +136,19 @@ public function lockProductsStock($productIds, $websiteId)
136136
->columns(
137137
[
138138
'product_id' => 'entity_id',
139-
'type_id' => 'type_id'
139+
'type_id' => 'type_id',
140140
]
141141
);
142-
$this->getConnection()->query($select);
142+
$items = [];
143143

144-
return $this->getConnection()->fetchAll($selectProducts);
144+
foreach ($this->getConnection()->query($select)->fetchAll() as $si) {
145+
$items[$si['product_id']] = $si;
146+
}
147+
foreach ($this->getConnection()->fetchAll($selectProducts) as $p) {
148+
$items[$p['product_id']]['type_id'] = $p['type_id'];
149+
}
150+
151+
return $items;
145152
}
146153

147154
/**

app/code/Magento/CatalogInventory/Model/StockManagement.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,42 @@ class StockManagement implements StockManagementInterface
4848
*/
4949
private $qtyCounter;
5050

51+
/**
52+
* @var StockRegistryStorage
53+
*/
54+
private $stockRegistryStorage;
55+
5156
/**
5257
* @param ResourceStock $stockResource
5358
* @param StockRegistryProviderInterface $stockRegistryProvider
5459
* @param StockState $stockState
5560
* @param StockConfigurationInterface $stockConfiguration
5661
* @param ProductRepositoryInterface $productRepository
5762
* @param QtyCounterInterface $qtyCounter
63+
* @param StockRegistryStorage|null $stockRegistryStorage
5864
*/
5965
public function __construct(
6066
ResourceStock $stockResource,
6167
StockRegistryProviderInterface $stockRegistryProvider,
6268
StockState $stockState,
6369
StockConfigurationInterface $stockConfiguration,
6470
ProductRepositoryInterface $productRepository,
65-
QtyCounterInterface $qtyCounter
71+
QtyCounterInterface $qtyCounter,
72+
StockRegistryStorage $stockRegistryStorage = null
6673
) {
6774
$this->stockRegistryProvider = $stockRegistryProvider;
6875
$this->stockState = $stockState;
6976
$this->stockConfiguration = $stockConfiguration;
7077
$this->productRepository = $productRepository;
7178
$this->qtyCounter = $qtyCounter;
7279
$this->resource = $stockResource;
80+
$this->stockRegistryStorage = $stockRegistryStorage ?: \Magento\Framework\App\ObjectManager::getInstance()
81+
->get(StockRegistryStorage::class);
7382
}
7483

7584
/**
7685
* Subtract product qtys from stock.
77-
* Return array of items that require full save
86+
* Return array of items that require full save.
7887
*
7988
* @param string[] $items
8089
* @param int $websiteId
@@ -92,17 +101,20 @@ public function registerProductsSale($items, $websiteId = null)
92101
$fullSaveItems = $registeredItems = [];
93102
foreach ($lockedItems as $lockedItemRecord) {
94103
$productId = $lockedItemRecord['product_id'];
104+
$this->stockRegistryStorage->removeStockItem($productId, $websiteId);
105+
95106
/** @var StockItemInterface $stockItem */
96107
$orderedQty = $items[$productId];
97108
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId);
109+
$stockItem->setQty($lockedItemRecord['qty']); // update data from locked item
98110
$canSubtractQty = $stockItem->getItemId() && $this->canSubtractQty($stockItem);
99111
if (!$canSubtractQty || !$this->stockConfiguration->isQty($lockedItemRecord['type_id'])) {
100112
continue;
101113
}
102114
if (!$stockItem->hasAdminArea()
103115
&& !$this->stockState->checkQty($productId, $orderedQty, $stockItem->getWebsiteId())
104116
) {
105-
$this->getResource()->rollBack();
117+
$this->getResource()->commit();
106118
throw new \Magento\Framework\Exception\LocalizedException(
107119
__('Not all of your products are available in the requested quantity.')
108120
);
@@ -122,6 +134,7 @@ public function registerProductsSale($items, $websiteId = null)
122134
}
123135
$this->qtyCounter->correctItemsQty($registeredItems, $websiteId, '-');
124136
$this->getResource()->commit();
137+
125138
return $fullSaveItems;
126139
}
127140

0 commit comments

Comments
 (0)