Skip to content

Commit a88f1cc

Browse files
Merge pull request #8342 from magento-l3/PR_Jun_06_2023
L3 Bugfix delivery
2 parents 4b45119 + cb54bcb commit a88f1cc

File tree

43 files changed

+1328
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1328
-82
lines changed

app/code/Magento/Bundle/Test/Mftf/Section/StorefrontProductInfoMainSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<element name="asLowAsFinalPrice" type="text" selector="div.price-box.price-final_price p.minimal-price > span.price-final_price span.price"/>
1717
<element name="fixedFinalPrice" type="text" selector="div.price-box.price-final_price > span.price-final_price span.price"/>
1818
<element name="productBundleOptionsCheckbox" type="checkbox" selector="//*[@id='product-options-wrapper']//div[@class='fieldset']//label[contains(.,'{{childName}}')]/../input" parameterized="true" timeout="30"/>
19+
<element name="productBundleOneOptionInput" type="input" selector="//*[@id='product-options-wrapper']//div[@class='fieldset']//label[contains(.,'{{childName}}')]/..//input[contains(@class, 'option')]" parameterized="true" timeout="30"/>
20+
<element name="productBundleOptionQty" type="input" selector="//*[@id='product-options-wrapper']//div[@class='fieldset']//label[contains(.,'{{childName}}')]/..//input[contains(@class, 'qty')]" parameterized="true" timeout="30"/>
1921
<element name="includingTaxPrice" type="text" selector=".//*[@class='price-wrapper price-including-tax']/span"/>
2022
<element name="excludingTaxPrice" type="text" selector=".//*[@class='price-wrapper price-excluding-tax']/span"/>
2123
</section>

