Skip to content

Commit d81d1d4

Browse files
author
Vaha
committed
added product list price modifier to modify price attributes data to price format
1 parent 047f5b9 commit d81d1d4

15 files changed

+359
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertAdminProductGridCellActionGroup">
12+
<annotations>
13+
<description>Checks value for Admin Product Grid cell by provided row and column.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="row" type="string" defaultValue="1"/>
17+
<argument name="column" type="string" defaultValue="Name"/>
18+
<argument name="value" type="string" defaultValue="1"/>
19+
</arguments>
20+
21+
<see selector="{{AdminProductGridSection.productGridCell(row,column)}}" userInput="{{value}}" stepKey="seeProductGridCellWithProvidedValue"/>
22+
</actionGroup>
23+
</actionGroups>
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="CheckAdminProductGridColumnOptionActionGroup">
12+
<annotations>
13+
<description>Checks Admin Product Grid 'Columns' option.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="optionName" type="string" defaultValue="Name"/>
17+
</arguments>
18+
19+
<checkOption selector="{{AdminProductGridFilterSection.viewColumnOption(optionName)}}" stepKey="checkColumn"/>
20+
</actionGroup>
21+
</actionGroups>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="ClearFiltersAdminProductGridActionGroup">
12+
<annotations>
13+
<description>Clicks on 'Clear Filters'.</description>
14+
</annotations>
15+
16+
<conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFilters"/>
17+
<waitForPageLoad stepKey="waitForGridLoad"/>
18+
</actionGroup>
19+
</actionGroups>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="ResetAdminProductGridColumnsActionGroup">
12+
<annotations>
13+
<description>Clicks 'reset' for Admin Product Grid 'Columns' dropdown.</description>
14+
</annotations>
15+
16+
<click selector="{{AdminProductGridFilterSection.resetGridColumns}}" stepKey="resetProductGridColumns"/>
17+
</actionGroup>
18+
</actionGroups>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="ToggleAdminProductGridColumnsDropdownActionGroup">
12+
<annotations>
13+
<description>Toggles Admin Product Grid 'Columns' dropdown.</description>
14+
</annotations>
15+
16+
<click selector="{{AdminProductGridFilterSection.columnsDropdown}}" stepKey="toggleColumnsDropdown"/>
17+
</actionGroup>
18+
</actionGroups>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
<data key="attribute_code">short_description</data>
3232
<data key="value" unique="suffix">API Product Short Description</data>
3333
</entity>
34+
<entity name="ApiProductSpecialPrice" type="custom_attribute">
35+
<data key="attribute_code">special_price</data>
36+
<data key="value">51.51</data>
37+
</entity>
38+
<entity name="ApiProductCost" type="custom_attribute">
39+
<data key="attribute_code">cost</data>
40+
<data key="value">50.05</data>
41+
</entity>
3442
<entity name="ApiProductNewsFromDate" type="custom_attribute">
3543
<data key="attribute_code">news_from_date</data>
3644
<data key="value">2018-05-17 00:00:00</data>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@
175175
<data key="status">1</data>
176176
<data key="quantity">0</data>
177177
</entity>
178+
<entity name="SimpleOutOfStockProductWithSpecialPriceAndCost" type="product" extends="SimpleOutOfStockProduct">
179+
<requiredEntity type="custom_attribute_array">ApiProductSpecialPrice</requiredEntity>
180+
<requiredEntity type="custom_attribute_array">ApiProductCost</requiredEntity>
181+
</entity>
178182
<entity name="SimpleProductInStockQuantityZero" type="product">
179183
<data key="name" unique="suffix">SimpleProductInStockQuantityZero</data>
180184
<data key="sku" unique="suffix">testSku</data>

