Skip to content

Commit ed98984

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-92573' into 2.2-develop-pr30
2 parents f30a14c + 76a10b1 commit ed98984

File tree

36 files changed

+860
-252
lines changed

36 files changed

+860
-252
lines changed

app/code/Magento/Catalog/Controller/Product/Compare/Add.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ public function execute()
3636
$productName = $this->_objectManager->get(
3737
\Magento\Framework\Escaper::class
3838
)->escapeHtml($product->getName());
39-
$this->messageManager->addSuccess(__('You added product %1 to the comparison list.', $productName));
39+
$this->messageManager->addComplexSuccessMessage(
40+
'addCompareSuccessMessage',
41+
[
42+
'product_name' => $productName,
43+
'compare_list_url' => $this->_url->getUrl('catalog/product_compare')
44+
]
45+
);
46+
4047
$this->_eventManager->dispatch('catalog_product_compare_add_product', ['product' => $product]);
4148
}
4249

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ protected function prepareFinalPriceDataForType($entityIds, $type)
307307
$query = $select->insertFromSelect($finalPriceTable->getTableName(), [], false);
308308
$this->getConnection()->query($query);
309309

310-
$this->applyDiscountPrices($finalPriceTable);
310+
$this->modifyPriceIndex($finalPriceTable);
311311

312312
return $this;
313313
}
@@ -512,12 +512,12 @@ protected function _prepareCustomOptionPriceTable()
512512
}
513513