app/code/Magento/Bundle/view/base/web/js/price-bundle.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ define([
1111
'underscore',
1212
'mage/template',
1313
'priceUtils',
14+
'jquery/jquery.parsequery',
1415
'priceBox'
1516
], function ($, _, mageTemplate, utils) {
1617
'use strict';
@@ -40,9 +41,14 @@ define([
4041
*/
4142
_init: function initPriceBundle() {
4243
var form = this.element,
43-
options = $(this.options.productBundleSelector, form);
44+
options = $(this.options.productBundleSelector, form),
45+
qty = $(this.options.qtyFieldSelector, form);
46+
47+
// Override defaults with URL query parameters and/or inputs values
48+
this._overrideDefaults();
4449

4550
options.trigger('change');
51+
qty.trigger('change');
4652
},
4753

4854
/**
@@ -60,6 +66,71 @@ define([
6066
qty.on('change', this._onQtyFieldChanged.bind(this));
6167
},
6268

69+
/**
70+
* Override default options values settings with either URL query parameters or
71+
* initialized inputs values.
72+
* @private
73+
*/
74+
_overrideDefaults: function () {
75+
var hashIndex = window.location.href.indexOf('#');
76+
77+
if (hashIndex !== -1) {
78+
this._parseQueryParams(window.location.href.substr(hashIndex + 1));
79+
}
80+
},
81+
82+
/**
83+
* Parse query parameters from a query string and set options values based on the
84+
* key value pairs of the parameters.
85+
* @param {*} queryString - URL query string containing query parameters.
86+
* @private
87+
*/
88+
_parseQueryParams: function (queryString) {
89+
var queryParams = $.parseQuery({
90+
query: queryString
91+
}),
92+
selectedValues = [],
93+
form = this.element,
94+
options = $(this.options.productBundleSelector, form),
95+
qtys = $(this.options.qtyFieldSelector, form);
96+
97+
$.each(queryParams, $.proxy(function (key, value) {
98+
qtys.each(function (index, qty) {
99+
if (qty.name === key) {
100+
$(qty).val(value);
101+
}
102+
});
103+
options.each(function (index, option) {
104+
let optionType = $(option).prop('type');
105+
106+
if (option.name === key ||
107+
optionType === 'select-multiple'
108+
&& key.indexOf(option.name.substr(0, option.name.length - 2)) !== false
109+
) {
110+
111+
switch (optionType) {
112+
case 'radio':
113+
$(option).val() === value ? $(option).prop('checked', true) : '';
114+
break;
115+
case 'checkbox':
116+
$(option).prop('checked', true);
117+
break;
118+
case 'hidden':
119+
case 'select-one':
120+
$(option).val(value);
121+
break;
122+
case 'select-multiple':
123+
selectedValues.push(value);
124+
break;
125+
}
126+
if (optionType === 'select-multiple' && selectedValues.length) {
127+
$(option).val(selectedValues);
128+
}
129+
}
130+
});
131+
}, this));
132+
},
133+
63134
/**
64135
* Update price box config with bundle option prices
65136
* @private

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
namespace Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery;
1515

16+
use Magento\Catalog\Helper\Image;
1617
use Magento\Framework\App\ObjectManager;
1718
use Magento\Backend\Block\Media\Uploader;
1819
use Magento\Framework\Json\Helper\Data as JsonHelper;
@@ -45,7 +46,7 @@ class Content extends \Magento\Backend\Block\Widget
4546
protected $_jsonEncoder;
4647

4748
/**
48-
* @var \Magento\Catalog\Helper\Image
49+
* @var Image
4950
*/
5051
private $imageHelper;
5152

@@ -67,6 +68,7 @@ class Content extends \Magento\Backend\Block\Widget
6768
* @param ImageUploadConfigDataProvider $imageUploadConfigDataProvider
6869
* @param Database $fileStorageDatabase
6970
* @param JsonHelper|null $jsonHelper
71+
* @param Image|null $imageHelper
7072
*/
7173
public function __construct(
7274
\Magento\Backend\Block\Template\Context $context,
@@ -75,7 +77,8 @@ public function __construct(
7577
array $data = [],
7678
ImageUploadConfigDataProvider $imageUploadConfigDataProvider = null,
7779
Database $fileStorageDatabase = null,
78-
?JsonHelper $jsonHelper = null
80+
?JsonHelper $jsonHelper = null,
81+
?Image $imageHelper = null
7982
) {
8083
$this->_jsonEncoder = $jsonEncoder;
8184
$this->_mediaConfig = $mediaConfig;
@@ -85,6 +88,7 @@ public function __construct(
8588
?: ObjectManager::getInstance()->get(ImageUploadConfigDataProvider::class);
8689
$this->fileStorageDatabase = $fileStorageDatabase
8790
?: ObjectManager::getInstance()->get(Database::class);
91+
$this->imageHelper = $imageHelper ?: ObjectManager::getInstance()->get(Image::class);
8892
}
8993

9094
/**
@@ -191,7 +195,7 @@ public function getImagesJson()
191195
$fileHandler = $mediaDir->stat($this->_mediaConfig->getMediaPath($image['file']));
192196
$image['size'] = $fileHandler['size'];
193197
} catch (FileSystemException $e) {
194-
$image['url'] = $this->getImageHelper()->getDefaultPlaceholderUrl('small_image');
198+
$image['url'] = $this->imageHelper->getDefaultPlaceholderUrl('small_image');
195199
$image['size'] = 0;
196200
$this->_logger->warning($e);
197201
}
@@ -304,17 +308,14 @@ public function getImageTypesJson()
304308
}
305309

306310
/**
307-
* Returns image helper object.
311+
* Flag if gallery content editing is enabled.
308312
*
309-
* @return \Magento\Catalog\Helper\Image
310-
* @deprecated 101.0.3
313+
* Is enabled by default, exposed to interceptors to add custom logic
314+
*
315+
* @return bool
311316
*/
312-
private function getImageHelper()
317+
public function isEditEnabled() : bool
313318
{
314-
if ($this->imageHelper === null) {
315-
$this->imageHelper = \Magento\Framework\App\ObjectManager::getInstance()
316-
->get(\Magento\Catalog\Helper\Image::class);
317-
}
318-
return $this->imageHelper;
319+
return true;
319320
}
320321
}

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/Section/StorefrontProductInfoMainSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<element name="price" type="text" selector=".product-info-main [data-price-type='finalPrice']"/>
1717
<element name="productPrice" type="text" selector=".price-final_price"/>
1818
<element name="qty" type="input" selector="#qty"/>
19+
<element name="qtyByClassAndQuantity" type="input" selector="//input[contains(@class,'qty') and @value='{{quantity}}']" parameterized="true"/>
1920
<element name="specialPrice" type="text" selector=".special-price"/>
2021
<element name="specialPriceAmount" type="text" selector=".special-price span.price"/>
2122
<element name="updatedPrice" type="text" selector="div.price-box.price-final_price [data-price-type='finalPrice'] .price"/>

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>

0 commit comments

Comments
 (0)