Skip to content

Commit c86a881

Browse files
author
Stanislav Idolov
authored
Merge pull request magento#3139 from arnobsh/MC-33760
MC-33760: Low Stock Report Export Error in Magento2.3.4
2 parents 5884f25 + ab7ea7b commit c86a881

File tree

6 files changed

+130
-34
lines changed

6 files changed

+130
-34
lines changed

InventoryAdminUi/Test/Mftf/Data/CatalogInventoryConfigData.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@
9090
<data key="path">cataloginventory/item_options/min_qty</data>
9191
<data key="value">0</data>
9292
</entity>
93+
<entity name="NotifyQuantityBelowOne">
94+
<data key="path">cataloginventory/item_options/notify_stock_qty</data>
95+
<data key="value">1</data>
96+
</entity>
9397
<entity name="NotifyQuantityBelow">
9498
<data key="path">cataloginventory/item_options/notify_stock_qty</data>
9599
<data key="value">5</data>

InventoryAdminUi/Test/Mftf/Test/AdminLowStockReportForSimpleProductWithDefaultStockAndZeroQuantityTest.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@
2525
<createData entity="SimpleProduct" stepKey="product">
2626
<requiredEntity createDataKey="category"/>
2727
</createData>
28+
<!--Enable Manage Stock in case it's been disabled in previous tests.-->
29+
<magentoCLI command="config:set {{TurnOnManageStockConfig.path}} {{TurnOnManageStockConfig.value}}" stepKey="enableManageStock"/>
30+
<!--Set "Notify Quantity Below" configuration.-->
31+
<magentoCLI command="config:set {{NotifyQuantityBelowOne.path}} {{NotifyQuantityBelowOne.value}}" stepKey="setNotifyQuantityBelow"/>
2832
<actionGroup ref="LoginAsAdmin" stepKey="loginToAdminArea"/>
2933
</before>
3034
<after>
35+
<!--Disable "Manage Stock" in configuration.-->
36+
<magentoCLI command="config:set {{TurnOffManageStockConfig.path}} {{TurnOnManageStockConfig.value}}" stepKey="disableManageStock"/>
37+
<!--Revert "Notify Quantity Below" configuration.-->
38+
<magentoCLI command="config:set {{RevertNotifyQuantityBelow.path}} {{RevertNotifyQuantityBelow.value}}" stepKey="revertNotifyQtyBelow"/>
3139
<actionGroup ref="logout" stepKey="logoutFromAdminArea"/>
3240
<deleteData createDataKey="category" stepKey="deleteCategory"/>
3341
<deleteData createDataKey="product" stepKey="deleteProduct"/>
Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
declare(strict_types=1);
8-
97
namespace Magento\InventoryLowQuantityNotificationAdminUi\Controller\Adminhtml\Report;
108

11-
use Magento\Framework\App\ResponseInterface;
9+
use Exception;
10+
use Magento\Framework\App\Action\HttpGetActionInterface;
1211
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\App\ResponseInterface;
13+
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Reports\Controller\Adminhtml\Report\Product as ProductReportController;
1415

15-
class ExportLowstockCsv extends ProductReportController
16+
/**
17+
* Export low stock products in CSV format
18+
*/
19+
class ExportLowstockCsv extends ProductReportController implements HttpGetActionInterface
1620
{
1721
/**
1822
* Authorization level of a basic admin session
@@ -25,21 +29,24 @@ class ExportLowstockCsv extends ProductReportController
2529
* Export low stock products report to CSV format
2630
*
2731
* @return ResponseInterface
32+
* @throws \Exception
2833
*/
2934
public function execute()
3035
{
31-
$this->_view->loadLayout(false);
32-
$fileName = 'products_lowstock.csv';
33-
34-
$exportBlock = $this->_view->getLayout()->getChildBlock(
35-
'adminhtml.block.report.product.inventory.lowstock.grid',
36-
'grid.export'
37-
);
38-
39-
return $this->_fileFactory->create(
40-
$fileName,
41-
$exportBlock->getCsvFile(),
42-
DirectoryList::VAR_DIR
43-
);
36+
try {
37+
$this->_view->loadLayout('reports_report_product_lowstock');
38+
$fileName = 'products_lowstock.csv';
39+
$exportBlock = $this->_view->getLayout()->getChildBlock(
40+
'adminhtml.block.report.product.inventory.lowstock.grid',
41+
'grid.export'
42+
);
43+
return $this->_fileFactory->create(
44+
$fileName,
45+
$exportBlock->getCsvFile(),
46+
DirectoryList::VAR_DIR
47+
);
48+
} catch (Exception $e) {
49+
throw new LocalizedException(__('Could not export low stock report'), $e);
50+
}
4451
}
4552
}
Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
declare(strict_types=1);
8-
97
namespace Magento\InventoryLowQuantityNotificationAdminUi\Controller\Adminhtml\Report;
108

11-
use Magento\Framework\App\ResponseInterface;
9+
use Exception;
10+
use Magento\Framework\App\Action\HttpGetActionInterface;
1211
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\App\ResponseInterface;
13+
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Reports\Controller\Adminhtml\Report\Product as ProductReportController;
1415