514514
/**
515-
* Apply discount prices to final price index table.
515+
* Modify data in price index table.
516516
*
517517
* @param IndexTableStructure $finalPriceTable
518518
* @return void
519519
*/
520-
private function applyDiscountPrices(IndexTableStructure $finalPriceTable)
520+
private function modifyPriceIndex(IndexTableStructure $finalPriceTable)
521521
{
522522
foreach ($this->priceModifiers as $priceModifier) {
523523
$priceModifier->modifyPrice($finalPriceTable);

app/code/Magento/Catalog/etc/frontend/di.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@
7979
<argument name="typeId" xsi:type="string">recently_compared_product</argument>
8080
</arguments>
8181
</virtualType>
82+
<type name="Magento\Framework\View\Element\Message\MessageConfigurationsPool">
83+
<arguments>
84+
<argument name="configurationsMap" xsi:type="array">
85+
<item name="addCompareSuccessMessage" xsi:type="array">
86+
<item name="renderer" xsi:type="const">\Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE</item>
87+
<item name="data" xsi:type="array">
88+
<item name="template" xsi:type="string">Magento_Catalog::messages/addCompareSuccessMessage.phtml</item>
89+
</item>
90+
</item>
91+
</argument>
92+
</arguments>
93+
</type>
8294
<type name="Magento\Framework\App\ResourceConnection">
8395
<plugin name="get_catalog_category_product_index_table_name" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver"/>
8496
</type>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
// @codingStandardsIgnoreFile
7+
/** @var \Magento\Framework\View\Element\Template $block */
8+
?>
9+
<?= $block->escapeHtml(__(
10+
'You added product %1 to the <a href="%2">comparison list</a>.',
11+
$block->getData('product_name'),
12+
$block->getData('compare_list_url')),
13+
['a']
14+
);

app/code/Magento/Catalog/view/frontend/web/js/storage-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ define([
129129
},
130130

131131
/**
132-
* Prepare storages congfig.
132+
* Prepare storages config.
133133
*
134134
* @returns {Object} Chainable.
135135
*/
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogInventory\Model\Indexer;
9+
10+
use Magento\CatalogInventory\Api\StockConfigurationInterface;
11+
use Magento\CatalogInventory\Model\ResourceModel\Stock\Item;
12+
use Magento\CatalogInventory\Model\Stock;
13+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\PriceModifierInterface;
14+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;
15+
16+
/**
17+
* Class for filter product price index.
18+
*/
19+
class ProductPriceIndexFilter implements PriceModifierInterface
20+
{
21+
/**
22+
* @var StockConfigurationInterface
23+
*/
24+
private $stockConfiguration;
25+
26+
/**
27+
* @var Item
28+
*/
29+
private $stockItem;
30+
31+
/**
32+
* @param StockConfigurationInterface $stockConfiguration
33+
* @param Item $stockItem
34+
*/
35+
public function __construct(StockConfigurationInterface $stockConfiguration, Item $stockItem)
36+
{
37+
$this->stockConfiguration = $stockConfiguration;
38+
$this->stockItem = $stockItem;
39+
}
40+
41+
/**
42+
* Remove out of stock products data from price index.
43+
*
44+
* @param IndexTableStructure $priceTable
45+
* @param array $entityIds
46+
* @return void
47+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
48+
*/
49+
public function modifyPrice(IndexTableStructure $priceTable, array $entityIds = [])
50+
{
51+
if ($this->stockConfiguration->isShowOutOfStock()) {
52+
return;
53+
}
54+
55+
$connection = $this->stockItem->getConnection();
56+
$select = $connection->select();
57+
$select->from(
58+
['price_index' => $priceTable->getTableName()],
59+
[]
60+
);
61+
$select->joinInner(
62+
['stock_item' => $this->stockItem->getMainTable()],
63+
'stock_item.product_id = price_index.' . $priceTable->getEntityField()
64+
. ' AND stock_item.stock_id = ' . Stock::DEFAULT_STOCK_ID,
65+
[]
66+
);
67+
if ($this->stockConfiguration->getManageStock()) {
68+
$stockStatus = $connection->getCheckSql(
69+
'use_config_manage_stock = 0 AND manage_stock = 0',
70+
Stock::STOCK_IN_STOCK,
71+
'is_in_stock'
72+
);
73+
} else {
74+
$stockStatus = $connection->getCheckSql(
75+
'use_config_manage_stock = 0 AND manage_stock = 1',
76+
'is_in_stock',
77+
Stock::STOCK_IN_STOCK
78+
);
79+
}
80+
$select->where($stockStatus . ' = ?', Stock::STOCK_OUT_OF_STOCK);
81+
82+
$query = $select->deleteFromSelect('price_index');
83+
$connection->query($query);
84+
}
85+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogInventory\Model\Plugin;
7+
8+
use Magento\CatalogInventory\Model\ResourceModel\Stock\Item;
9+
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
10+
use Magento\Framework\Model\AbstractModel;
11+
12+
/**
13+
* Update product price index after product stock status changed.
14+
*/
15+
class PriceIndexUpdater
16+
{
17+
/**
18+
* @var Processor
19+
*/
20+
private $priceIndexProcessor;
21+
22+
/**
23+
* @param Processor $priceIndexProcessor
24+
*/
25+
public function __construct(Processor $priceIndexProcessor)
26+
{
27+
$this->priceIndexProcessor = $priceIndexProcessor;
28+
}
29+
30+
/**
31+
* @param Item $subject
32+
* @param Item $result
33+
* @param AbstractModel $model
34+
* @return Item
35+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
36+
*/
37+
public function afterSave(Item $subject, Item $result, AbstractModel $model)
38+
{
39+
$fields = [
40+
'is_in_stock',
41+
'use_config_manage_stock',
42+
'manage_stock',
43+
];
44+
foreach ($fields as $field) {
45+
if ($model->dataHasChangedFor($field)) {
46+
$this->priceIndexProcessor->reindexRow($model->getProductId());
47+
break;
48+
}
49+
}
50+
51+
return $result;
52+
}
53+
54+
/**
55+
* @param Item $subject
56+
* @param $result
57+
* @param int $websiteId
58+
* @return void
59+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
60+
*/
61+
public function afterUpdateSetOutOfStock(Item $subject, $result, int $websiteId)
62+
{
63+
$this->priceIndexProcessor->markIndexerAsInvalid();
64+
}
65+
66+
/**
67+
* @param Item $subject
68+
* @param $result
69+
* @param int $websiteId
70+
* @return void
71+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
72+
*/
73+
public function afterUpdateSetInStock(Item $subject, $result, int $websiteId)
74+
{
75+
$this->priceIndexProcessor->markIndexerAsInvalid();
76+
}
77+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ protected function _initConfig()
206206
/**
207207
* Set items out of stock basing on their quantities and config settings
208208
*
209+
* @deprecated
210+
* @see \Magento\CatalogInventory\Model\ResourceModel\Stock\Item::updateSetOutOfStock
209211
* @param string|int $website
210212
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
211213
* @return void
@@ -241,6 +243,8 @@ public function updateSetOutOfStock($website = null)
241243
/**
242244
* Set items in stock basing on their quantities and config settings
243245
*
246+
* @deprecated
247+
* @see \Magento\CatalogInventory\Model\ResourceModel\Stock\Item::updateSetInStock
244248
* @param int|string $website
245249
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
246250
* @return void
@@ -274,6 +278,8 @@ public function updateSetInStock($website)
274278
/**
275279
* Update items low stock date basing on their quantities and config settings
276280
*
281+
* @deprecated
282+
* @see \Magento\CatalogInventory\Model\ResourceModel\Stock\Item::updateLowStockDate
277283
* @param int|string $website
278284
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
279285
* @return void

0 commit comments

Comments
 (0)