Skip to content

Commit a001993

Browse files
committed
MAGETWO-73638: Product "Use Default Value" checkbox for an attributes are unchecked for the new website scope
1 parent aa6b899 commit a001993

12 files changed

+152
-39
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ private function handleImageRemoveError($postData, $productId)
216216
/**
217217
* Do copying data to stores
218218
*
219+
* If the 'copy_from' field is not specified in the input data,
220+
* the store fallback mechanism will automatically take the admin store's default value.
221+
*
219222
* @param array $data
220223
* @param int $productId
221224
* @return void
@@ -227,15 +230,17 @@ protected function copyToStores($data, $productId)
227230
if (isset($data['product']['website_ids'][$websiteId])
228231
&& (bool)$data['product']['website_ids'][$websiteId]) {
229232
foreach ($group as $store) {
230-
$copyFrom = (isset($store['copy_from'])) ? $store['copy_from'] : 0;
231-
$copyTo = (isset($store['copy_to'])) ? $store['copy_to'] : 0;
232-
if ($copyTo) {
233-
$this->_objectManager->create(\Magento\Catalog\Model\Product::class)
234-
->setStoreId($copyFrom)
235-
->load($productId)
236-
->setStoreId($copyTo)
237-
->setCopyFromView(true)
238-
->save();
233+
if (isset($store['copy_from'])) {
234+
$copyFrom = $store['copy_from'];
235+
$copyTo = (isset($store['copy_to'])) ? $store['copy_to'] : 0;
236+
if ($copyTo) {
237+
$this->_objectManager->create(\Magento\Catalog\Model\Product::class)
238+
->setStoreId($copyFrom)
239+
->load($productId)
240+
->setStoreId($copyTo)
241+
->setCopyFromView(true)
242+
->save();
243+
}
239244
}
240245
}
241246
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
1111
<section name="AdminProductCustomizableOptionsSection">
1212
<element name="checkIfCustomizableOptionsTabOpen" type="text" selector="//span[text()='Customizable Options']/parent::strong/parent::*[@data-state-collapsible='closed']"/>
13-
<element name="customezableOptions" type="text" selector="//strong[contains(@class, 'admin__collapsible-title')]/span[text()='Customizable Options']"/>
13+
<element name="customezableOptions" type="text" selector="//strong[contains(@class, 'admin__collapsible-title')]/span[text()='Customizable Options']" timeout="30"/>
1414
<element name="useDefaultOptionTitle" type="text" selector="[data-index='options'] tr.data-row [data-index='title'] [name^='options_use_default']"/>
1515
<element name="useDefaultOptionValueTitleByIndex" type="text" selector="[data-index='options'] [data-index='values'] tr[data-repeat-index='{{var1}}'] [name^='options_use_default']" parameterized="true"/>
1616
<element name="addOptionBtn" type="button" selector="button[data-index='button_add']"/>
@@ -22,4 +22,4 @@
2222
<element name="fillOptionValuePrice" type="input" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//tbody/tr[@data-repeat-index='{{var2}}']//span[text()='Price']/parent::label/parent::div//div[@class='admin__control-addon']/input" parameterized="true"/>
2323
<element name="clickSelectPriceType" type="select" selector="//span[text()='{{var1}}']/parent::div/parent::div/parent::div//tbody//tr[@data-repeat-index='{{var2}}']//span[text()='Price Type']/parent::label/parent::div//select" parameterized="true"/>
2424
</section>
25-
</sections>
25+
</sections>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
1111
<section name="AdminProductFormSection">
1212
<element name="productName" type="input" selector=".admin__field[data-index=name] input"/>
13+
<element name="productNameUseDefault" type="checkbox" selector="input[name='use_default[name]']"/>
1314
<element name="productSku" type="input" selector=".admin__field[data-index=sku] input"/>
1415
<element name="productStatus" type="checkbox" selector="input[name='product[status]']"/>
16+
<element name="productStatusUseDefault" type="checkbox" selector="input[name='use_default[status]']"/>
1517
<element name="productPrice" type="input" selector=".admin__field[data-index=price] input"/>
18+
<element name="productTaxClassUseDefault" type="checkbox" selector="input[name='use_default[tax_class_id]']"/>
1619
<element name="categoriesDropdown" type="multiselect" selector="div[data-index='category_ids']"/>
1720
<element name="productQuantity" type="input" selector=".admin__field[data-index=qty] input"/>
1821
<element name="productStockStatus" type="select" selector="select[name='product[quantity_and_stock_status][is_in_stock]']"/>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
11+
<test name="AdminMultipleWebsitesUseDefaultValuesTest">
12+
<annotations>
13+
<title value="Use Default Value checkboxes should be checked for new website scope"/>
14+
<description value="Use Default Value checkboxes for product attribute should be checked for new website scope"/>
15+
<severity value="MAJOR"/>
16+
<testCaseId value="MAGETWO-92990"/>
17+
<group value="Catalog"/>
18+
</annotations>
19+
<after>
20+
<deleteData url="V1/products/{{_defaultProduct.sku}}" stepKey="deleteProduct"/>
21+
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteSecondWebsite">
22+
<argument name="websiteName" value="Second Website"/>
23+
</actionGroup>
24+
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
25+
</after>
26+
<actionGroup ref="LoginActionGroup" stepKey="loginAsAdmin"/>
27+
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="createAdditionalWebsite">
28+
<argument name="newWebsiteName" value="Second Website"/>
29+
<argument name="websiteCode" value="second_website"/>
30+
</actionGroup>
31+
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createNewStoreGroup">
32+
<argument name="website" value="Second Website"/>
33+
<argument name="storeGroupName" value="Second Store"/>
34+
<argument name="storeGroupCode" value="second_store"/>
35+
</actionGroup>
36+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createNewStore">
37+
<argument name="storeGroup" value="secondStoreGroup"/>
38+
<argument name="customStore" value="secondStore"/>
39+
</actionGroup>
40+
41+
<!--Create a Simple Product -->
42+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToCatalogProductGrid"/>
43+
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickAddProductDropdown"/>
44+
<click selector="{{AdminProductGridActionSection.addSimpleProduct}}" stepKey="clickAddSimpleProduct"/>
45+
<fillField userInput="{{_defaultProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="fillProductName"/>
46+
<fillField userInput="{{_defaultProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="fillProductSKU"/>
47+
<fillField userInput="{{_defaultProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="fillProductPrice"/>
48+
<fillField userInput="{{_defaultProduct.quantity}}" selector="{{AdminProductFormSection.productQuantity}}" stepKey="fillProductQuantity"/>
49+
50+
<!-- Add product to second website and save the product -->
51+
<click selector="{{ProductInWebsitesSection.sectionHeader}}" stepKey="openProductInWebsites"/>
52+
<click selector="{{ProductInWebsitesSection.website('Second Website')}}" stepKey="selectSecondWebsite"/>
53+
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickSave"/>
54+
<waitForLoadingMaskToDisappear stepKey="waitForProductPageSave"/>
55+
<seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="seeSaveProductMessage"/>
56+
57+
<!-- switch to the second store view -->
58+
<click selector="{{AdminProductFormActionSection.changeStoreButton}}" stepKey="clickStoreviewSwitcher"/>
59+
<click selector="{{AdminProductFormActionSection.selectStoreView('Second Store View')}}" stepKey="chooseStoreView"/>
60+
<click selector="{{AdminConfirmationModalSection.ok}}" stepKey="acceptStoreSwitchingMessage"/>
61+
<waitForPageLoad time="30" stepKey="waitForPageLoad9"/>
62+
<see userInput="Second Store View" selector="{{AdminMainActionsSection.storeSwitcher}}" stepKey="seeNewStoreViewName"/>
63+
64+
<!-- Check if Use Default Value checkboxes are checked -->
65+
<seeCheckboxIsChecked selector="{{AdminProductFormSection.productStatusUseDefault}}" stepKey="seeProductStatusCheckboxChecked"/>
66+
<seeCheckboxIsChecked selector="{{AdminProductFormSection.productNameUseDefault}}" stepKey="seeProductNameCheckboxChecked"/>
67+
<seeCheckboxIsChecked selector="{{AdminProductFormSection.productTaxClassUseDefault}}" stepKey="seeTaxClassCheckboxChecked"/>
68+
<seeCheckboxIsChecked selector="{{AdminProductFormSection.visibilityUseDefault}}" stepKey="seeVisibilityCheckboxChecked"/>
69+
</test>
70+
</tests>

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,26 @@
2121

2222
<after>
2323
<actionGroup ref="ResetWebUrlOptions" stepKey="resetUrlOption"/>
24-
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteWebsite"/>
25-
24+
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteSecondWebsite">
25+
<argument name="websiteName" value="Second Website"/>
26+
</actionGroup>
2627
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
2728
</after>
2829
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
2930
<actionGroup ref="EnableWebUrlOptions" stepKey="addStoreCodeToUrls"/>
30-
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="addnewWebsite"/>
31-
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="addNewStoreGroup"/>
32-
33-
<!--Create Store view -->
34-
<amOnPage url="{{AdminSystemStorePage.url}}" stepKey="amOnAdminSystemStorePage"/>
35-
<waitForPageLoad time="30" stepKey="waitForStoreViewGridPageLoad" />
36-
<click selector="{{AdminStoresMainActionsSection.createStoreViewButton}}" stepKey="createStoreViewButton"/>
37-
<waitForPageLoad stepKey="waitForProductPageLoad"/>
38-
<selectOption userInput="Second Store" selector="{{AdminNewStoreSection.storeGrpDropdown}}" stepKey="selectStoreGroup"/>
39-
<fillField userInput="Second Store View" selector="{{AdminNewStoreSection.storeNameTextField}}" stepKey="fillStoreViewName"/>
40-
<fillField userInput="second_store_view" selector="{{AdminNewStoreSection.storeCodeTextField}}" stepKey="fillStoreViewCode"/>
41-
<selectOption userInput="1" selector="{{AdminNewStoreSection.statusDropdown}}" stepKey="enableStoreViewStatus"/>
42-
<click selector="{{AdminStoresMainActionsSection.saveButton}}" stepKey="clickStoreViewSaveButton"/>
43-
<waitForElementVisible selector="{{AdminNewStoreSection.acceptNewStoreViewCreation}}" stepKey="waitForAcceptNewStoreViewCreationModal" />
44-
<conditionalClick selector="{{AdminNewStoreSection.acceptNewStoreViewCreation}}" dependentSelector="{{AdminNewStoreSection.acceptNewStoreViewCreation}}" visible="true" stepKey="AcceptNewStoreViewCreation"/>
45-
<waitForElementVisible selector="{{AdminStoresGridSection.storeFilterTextField}}" stepKey="waitForPageReolad"/>
46-
<see userInput="You saved the store view." stepKey="seeSaveMessage" />
31+
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="addnewWebsite">
32+
<argument name="newWebsiteName" value="Second Website"/>
33+
<argument name="websiteCode" value="second_website"/>
34+
</actionGroup>
35+
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createNewStoreGroup">
36+
<argument name="website" value="Second Website"/>
37+
<argument name="storeGroupName" value="Second Store"/>
38+
<argument name="storeGroupCode" value="second_store"/>
39+
</actionGroup>
40+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createNewStore">
41+
<argument name="storeGroup" value="secondStoreGroup"/>
42+
<argument name="customStore" value="secondStore"/>
43+
</actionGroup>
4744

4845
<!--Create a Simple Product with Custom Options -->
4946
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToCatalogProductGrid"/>
@@ -89,6 +86,5 @@
8986

9087
<click selector="{{AdminProductCustomizableOptionsSection.customezableOptions}}" stepKey="openCustomOptionsSection"/>
9188
<seeNumberOfElements selector=".admin__dynamic-rows[data-index='values'] tr.data-row" userInput="3" stepKey="see4RowsOfOptions"/>
92-
9389
</test>
9490
</tests>

app/code/Magento/Store/Test/Mftf/ActionGroup/AdminCreateNewStoreGroupActionGroup.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd">
1111
<actionGroup name="AdminCreateNewStoreGroupActionGroup">
12+
<arguments>
13+
<argument name="website" type="string"/>
14+
<argument name="storeGroupName" type="string"/>
15+
<argument name="storeGroupCode" type="string"/>
16+
</arguments>
1217
<amOnPage url="{{AdminSystemStoreGroupPage.url}}" stepKey="navigateToNewStoreView"/>
1318
<waitForPageLoad stepKey="waitForPageLoad1" />
1419
<!--Create Store group -->
15-
<selectOption selector="{{AdminNewStoreGroupSection.storeGrpWebsiteDropdown}}" userInput="Second Website" stepKey="selectWebsite" />
16-
<fillField selector="{{AdminNewStoreGroupSection.storeGrpNameTextField}}" userInput="Second Store" stepKey="enterStoreGroupName" />
17-
<fillField selector="{{AdminNewStoreGroupSection.storeGrpCodeTextField}}" userInput="second_store" stepKey="enterStoreGroupCode" />
20+
<selectOption selector="{{AdminNewStoreGroupSection.storeGrpWebsiteDropdown}}" userInput="{{website}}" stepKey="selectWebsite" />
21+
<fillField selector="{{AdminNewStoreGroupSection.storeGrpNameTextField}}" userInput="{{storeGroupName}}" stepKey="enterStoreGroupName" />
22+
<fillField selector="{{AdminNewStoreGroupSection.storeGrpCodeTextField}}" userInput="{{storeGroupCode}}" stepKey="enterStoreGroupCode" />
1823
<selectOption selector="{{AdminNewStoreGroupSection.storeRootCategoryDropdown}}" userInput="Default Category" stepKey="chooseRootCategory" />
1924
<click selector="{{AdminStoreGroupActionsSection.saveButton}}" stepKey="clickSaveStoreGroup" />
2025
<waitForElementVisible selector="{{AdminStoresGridSection.storeGrpFilterTextField}}" stepKey="waitForStoreGridReload"/>

app/code/Magento/Store/Test/Mftf/ActionGroup/AdminCreateWebsiteActionGroup.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd">
1111
<actionGroup name="AdminCreateWebsiteActionGroup">
12+
<arguments>
13+
<argument name="newWebsiteName" type="string"/>
14+
<argument name="websiteCode" type="string"/>
15+
</arguments>
1216
<amOnPage url="{{AdminSystemStoreWebsitePage.url}}" stepKey="navigateToNewWebsitePage"/>
1317
<waitForPageLoad stepKey="waitForStoresPageLoad"/>
1418
<!--Create Website-->
15-
<fillField selector="{{AdminNewWebsiteSection.name}}" userInput="Second Website" stepKey="enterWebsiteName" />
16-
<fillField selector="{{AdminNewWebsiteSection.code}}" userInput="second_website" stepKey="enterWebsiteCode" />
19+
<fillField selector="{{AdminNewWebsiteSection.name}}" userInput="{{newWebsiteName}}" stepKey="enterWebsiteName" />
20+
<fillField selector="{{AdminNewWebsiteSection.code}}" userInput="{{websiteCode}}" stepKey="enterWebsiteCode" />
1721
<click selector="{{AdminNewWebsiteActionsSection.saveWebsite}}" stepKey="clickSaveWebsite" />
1822
<waitForElementVisible selector="{{AdminStoresGridSection.websiteFilterTextField}}" stepKey="waitForStoreGridToReload"/>
1923
<see userInput="You saved the website." stepKey="seeSavedMessage" />

app/code/Magento/Store/Test/Mftf/ActionGroup/AdminDeleteWebsiteActionGroup.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd">
1010
<actionGroup name="AdminDeleteWebsiteActionGroup">
11+
<arguments>
12+
<argument name="websiteName" type="string"/>
13+
</arguments>
1114
<amOnPage url="{{AdminSystemStorePage.url}}" stepKey="amOnAdminSystemStorePage"/>
1215
<click selector="{{AdminStoresGridSection.resetButton}}" stepKey="resetSearchFilter"/>
13-
<fillField userInput="Second Website" selector="{{AdminStoresGridSection.websiteFilterTextField}}" stepKey="fillSearchWebsiteField"/>
16+
<fillField userInput="{{websiteName}}" selector="{{AdminStoresGridSection.websiteFilterTextField}}" stepKey="fillSearchWebsiteField"/>
1417
<click selector="{{AdminStoresGridSection.searchButton}}" stepKey="clickSearchButton"/>
15-
<see userInput="Second Website" selector="{{AdminStoresGridSection.websiteNameInFirstRow}}" stepKey="verifyThatCorrectWebsiteFound"/>
18+
<see userInput="{{websiteName}}" selector="{{AdminStoresGridSection.websiteNameInFirstRow}}" stepKey="verifyThatCorrectWebsiteFound"/>
1619
<click selector="{{AdminStoresGridSection.websiteNameInFirstRow}}" stepKey="clickEditExistingStoreRow"/>
1720
<waitForPageLoad stepKey="waitForStoreToLoad"/>
1821
<click selector="{{AdminStoresMainActionsSection.deleteButton}}" stepKey="clickDeleteWebsiteButtonOnEditWebsitePage"/>

app/code/Magento/Store/Test/Mftf/Data/StoreData.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@
3939
<data key="store_type">store</data>
4040
<requiredEntity type="storeGroup">customStoreGroup</requiredEntity>
4141
</entity>
42+
<entity name="secondStore" type="store">
43+
<data key="name">Second Store View</data>
44+
<data key="code">second_store_view</data>
45+
<data key="is_active">1</data>
46+
<requiredEntity type="storeGroup">secondStoreGroup</requiredEntity>
47+
</entity>
4248
</entities>

app/code/Magento/Store/Test/Mftf/Data/StoreGroupData.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@
2121
<data key="store_action">add</data>
2222
<data key="store_type">group</data>
2323
</entity>
24+
<entity name="secondStoreGroup" type="group">
25+
<data key="name">Second Store</data>
26+
<data key="code">main_website_store</data>
27+
<data key="root_category_id">2</data>
28+
<data key="website_id">1</data>
29+
</entity>
2430
</entities>

0 commit comments

Comments
 (0)