Skip to content

Commit 18ec675

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-1640+ACP2E-1621' into PR_Jun_06_2023
2 parents 2d21590 + 42ce8aa commit 18ec675

File tree

7 files changed

+220
-21
lines changed

7 files changed

+220
-21
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
namespace Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper;
1010

11-
use \Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1213

1314
/**
1415
* Class provides functionality to check and filter data came with product form.
@@ -32,7 +33,8 @@ public function prepareProductAttributes(Product $product, array $productData, a
3233
{
3334
$attributeList = $product->getAttributes();
3435
foreach ($productData as $attributeCode => $attributeValue) {
35-
if ($this->isAttributeShouldNotBeUpdated($product, $useDefaults, $attributeCode, $attributeValue)) {
36+
if ($this->isAttributeShouldNotBeUpdated($product, $useDefaults, $attributeCode, $attributeValue) &&
37+
$this->isCustomAttrEmptyValueAllowed($attributeList, $attributeCode, $productData)) {
3638
unset($productData[$attributeCode]);
3739
}
3840

@@ -63,6 +65,34 @@ private function prepareConfigData(Product $product, string $attributeCode, arra
6365
return $productData;
6466
}
6567

68+
/**
69+
* Check if custom attribute with empty value allowed
70+
*
71+
* @param mixed $attributeList
72+
* @param string $attributeCode
73+
* @param array $productData
74+
* @return bool
75+
*/
76+
private function isCustomAttrEmptyValueAllowed(
77+
$attributeList,
78+
string $attributeCode,
79+
array $productData
80+
): bool {
81+
$isAllowed = true;
82+
if ($attributeList && isset($attributeList[$attributeCode])) {
83+
/** @var Attribute $attribute */
84+
$attribute = $attributeList[$attributeCode];
85+
$isAttributeUserDefined = (int) $attribute->getIsUserDefined();
86+
$isAttributeIsRequired = (int) $attribute->getIsRequired();
87+
88+
if ($isAttributeUserDefined && !$isAttributeIsRequired &&
89+
empty($productData[$attributeCode])) {
90+
$isAllowed = false;
91+
}
92+
}
93+
return $isAllowed;
94+
}
95+
6696
/**
6797
* Prepare default attribute data for product.
6898
*
@@ -74,13 +104,15 @@ private function prepareConfigData(Product $product, string $attributeCode, arra
74104
private function prepareDefaultData(array $attributeList, string $attributeCode, array $productData): array
75105
{
76106
if (isset($attributeList[$attributeCode])) {
77-
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
107+
/** @var Attribute $attribute */
78108
$attribute = $attributeList[$attributeCode];
79109
$attributeType = $attribute->getBackendType();
110+
$attributeIsUserDefined = (int) $attribute->getIsUserDefined();
80111
// For non-numeric types set the attributeValue to 'false' to trigger their removal from the db
81112
if ($attributeType === 'varchar' || $attributeType === 'text' || $attributeType === 'datetime') {
82113
$attribute->setIsRequired(false);
83-
$productData[$attributeCode] = $attribute->getDefaultValue() ?: false;
114+
$productData[$attributeCode] = $attributeIsUserDefined ? false :
115+
($attribute->getDefaultValue() ?: false);
84116
} else {
85117
$productData[$attributeCode] = null;
86118
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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="AdminInputCustomAttributeToExistingProductActionGroup">
12+
<annotations>
13+
<description>Add the created text attribute to the existing product</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="attributeCode" type="string" defaultValue="test_attribute"/>
17+
<argument name="adminOption1" type="string" defaultValue="value 1 admin"/>
18+
</arguments>
19+
<!--Scroll to element to avoid test order flakiness-->
20+
<waitForElement selector="{{AdminProductFormSection.attributeTab}}" stepKey="waitForSection"/>
21+
<executeJS function="return document.evaluate(&quot;{{AdminProductFormSection.attributeTab}}&quot;, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.getBoundingClientRect().y" stepKey="sectionPosition"/>
22+
<executeJS function="return document.querySelector(&quot;{{AdminHeaderSection.pageMainActions}}&quot;).getBoundingClientRect().height" stepKey="floatingHeaderHeight"/>
23+
<executeJS function="window.scrollTo({top: {$sectionPosition}-{$floatingHeaderHeight}})" stepKey="scrollToAttributesTab"/>
24+
<conditionalClick selector="{{AdminProductFormSection.attributeTab}}" dependentSelector="{{AdminProductFormSection.attributeTabOpened}}" visible="false" stepKey="clickToOpen"/>
25+
<comment userInput="BIC workaround" stepKey="scrollToAttributeTab"/>
26+
<fillField selector="{{AdminProductFormSection.customInputField(attributeCode)}}" userInput="{{adminOption1}}" stepKey="fillAttributeCode"/>
27+
<click selector="{{AdminProductFormSection.save}}" stepKey="saveTheProduct" />
28+
<waitForPageLoad stepKey="waitForProductsToBeSaved"/>
29+
</actionGroup>
30+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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="AdminSelectCustomAttributeToExistingProductActionGroup">
12+
<annotations>
13+
<description>Add the created dropdown attribute to the existing product</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="attributeCode" type="string" defaultValue="test_attribute"/>
17+
<argument name="adminOption1" type="string" defaultValue="value 1 admin"/>
18+
</arguments>
19+
<!--Scroll to element to avoid test order flakiness-->
20+
<waitForElement selector="{{AdminProductFormSection.attributeTab}}" stepKey="waitForSection"/>
21+
<executeJS function="return document.evaluate(&quot;{{AdminProductFormSection.attributeTab}}&quot;, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.getBoundingClientRect().y" stepKey="sectionPosition"/>
22+
<executeJS function="return document.querySelector(&quot;{{AdminHeaderSection.pageMainActions}}&quot;).getBoundingClientRect().height" stepKey="floatingHeaderHeight"/>
23+
<executeJS function="window.scrollTo({top: {$sectionPosition}-{$floatingHeaderHeight}})" stepKey="scrollToAttributesTab"/>
24+
<conditionalClick selector="{{AdminProductFormSection.attributeTab}}" dependentSelector="{{AdminProductFormSection.attributeTabOpened}}" visible="false" stepKey="clickToOpen"/>
25+
<comment userInput="BIC workaround" stepKey="scrollToAttributeTab"/>
26+
<selectOption selector="{{AdminProductFormSection.customSelectField(attributeCode)}}" userInput="{{adminOption1}}" stepKey="selectAvalueFromDropdown"/>
27+
<click selector="{{AdminProductFormSection.save}}" stepKey="saveTheProduct" />
28+
<waitForPageLoad stepKey="waitForProductsToBeSaved"/>
29+
</actionGroup>
30+
</actionGroups>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9-
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1010
<section name="AdminProductFormSection">
1111
<element name="additionalOptions" type="select" selector=".admin__control-multiselect"/>
1212
<element name="datepickerNewAttribute" type="input" selector="[data-index='{{attrName}}'] input" timeout="30" parameterized="true"/>
@@ -69,6 +69,7 @@
6969
<element name="attributeRequiredInput" type="input" selector="//input[contains(@name, 'product[{{attributeCode}}]')]" parameterized="true"/>
7070
<element name="attributeFieldError" type="text" selector="//*[@class='admin__field _required _error']/..//label[contains(.,'This is a required field.')]"/>
7171
<element name="customSelectField" type="select" selector="//select[@name='product[{{var}}]']" parameterized="true"/>
72+
<element name="customInputField" type="input" selector="//input[@name='product[{{var}}]']" parameterized="true"/>
7273
<element name="searchCategory" type="input" selector="//*[@data-index='category_ids']//input[contains(@class, 'multiselect-search')]" timeout="30"/>
7374
<element name="selectCategory" type="input" selector="//*[@data-index='category_ids']//label[contains(., '{{categoryName}}')]" parameterized="true" timeout="30"/>
7475
<element name="done" type="button" selector="//*[@data-index='category_ids']//button[@data-action='close-advanced-select']" timeout="30"/>

app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateProductAttributeFromProductPageTest.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<actionGroup ref="FilterProductGridBySkuActionGroup" stepKey="filterProductGridBySku">
5454
<argument name="product" value="$$createSimpleProduct$$"/>
5555
</actionGroup>
56-
<click stepKey="openFirstProduct" selector="{{AdminProductGridSection.productRowBySku($$createSimpleProduct.sku$$)}}"/>
56+
<click selector="{{AdminProductGridSection.productRowBySku($$createSimpleProduct.sku$$)}}" stepKey="openFirstProduct"/>
5757
<waitForPageLoad stepKey="waitForProductToLoad"/>
5858

5959
<actionGroup ref="AdminFillProductQtyOnProductFormActionGroup" stepKey="fillProductQty">
@@ -96,6 +96,11 @@
9696
<actionGroup ref="AdminProductFormSaveButtonClickActionGroup" stepKey="saveTheProduct"/>
9797
<see selector="{{AdminCategoryMessagesSection.SuccessMessage}}" userInput="You saved the product." stepKey="messageYouSavedTheProductIsShown"/>
9898

99+
<actionGroup ref="AdminInputCustomAttributeToExistingProductActionGroup" stepKey="adminProductFillCustomAttribute">
100+
<argument name="attributeCode" value="{{newProductAttribute.attribute_code}}"/>
101+
<argument name="adminOption1" value="{{ProductAttributeOption8.label}}"/>
102+
</actionGroup>
103+
99104
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
100105
<argument name="indices" value=""/>
101106
</actionGroup>

app/code/Magento/Catalog/Test/Mftf/Test/AdminVerifyCreateCustomProductAttributeTest.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<title value="Create Custom Product Attribute Dropdown Field (Not Required) from Product Page"/>
1616
<description value="login as admin and create simple product with attribute Dropdown field"/>
1717
<severity value="MAJOR"/>
18-
<testCaseId value="MC-26027"/>
18+
<testCaseId value="AC-8015"/>
1919
<group value="mtf_migrated"/>
2020
<group value="catalog"/>
2121
</annotations>
@@ -63,6 +63,11 @@
6363
<checkOption selector="{{AdminCreateNewProductAttributeSection.defaultRadioButton('1')}}" stepKey="selectRadioButton"/>
6464
<click selector="{{AdminCreateNewProductAttributeSection.saveAttribute}}" stepKey="clickOnSaveAttribute"/>
6565
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveTheProduct"/>
66+
<waitForPageLoad stepKey="waitForProductsToBeSaved"/>
67+
<actionGroup ref="AdminSelectCustomAttributeToExistingProductActionGroup" stepKey="adminProductSelectCustomAttribute">
68+
<argument name="attributeCode" value="{{newProductAttribute.attribute_code}}"/>
69+
<argument name="adminOption1" value="{{ProductAttributeOption8.label}}"/>
70+
</actionGroup>
6671
<actionGroup ref="AdminAssertProductAttributeOnProductEditPageActionGroup" stepKey="adminProductAssertAttribute">
6772
<argument name="attributeLabel" value="{{ProductAttributeFrontendLabel.label}}"/>
6873
<argument name="attributeCode" value="{{newProductAttribute.attribute_code}}"/>

0 commit comments

Comments
 (0)