Skip to content

Commit

Permalink
added product list price modifier to modify price attributes data to …
Browse files Browse the repository at this point in the history
…price format
  • Loading branch information
Vaha committed Mar 12, 2020
1 parent 047f5b9 commit d81d1d4
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 1 deletion.
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AssertAdminProductGridCellActionGroup">
<annotations>
<description>Checks value for Admin Product Grid cell by provided row and column.</description>
</annotations>
<arguments>
<argument name="row" type="string" defaultValue="1"/>
<argument name="column" type="string" defaultValue="Name"/>
<argument name="value" type="string" defaultValue="1"/>
</arguments>

<see selector="{{AdminProductGridSection.productGridCell(row,column)}}" userInput="{{value}}" stepKey="seeProductGridCellWithProvidedValue"/>
</actionGroup>
</actionGroups>
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="CheckAdminProductGridColumnOptionActionGroup">
<annotations>
<description>Checks Admin Product Grid 'Columns' option.</description>
</annotations>
<arguments>
<argument name="optionName" type="string" defaultValue="Name"/>
</arguments>

<checkOption selector="{{AdminProductGridFilterSection.viewColumnOption(optionName)}}" stepKey="checkColumn"/>
</actionGroup>
</actionGroups>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="ClearFiltersAdminProductGridActionGroup">
<annotations>
<description>Clicks on 'Clear Filters'.</description>
</annotations>

<conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFilters"/>
<waitForPageLoad stepKey="waitForGridLoad"/>
</actionGroup>
</actionGroups>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="ResetAdminProductGridColumnsActionGroup">
<annotations>
<description>Clicks 'reset' for Admin Product Grid 'Columns' dropdown.</description>
</annotations>

<click selector="{{AdminProductGridFilterSection.resetGridColumns}}" stepKey="resetProductGridColumns"/>
</actionGroup>
</actionGroups>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="ToggleAdminProductGridColumnsDropdownActionGroup">
<annotations>
<description>Toggles Admin Product Grid 'Columns' dropdown.</description>
</annotations>

<click selector="{{AdminProductGridFilterSection.columnsDropdown}}" stepKey="toggleColumnsDropdown"/>
</actionGroup>
</actionGroups>
Expand Up @@ -31,6 +31,14 @@
<data key="attribute_code">short_description</data>
<data key="value" unique="suffix">API Product Short Description</data>
</entity>
<entity name="ApiProductSpecialPrice" type="custom_attribute">
<data key="attribute_code">special_price</data>
<data key="value">51.51</data>
</entity>
<entity name="ApiProductCost" type="custom_attribute">
<data key="attribute_code">cost</data>
<data key="value">50.05</data>
</entity>
<entity name="ApiProductNewsFromDate" type="custom_attribute">
<data key="attribute_code">news_from_date</data>
<data key="value">2018-05-17 00:00:00</data>
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml
Expand Up @@ -175,6 +175,10 @@
<data key="status">1</data>
<data key="quantity">0</data>
</entity>
<entity name="SimpleOutOfStockProductWithSpecialPriceAndCost" type="product" extends="SimpleOutOfStockProduct">
<requiredEntity type="custom_attribute_array">ApiProductSpecialPrice</requiredEntity>
<requiredEntity type="custom_attribute_array">ApiProductCost</requiredEntity>
</entity>
<entity name="SimpleProductInStockQuantityZero" type="product">
<data key="name" unique="suffix">SimpleProductInStockQuantityZero</data>
<data key="sku" unique="suffix">testSku</data>
Expand Down
Expand Up @@ -21,7 +21,7 @@
<element name="firstProductRowEditButton" type="button" selector="table.data-grid tr.data-row td .action-menu-item:first-of-type"/>
<element name="productThumbnail" type="text" selector="table.data-grid tr:nth-child({{row}}) td.data-grid-thumbnail-cell > img" parameterized="true"/>
<element name="productThumbnailBySrc" type="text" selector="img.admin__control-thumbnail[src*='{{pattern}}']" parameterized="true"/>
<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"/>
<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"/>
<element name="productGridHeaderCell" type="text" selector="//div[@data-role='grid-wrapper']//tr//th[contains(., '{{column}}')]" parameterized="true"/>
<element name="multicheckDropdown" type="button" selector="div[data-role='grid-wrapper'] th.data-grid-multicheck-cell button.action-multicheck-toggle"/>
<element name="multicheckOption" type="button" selector="//div[@data-role='grid-wrapper']//th[contains(@class, data-grid-multicheck-cell)]//li//span[text() = '{{label}}']" parameterized="true"/>
Expand Down
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminCheckProductListPriceAttributesTest">
<annotations>
<stories value="Check price attributes values on Admin Product List"/>
<title value="Check price attributes values on Admin Product List."/>
<description value="Login as admin, create simple product, add cost, special price. Go to Admin
Product List page filter grid by created product, add mentioned columns to grid, check values."/>
<group value="catalog"/>
</annotations>
<before>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginToAdminPanel"/>
<createData entity="SimpleOutOfStockProductWithSpecialPriceAndCost" stepKey="createSimpleProduct"/>