15-
class ExportLowstockExcel extends ProductReportController
16+
/**
17+
* Export low stock products in Excel format
18+
*/
19+
class ExportLowstockExcel extends ProductReportController implements HttpGetActionInterface
1620
{
1721
/**
1822
* Authorization level of a basic admin session
@@ -25,21 +29,24 @@ class ExportLowstockExcel extends ProductReportController
2529
* Export low stock products report to XML format
2630
*
2731
* @return ResponseInterface
32+
* @throws Exception
2833
*/
2934
public function execute()
3035
{
31-
$this->_view->loadLayout(false);
32-
$fileName = 'products_lowstock.xml';
33-
34-
$exportBlock = $this->_view->getLayout()->getChildBlock(
35-
'adminhtml.block.report.product.inventory.lowstock.grid',
36-
'grid.export'
37-
);
38-
39-
return $this->_fileFactory->create(
40-
$fileName,
41-
$exportBlock->getExcelFile(),
42-
DirectoryList::VAR_DIR
43-
);
36+
try {
37+
$this->_view->loadLayout('reports_report_product_lowstock');
38+
$fileName = 'products_lowstock.xml';
39+
$exportBlock = $this->_view->getLayout()->getChildBlock(
40+
'adminhtml.block.report.product.inventory.lowstock.grid',
41+
'grid.export'
42+
);
43+
return $this->_fileFactory->create(
44+
$fileName,
45+
$exportBlock->getExcelFile(),
46+
DirectoryList::VAR_DIR
47+
);
48+
} catch (Exception $e) {
49+
throw new LocalizedException(__('Could not export low stock report'), $e);
50+
}
4451
}
4552
}

InventoryLowQuantityNotificationAdminUi/Test/Mftf/Section/LowStockProductGridSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="LowStockProductGridSection">
1212
<element name="productSourceCode" type="input" selector="//tr[1]/td[@data-column='sourceCode']"/>
13+
<element name="exportButton" type="button" selector="//button[@title='Export']"/>
1314
</section>
1415
</sections>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminLowStockReportExportVerificationTest">
11+
<annotations>
12+
<stories value="Low Stock Report Export Error"/>
13+
<title value="Low Stock Report Export Error"/>
14+
<description value="Verify Low Stock Report Export Error"/>
15+
<testCaseId value="MC-33760"/>
16+
<severity value="MAJOR"/>
17+
<group value="msi"/>
18+
<group value="multi_mode"/>
19+
</annotations>
20+
<before>
21+
<!--Create category and product.-->
22+
<createData entity="SimpleSubCategory" stepKey="category"/>
23+
<createData entity="SimpleProduct" stepKey="firstProduct">
24+
<field key="status">1</field>
25+
<requiredEntity createDataKey="category"/>
26+
</createData>
27+
<!--Enable Manage Stock in case it's been disabled in previous tests.-->
28+
<magentoCLI command="config:set {{TurnOnManageStockConfig.path}} {{TurnOnManageStockConfig.value}}" stepKey="enableManageStock"/>
29+
<!--Set "Notify Quantity Below" configuration.-->
30+
<magentoCLI command="config:set {{NotifyQuantityBelow.path}} {{NotifyQuantityBelow.value}}" stepKey="setNotifyQuantityBelow"/>
31+
<actionGroup ref="LoginAsAdmin" stepKey="loginToAdminArea"/>
32+
</before>
33+
<after>
34+
<deleteData createDataKey="firstProduct" stepKey="deleteFirstProduct"/>
35+
<deleteData createDataKey="category" stepKey="deleteCategory"/>
36+
<!--Revert "Notify Quantity Below" configuration.-->
37+
<magentoCLI command="config:set {{RevertNotifyQuantityBelow.path}} {{RevertNotifyQuantityBelow.value}}" stepKey="revertNotifyQtyBelow"/>
38+
<!--Disable "Manage Stock" in configuration.-->
39+
<magentoCLI command="config:set {{TurnOffManageStockConfig.path}} {{TurnOnManageStockConfig.value}}" stepKey="disableManageStock"/>
40+
<actionGroup ref="logout" stepKey="logoutFromAdminArea"/>
41+
</after>
42+
43+
<!--Disable additional sources.-->
44+
<actionGroup ref="DisableAllSourcesActionGroup" stepKey="disableAllSources"/>
45+
<!--Set first product qty to 4.-->
46+
<amOnPage url="{{AdminProductEditPage.url($$firstProduct.id$$)}}" stepKey="openFirstProductEditPageToChangeQty4"/>
47+
<fillField selector="{{AdminProductFormSection.productQuantity}}" userInput="4" stepKey="fillFirstProductQtyWith4"/>
48+
<selectOption selector="{{AdminProductFormSection.productStockStatus}}" userInput="In Stock" stepKey="selectFirstProductInStockStatus"/>
49+
<actionGroup ref="AdminFormSaveAndClose" stepKey="saveFirstProductWithChangedQuantity"/>
50+
<waitForPageLoad time="60" stepKey="waitForFirstProductSave"/>
51+
52+
<!--Verify report is available with in stock product.-->
53+
<amOnPage url="{{LowStockReportPage.url}}" stepKey="navigateToLowStockReportPage"/>
54+
<click selector="{{LowStockProductGridSection.exportButton}}" stepKey="exportCSV"/>
55+
<waitForPageLoad time="30" stepKey="waitForExport"/>
56+
<dontSee userInput="Could not export low stock report" stepKey="verifyThereIsNoError"/>
57+
58+
<!--Verify there are no errors and we can see the product after export has been done.-->
59+
<actionGroup ref="AdminSearchLowStockReportByProductSkuAndSourceCodeActionGroup" stepKey="searchFirstProduct">
60+
<argument name="productSku" value="$$firstProduct.sku$$"/>
61+
<argument name="sourceCode" value="{{_defaultSource.source_code}}"/>
62+
</actionGroup>
63+
<actionGroup ref="AdminVerifyLowStockProductReportActionGroup" stepKey="verifyFirstProductInReport">
64+
<argument name="product" value="$$firstProduct$$"/>
65+
<argument name="productQty" value="4"/>
66+
<argument name="source" value="_defaultSource"/>
67+
</actionGroup>
68+
</test>
69+
</tests>

0 commit comments

Comments
 (0)