app/code/Magento/Catalog/Test/Mftf/Section/AdminProductGridSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<element name="firstProductRowEditButton" type="button" selector="table.data-grid tr.data-row td .action-menu-item:first-of-type"/>
2222
<element name="productThumbnail" type="text" selector="table.data-grid tr:nth-child({{row}}) td.data-grid-thumbnail-cell > img" parameterized="true"/>
2323
<element name="productThumbnailBySrc" type="text" selector="img.admin__control-thumbnail[src*='{{pattern}}']" parameterized="true"/>
24-
<element name="productGridCell" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., '{{column}}')]/preceding-sibling::th) +1 ]" parameterized="true"/>
24+
<element name="productGridCell" type="text" selector="//tr[{{row}}]//td[count(//div[@data-role='grid-wrapper']//tr//th[normalize-space(.)='{{column}}']/preceding-sibling::th) +1 ]" parameterized="true"/>
2525
<element name="productGridHeaderCell" type="text" selector="//div[@data-role='grid-wrapper']//tr//th[contains(., '{{column}}')]" parameterized="true"/>
2626
<element name="multicheckDropdown" type="button" selector="div[data-role='grid-wrapper'] th.data-grid-multicheck-cell button.action-multicheck-toggle"/>
2727
<element name="multicheckOption" type="button" selector="//div[@data-role='grid-wrapper']//th[contains(@class, data-grid-multicheck-cell)]//li//span[text() = '{{label}}']" parameterized="true"/>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminCheckProductListPriceAttributesTest">
12+
<annotations>
13+
<stories value="Check price attributes values on Admin Product List"/>
14+
<title value="Check price attributes values on Admin Product List."/>
15+
<description value="Login as admin, create simple product, add cost, special price. Go to Admin
16+
Product List page filter grid by created product, add mentioned columns to grid, check values."/>
17+
<group value="catalog"/>
18+
</annotations>
19+
<before>
20+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginToAdminPanel"/>
21+
<createData entity="SimpleOutOfStockProductWithSpecialPriceAndCost" stepKey="createSimpleProduct"/>
22+
23+
<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="adminOpenProductIndexPage"/>
24+
<actionGroup ref="FilterProductGridBySkuActionGroup" stepKey="filterProductGridByCreatedSimpleProductSku">
25+
<argument name="product" value="$$createSimpleProduct$$"/>
26+
</actionGroup>
27+
</before>
28+
<after>
29+
<actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="clearFiltersAdminProductGrid"/>
30+
<actionGroup ref="ToggleAdminProductGridColumnsDropdownActionGroup" stepKey="openToResetColumnsDropdown"/>
31+
<actionGroup ref="ResetAdminProductGridColumnsActionGroup" stepKey="resetAdminProductGridColumns"/>
32+
33+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
34+
<actionGroup ref="logout" stepKey="logout"/>
35+
<!-- Reindex invalidated indices after product attribute has been created/deleted -->
36+
<actionGroup ref="CliRunReindexUsingCronJobsActionGroup" stepKey="reindexInvalidatedIndices"/>
37+
</after>
38+
39+
<actionGroup ref="ToggleAdminProductGridColumnsDropdownActionGroup" stepKey="openColumnsDropdown"/>
40+
<actionGroup ref="CheckAdminProductGridColumnOptionActionGroup" stepKey="checkSpecialPriceOption">
41+
<argument name="optionName" value="Special Price"/>
42+
</actionGroup>
43+
<actionGroup ref="CheckAdminProductGridColumnOptionActionGroup" stepKey="checkCostOption">
44+
<argument name="optionName" value="Cost"/>
45+
</actionGroup>
46+
<actionGroup ref="ToggleAdminProductGridColumnsDropdownActionGroup" stepKey="closeColumnsDropdown"/>
47+
48+
<actionGroup ref="AssertAdminProductGridCellActionGroup" stepKey="seePrice">
49+
<argument name="row" value="1"/>
50+
<argument name="column" value="Price"/>
51+
<argument name="value" value="${{SimpleOutOfStockProduct.price}}"/>
52+
</actionGroup>
53+
<actionGroup ref="AssertAdminProductGridCellActionGroup" stepKey="seeCorrectSpecialPrice">
54+
<argument name="row" value="1"/>
55+
<argument name="column" value="Special Price"/>
56+
<argument name="value" value="${{ApiProductSpecialPrice.value}}"/>
57+
</actionGroup>
58+
<actionGroup ref="AssertAdminProductGridCellActionGroup" stepKey="seeCorrectCost">
59+
<argument name="row" value="1"/>
60+
<argument name="column" value="Cost"/>
61+
<argument name="value" value="${{ApiProductCost.value}}"/>
62+
</actionGroup>
63+
</test>
64+
</tests>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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\Catalog\Ui\DataProvider\Product\Modifier;
9+
10+
use Magento\Framework\Currency;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\Locale\CurrencyInterface;
13+
use Magento\Store\Api\Data\StoreInterface;
14+
use Magento\Store\Model\StoreManagerInterface;
15+
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
16+
17+
/**
18+
* Modify product listing price attributes
19+
*/
20+
class PriceAttributes implements ModifierInterface
21+
{
22+
/**
23+
* @var array
24+
*/
25+
private $priceAttributeList;
26+
27+
/**
28+
* @var StoreManagerInterface
29+
*/
30+
private $storeManager;
31+
32+
/**
33+
* @var CurrencyInterface
34+
*/
35+
private $localeCurrency;
36+
37+
/**
38+
* PriceAttributes constructor.
39+
*
40+
* @param StoreManagerInterface $storeManager
41+
* @param CurrencyInterface $localeCurrency
42+
* @param array $priceAttributeList
43+
*/
44+
public function __construct(
45+
StoreManagerInterface $storeManager,
46+
CurrencyInterface $localeCurrency,
47+
array $priceAttributeList = []
48+
) {
49+
$this->storeManager = $storeManager;
50+
$this->localeCurrency = $localeCurrency;
51+
$this->priceAttributeList = $priceAttributeList;
52+
}
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
public function modifyData(array $data): array
58+
{
59+
if (empty($data) || empty($this->priceAttributeList)) {
60+
return $data;
61+
}
62+
63+
foreach ($data['items'] as &$item) {
64+
foreach ($this->priceAttributeList as $priceAttribute) {
65+
if (isset($item[$priceAttribute])) {
66+
$item[$priceAttribute] = $this->getCurrency()->toCurrency(sprintf("%f", $item[$priceAttribute]));
67+
}
68+
}
69+
}
70+
71+
return $data;
72+
}
73+
74+
/**
75+
* @inheritdoc
76+
*/
77+
public function modifyMeta(array $meta): array
78+
{
79+
return $meta;
80+
}
81+
82+
/**
83+
* Retrieve store
84+
*
85+
* @return StoreInterface
86+
* @throws NoSuchEntityException
87+
*/
88+
private function getStore(): StoreInterface
89+
{
90+
return $this->storeManager->getStore();
91+
}
92+
93+
/**
94+
* Retrieve currency
95+
*
96+
* @return Currency
97+
* @throws NoSuchEntityException
98+
*/
99+
private function getCurrency(): Currency
100+
{
101+
$baseCurrencyCode = $this->getStore()->getBaseCurrencyCode();
102+
103+
return $this->localeCurrency->getCurrency($baseCurrencyCode);
104+
}
105+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@
177177
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Modifier\Attributes</item>
178178
<item name="sortOrder" xsi:type="number">10</item>
179179
</item>
180+
<item name="priceAttributes" xsi:type="array">
181+
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Modifier\PriceAttributes</item>
182+
<item name="sortOrder" xsi:type="number">10</item>
183+
</item>
180184
</argument>
181185
</arguments>
182186
</virtualType>
@@ -188,6 +192,14 @@
188192
</argument>
189193
</arguments>
190194
</type>
195+
<type name="Magento\Catalog\Ui\DataProvider\Product\Modifier\PriceAttributes">
196+
<arguments>
197+
<argument name="priceAttributeList" xsi:type="array">
198+
<item name="cost" xsi:type="string">cost</item>
199+
<item name="special_price" xsi:type="string">special_price</item>
200+
</argument>
201+
</arguments>
202+
</type>
191203
<type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\CustomOptions">
192204
<arguments>
193205
<argument name="scopeName" xsi:type="string">product_form.product_form</argument>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
10+
<entity name="ApiProductMsrp" type="custom_attribute">
11+
<data key="attribute_code">msrp</data>
12+
<data key="value">111.11</data>
13+
</entity>
14+
</entities>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="SimpleOutOfStockProductWithSpecialPriceCostAndMsrp" type="product" extends="SimpleOutOfStockProduct">
12+
<requiredEntity type="custom_attribute_array">ApiProductSpecialPrice</requiredEntity>
13+
<requiredEntity type="custom_attribute_array">ApiProductCost</requiredEntity>
14+
<requiredEntity type="custom_attribute_array">ApiProductMsrp</requiredEntity>
15+
</entity>
16+
</entities>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminCheckProductListPriceAttributesTest">
12+
<annotations>
13+
<group value="msrp"/>
14+
</annotations>
15+
<before>
16+
<createData entity="SimpleOutOfStockProductWithSpecialPriceCostAndMsrp" stepKey="createSimpleProduct"/>
17+
</before>
18+
19+
<actionGroup ref="CheckAdminProductGridColumnOptionActionGroup" stepKey="checkMsrpOption" after="checkCostOption">
20+
<argument name="optionName" value="Minimum Advertised Price"/>
21+
</actionGroup>
22+
23+
<actionGroup ref="AssertAdminProductGridCellActionGroup" stepKey="seeCorrectMsrp" after="seeCorrectCost">
24+
<argument name="row" value="1"/>
25+
<argument name="column" value="Minimum Advertised Price"/>
26+
<argument name="value" value="${{ApiProductMsrp.value}}"/>
27+
</actionGroup>
28+
</test>
29+
</tests>

0 commit comments

Comments
 (0)