Skip to content

Commit 967115f

Browse files
authored
ENGCOM-6925: Removed disabled products from low stock report grid #26862
2 parents 177e972 + bc2eedf commit 967115f

File tree

4 files changed

+94
-9
lines changed

4 files changed

+94
-9
lines changed

app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@
212212
<data key="quantity">1001</data>
213213
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
214214
</entity>
215+
<entity name="SimpleProductDisabledStockQuantityZero" type="product">
216+
<data key="sku" unique="suffix">testSku</data>
217+
<data key="type_id">simple</data>
218+
<data key="attribute_set_id">4</data>
219+
<data key="name" unique="suffix">Simple Product Disabled Quantity Zero</data>
220+
<data key="price">123.00</data>
221+
<data key="visibility">4</data>
222+
<data key="status">2</data>
223+
<data key="quantity">0</data>
224+
<requiredEntity type="product_extension_attribute">EavStock0</requiredEntity>
225+
</entity>
215226
<entity name="SimpleProductNotVisibleIndividually" type="product">
216227
<data key="name" unique="suffix">Simple Product Not Visible Individually</data>
217228
<data key="sku" unique="suffix">simple_product_not_visible_individually</data>

app/code/Magento/Reports/Block/Adminhtml/Product/Lowstock/Grid.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Reports\Block\Adminhtml\Product\Lowstock;
79

10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Backend\Helper\Data;
12+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
13+
use Magento\Framework\Data\Collection as DataCollection;
14+
use Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection;
15+
use Magento\Reports\Model\ResourceModel\Product\Lowstock\CollectionFactory;
16+
817
/**
918
* Adminhtml low stock products report grid block
1019
*
@@ -15,27 +24,29 @@
1524
class Grid extends \Magento\Backend\Block\Widget\Grid
1625
{
1726
/**
18-
* @var \Magento\Reports\Model\ResourceModel\Product\Lowstock\CollectionFactory
27+
* @var CollectionFactory
1928
*/
2029
protected $_lowstocksFactory;
2130

2231
/**
23-
* @param \Magento\Backend\Block\Template\Context $context
24-
* @param \Magento\Backend\Helper\Data $backendHelper
25-
* @param \Magento\Reports\Model\ResourceModel\Product\Lowstock\CollectionFactory $lowstocksFactory
32+
* @param Context $context
33+
* @param Data $backendHelper
34+
* @param CollectionFactory $lowstocksFactory
2635
* @param array $data
2736
*/
2837
public function __construct(
29-
\Magento\Backend\Block\Template\Context $context,
30-
\Magento\Backend\Helper\Data $backendHelper,
31-
\Magento\Reports\Model\ResourceModel\Product\Lowstock\CollectionFactory $lowstocksFactory,
38+
Context $context,
39+
Data $backendHelper,
40+
CollectionFactory $lowstocksFactory,
3241
array $data = []
3342
) {
3443
$this->_lowstocksFactory = $lowstocksFactory;
3544
parent::__construct($context, $backendHelper, $data);
3645
}
3746

3847
/**
48+
* @inheritDoc
49+
*
3950
* @return \Magento\Backend\Block\Widget\Grid
4051
*/
4152
protected function _prepareCollection()
@@ -56,7 +67,7 @@ protected function _prepareCollection()
5667
$storeId = null;
5768
}
5869

59-
/** @var $collection \Magento\Reports\Model\ResourceModel\Product\Lowstock\Collection */
70+
/** @var $collection Collection */
6071
$collection = $this->_lowstocksFactory->create()->addAttributeToSelect(
6172
'*'
6273
)->filterByIsQtyProductTypes()->joinInventoryItem(
@@ -67,7 +78,10 @@ protected function _prepareCollection()
6778
$storeId
6879
)->setOrder(
6980
'qty',
70-
\Magento\Framework\Data\Collection::SORT_ORDER_ASC
81+
DataCollection::SORT_ORDER_ASC
82+
)->addAttributeToFilter(
83+
'status',
84+
Status::STATUS_ENABLED
7185
);
7286

7387
if ($storeId) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminLowStockReportFilterProductActionGroup">
11+
<annotations>
12+
<description>Filter in "Low Stock" report with by product SKU.</description>
13+
</annotations>
14+
<arguments>
15+
<argument name="sku" type="string" defaultValue="{{_defaultProduct.sku}}"/>
16+
</arguments>
17+
18+
<fillField selector="{{LowStockReportFilterSection.productSku}}" userInput="{{sku}}" stepKey="fillSkuFilterField" />
19+
<click selector="{{LowStockReportFilterSection.searchButton}}" stepKey="clickSearch"/>
20+
</actionGroup>
21+
</actionGroups>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminReportsLowStockDisableProductTest">
11+
<annotations>
12+
<features value="Reports"/>
13+
<group value="reports"/>
14+
<title value="The disabled product doesn't present on 'Low Stock' report."/>
15+
<description value="A product must don't presents on 'Low Stock' report if the product is disabled."/>
16+
</annotations>
17+
<before>
18+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
19+
20+
<!-- Created disabled simple product with stock quantity zero -->
21+
<createData entity="SimpleProductDisabledStockQuantityZero" stepKey="createProduct"/>
22+
</before>
23+
<after>
24+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
25+
<actionGroup ref="logout" stepKey="logout"/>
26+
</after>
27+
28+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToReportsLowStockPage">
29+
<argument name="menuUiId" value="{{AdminMenuReports.dataUiId}}"/>
30+
<argument name="submenuUiId" value="{{AdminMenuReportsProductsLowStock.dataUiId}}"/>
31+
</actionGroup>
32+
<actionGroup ref="AdminLowStockReportFilterProductActionGroup" stepKey="assertProductInReport">
33+
<argument name="sku" value="{{SimpleProductDisabledStockQuantityZero.sku}}"/>
34+
</actionGroup>
35+
36+
<!-- Verify doesn't present in the report -->
37+
<dontSeeElement selector="{{LowStockProductGridSection.productSku}}" stepKey="assertSelector"/>
38+
</test>
39+
</tests>

0 commit comments

Comments
 (0)