Skip to content

Commit 69b5b6f

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-89986' into 2.2-develop-pr48
2 parents 7afa9b0 + afbbff3 commit 69b5b6f

File tree

5 files changed

+127
-0
lines changed

5 files changed

+127
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Weee\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper;
7+
8+
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper;
10+
use Magento\Framework\App\RequestInterface;
11+
12+
/**
13+
* Handles product tax attributes data initialization.
14+
*/
15+
class ProcessTaxAttribute
16+
{
17+
/**
18+
* @var RequestInterface
19+
*/
20+
private $request;
21+
22+
/**
23+
* @param RequestInterface $request
24+
*/
25+
public function __construct(RequestInterface $request)
26+
{
27+
$this->request = $request;
28+
}
29+
30+
/**
31+
* @param Helper $subject
32+
* @param Product $result
33+
* @param Product $product
34+
* @param array $productData
35+
* @return Product
36+
*
37+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
38+
*/
39+
public function afterInitializeFromData(
40+
Helper $subject,
41+
Product $result,
42+
Product $product,
43+
array $productData
44+
): Product {
45+
$attributes = $result->getAttributes();
46+
if (!empty($attributes)) {
47+
foreach ($attributes as $attribute) {
48+
if ($attribute->getFrontendInput() == 'weee' && !isset($productData[$attribute->getAttributeCode()])) {
49+
$result->setData($attribute->getAttributeCode(), []);
50+
}
51+
}
52+
}
53+
54+
return $result;
55+
}
56+
}

app/code/Magento/Weee/Test/Mftf/Section/AdminProductAddFPTValueSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
1111
<section name="AdminProductAddFPTValueSection">
1212
<element name="addFPT" type="button" selector="[data-index='{{FPTAttributeCode}}'] [data-action='add_new_row']" parameterized="true"/>
13+
<element name="removeRowByIndex" type="button" selector="[data-index='{{FPTAttributeCode}}'] [data-action='remove_row']:nth-of-type({{rowIndex}})" parameterized="true"/>
1314
<element name="selectCountryForFPT" type="select" selector="(//select[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[country]')])[last()]" parameterized="true"/>
1415
<element name="selectStateForFPT" type="select" selector="(//select[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[state]')])[last()]" parameterized="true"/>
1516
<element name="setTaxValueForFPT" type="text" selector="(//input[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[value]')])[last()]" parameterized="true"/>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
10+
<test name="AdminRemoveProductWeeeAttributeOptionTest">
11+
<annotations>
12+
<features value="Weee attribute options can be removed in product page"/>
13+
<title value="Weee attribute options can be removed in product page"/>
14+
<description value="Weee attribute options can be removed in product page"/>
15+
<severity value="CRITICAL"/>
16+
<testCaseId value="MAGETWO-94817"/>
17+
<group value="weee"/>
18+
</annotations>
19+
<before>
20+
<createData entity="productFPTAttribute" stepKey="createProductFPTAttribute"/>
21+
<createData entity="AddToDefaultSet" stepKey="addFPTToAttributeSet">
22+
<requiredEntity createDataKey="createProductFPTAttribute"/>
23+
</createData>
24+
<createData entity="SimpleOne" stepKey="createSimpleProduct"/>
25+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
26+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProductInitial">
27+
<argument name="product" value="$$createSimpleProduct$$"/>
28+
</actionGroup>
29+
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProductInitial">
30+
<argument name="product" value="$$createSimpleProduct$$"/>
31+
</actionGroup>
32+
<actionGroup ref="AdminProductAddFPTValueActionGroup" stepKey="addWeeeAttributeValue">
33+
<argument name="FPTAttributeCode" value="$$createProductFPTAttribute.attribute_code$$"/>
34+
<argument name="stateForFPT" value="California"/>
35+
<argument name="valueForFPT" value="10"/>
36+
</actionGroup>
37+
<actionGroup ref="SaveProductOnProductPageOnAdmin" stepKey="saveProductInitial"/>
38+
</before>
39+
<after>
40+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductListing"/>
41+
<waitForPageLoad stepKey="waitForProductListingPageLoad"/>
42+
<actionGroup ref="AdminResetProductGridToDefaultViewActionGroup" stepKey="resetGridToDefaultKeywordSearch"/>
43+
<actionGroup ref="logout" stepKey="logout"/>
44+
<deleteData createDataKey="createProductFPTAttribute" stepKey="deleteProductFPTAttribute"/>
45+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
46+
</after>
47+
<!-- Test Steps -->
48+
<!-- Step 1: Open created product edit page -->
49+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProduct">
50+
<argument name="product" value="$$createSimpleProduct$$"/>
51+
</actionGroup>
52+
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct">
53+
<argument name="product" value="$$createSimpleProduct$$"/>
54+
</actionGroup>
55+
<!-- Step 2: Remove weee attribute options -->
56+
<click selector="{{AdminProductAddFPTValueSection.removeRowByIndex('$$createProductFPTAttribute.attribute_code$$','1')}}" stepKey="removeAttributeOption"/>
57+
<actionGroup ref="SaveProductOnProductPageOnAdmin" stepKey="saveProduct"/>
58+
<!-- Assert weee attribute options are empty -->
59+
<dontSeeElement selector="{{AdminProductAddFPTValueSection.removeRowByIndex('$$createProductFPTAttribute.attribute_code$$','1')}}" stepKey="dontSeeOptions"/>
60+
</test>
61+
</tests>

app/code/Magento/Weee/Ui/DataProvider/Product/Form/Modifier/Weee.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
180180
'component' => 'Magento_Weee/js/fpt-group',
181181
'visible' => true,
182182
'label' => __('Country/State'),
183+
'showLabel' => false,
183184
],
184185
],
185186
],
@@ -197,6 +198,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
197198
'validation' => [
198199
'required-entry' => true,
199200
],
201+
'showLabel' => false,
200202
],
201203
],
202204
],
@@ -216,6 +218,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
216218
],
217219
'caption' => '*',
218220
'visible' => true,
221+
'showLabel' => false,
219222
],
220223
],
221224
],
@@ -233,6 +236,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
233236
'validation' => [
234237
'validate-fpt-group' => true
235238
],
239+
'showLabel' => false,
236240
],
237241
],
238242
],
@@ -252,6 +256,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
252256
'validation' => [
253257
'required-entry' => true
254258
],
259+
'showLabel' => false,
255260
],
256261
],
257262
],
@@ -267,6 +272,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
267272
'label' => __('Website'),
268273
'visible' => $this->websiteManager->isMultiWebsites(),
269274
'options' => $this->websiteManager->getWebsites($product, $eavAttribute),
275+
'showLabel' => false,
270276
],
271277
],
272278
],

app/code/Magento/Weee/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,7 @@
7878
</argument>
7979
</arguments>
8080
</type>
81+
<type name="Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper">
82+
<plugin name="weeeAttributeOptionsProcess" type="Magento\Weee\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper\ProcessTaxAttribute"/>
83+
</type>
8184
</config>

0 commit comments

Comments
 (0)