<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="adminOpenProductIndexPage"/>
<actionGroup ref="FilterProductGridBySkuActionGroup" stepKey="filterProductGridByCreatedSimpleProductSku">
<argument name="product" value="$$createSimpleProduct$$"/>
</actionGroup>
</before>
<after>
<actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="clearFiltersAdminProductGrid"/>
<actionGroup ref="ToggleAdminProductGridColumnsDropdownActionGroup" stepKey="openToResetColumnsDropdown"/>
<actionGroup ref="ResetAdminProductGridColumnsActionGroup" stepKey="resetAdminProductGridColumns"/>

<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
<actionGroup ref="logout" stepKey="logout"/>
<!-- Reindex invalidated indices after product attribute has been created/deleted -->
<actionGroup ref="CliRunReindexUsingCronJobsActionGroup" stepKey="reindexInvalidatedIndices"/>
</after>

<actionGroup ref="ToggleAdminProductGridColumnsDropdownActionGroup" stepKey="openColumnsDropdown"/>
<actionGroup ref="CheckAdminProductGridColumnOptionActionGroup" stepKey="checkSpecialPriceOption">
<argument name="optionName" value="Special Price"/>
</actionGroup>
<actionGroup ref="CheckAdminProductGridColumnOptionActionGroup" stepKey="checkCostOption">
<argument name="optionName" value="Cost"/>
</actionGroup>
<actionGroup ref="ToggleAdminProductGridColumnsDropdownActionGroup" stepKey="closeColumnsDropdown"/>

<actionGroup ref="AssertAdminProductGridCellActionGroup" stepKey="seePrice">
<argument name="row" value="1"/>
<argument name="column" value="Price"/>
<argument name="value" value="${{SimpleOutOfStockProduct.price}}"/>
</actionGroup>
<actionGroup ref="AssertAdminProductGridCellActionGroup" stepKey="seeCorrectSpecialPrice">
<argument name="row" value="1"/>
<argument name="column" value="Special Price"/>
<argument name="value" value="${{ApiProductSpecialPrice.value}}"/>
</actionGroup>
<actionGroup ref="AssertAdminProductGridCellActionGroup" stepKey="seeCorrectCost">
<argument name="row" value="1"/>
<argument name="column" value="Cost"/>
<argument name="value" value="${{ApiProductCost.value}}"/>
</actionGroup>
</test>
</tests>
@@ -0,0 +1,105 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Ui\DataProvider\Product\Modifier;

use Magento\Framework\Currency;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Locale\CurrencyInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;

/**
* Modify product listing price attributes
*/
class PriceAttributes implements ModifierInterface
{
/**
* @var array
*/
private $priceAttributeList;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var CurrencyInterface
*/
private $localeCurrency;

/**
* PriceAttributes constructor.
*
* @param StoreManagerInterface $storeManager
* @param CurrencyInterface $localeCurrency
* @param array $priceAttributeList
*/
public function __construct(
StoreManagerInterface $storeManager,
CurrencyInterface $localeCurrency,
array $priceAttributeList = []
) {
$this->storeManager = $storeManager;
$this->localeCurrency = $localeCurrency;
$this->priceAttributeList = $priceAttributeList;
}

/**
* @inheritdoc
*/
public function modifyData(array $data): array
{
if (empty($data) || empty($this->priceAttributeList)) {
return $data;
}

foreach ($data['items'] as &$item) {
foreach ($this->priceAttributeList as $priceAttribute) {
if (isset($item[$priceAttribute])) {
$item[$priceAttribute] = $this->getCurrency()->toCurrency(sprintf("%f", $item[$priceAttribute]));
}
}
}

return $data;
}

/**
* @inheritdoc
*/
public function modifyMeta(array $meta): array
{
return $meta;
}

/**
* Retrieve store
*
* @return StoreInterface
* @throws NoSuchEntityException
*/
private function getStore(): StoreInterface
{
return $this->storeManager->getStore();
}

/**
* Retrieve currency
*
* @return Currency
* @throws NoSuchEntityException
*/
private function getCurrency(): Currency
{
$baseCurrencyCode = $this->getStore()->getBaseCurrencyCode();

return $this->localeCurrency->getCurrency($baseCurrencyCode);
}
}
12 changes: 12 additions & 0 deletions app/code/Magento/Catalog/etc/adminhtml/di.xml
Expand Up @@ -177,6 +177,10 @@
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Modifier\Attributes</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
<item name="priceAttributes" xsi:type="array">
<item name="class" xsi:type="string">Magento\Catalog\Ui\DataProvider\Product\Modifier\PriceAttributes</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</arguments>
</virtualType>
Expand All @@ -188,6 +192,14 @@
</argument>
</arguments>
</type>
<type name="Magento\Catalog\Ui\DataProvider\Product\Modifier\PriceAttributes">
<arguments>
<argument name="priceAttributeList" xsi:type="array">
<item name="cost" xsi:type="string">cost</item>
<item name="special_price" xsi:type="string">special_price</item>
</argument>
</arguments>
</type>
<type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\CustomOptions">
<arguments>
<argument name="scopeName" xsi:type="string">product_form.product_form</argument>
Expand Down
14 changes: 14 additions & 0 deletions app/code/Magento/Msrp/Test/Mftf/Data/CustomAttributeData.xml
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
<entity name="ApiProductMsrp" type="custom_attribute">
<data key="attribute_code">msrp</data>
<data key="value">111.11</data>
</entity>
</entities>
16 changes: 16 additions & 0 deletions app/code/Magento/Msrp/Test/Mftf/Data/ProductData.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
<entity name="SimpleOutOfStockProductWithSpecialPriceCostAndMsrp" type="product" extends="SimpleOutOfStockProduct">
<requiredEntity type="custom_attribute_array">ApiProductSpecialPrice</requiredEntity>
<requiredEntity type="custom_attribute_array">ApiProductCost</requiredEntity>
<requiredEntity type="custom_attribute_array">ApiProductMsrp</requiredEntity>
</entity>
</entities>
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminCheckProductListPriceAttributesTest">
<annotations>
<group value="msrp"/>
</annotations>
<before>
<createData entity="SimpleOutOfStockProductWithSpecialPriceCostAndMsrp" stepKey="createSimpleProduct"/>
</before>

<actionGroup ref="CheckAdminProductGridColumnOptionActionGroup" stepKey="checkMsrpOption" after="checkCostOption">
<argument name="optionName" value="Minimum Advertised Price"/>
</actionGroup>

<actionGroup ref="AssertAdminProductGridCellActionGroup" stepKey="seeCorrectMsrp" after="seeCorrectCost">
<argument name="row" value="1"/>
<argument name="column" value="Minimum Advertised Price"/>
<argument name="value" value="${{ApiProductMsrp.value}}"/>
</actionGroup>
</test>
</tests>

0 comments on commit d81d1d4

Please sign in to comment.