Skip to content

Commit 1fe7184

Browse files
committed
Merge branch 'BUG#AC-2877' into spartans_pr_22062022
2 parents 95b0396 + b46b283 commit 1fe7184

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontSelectionOfOutOfStockChildProductsOfConfigurableProductDisabledTest">
12+
<annotations>
13+
<features value="CatalogInventory"/>
14+
<stories value="Storefront selection of out of stock child products of configurable product"/>
15+
<title value="Storefront selection of out of stock child products of configurable Product disabled"/>
16+
<description value="Storefront selection of out of stock child products of configurable are disabled on storefront when display of out of stock options are enabled"/>
17+
<severity value="MAJOR"/>
18+
<group value="catalogInventory"/>
19+
</annotations>
20+
21+
<before>
22+
<!--Set Display out of stock product-->
23+
<magentoCLI stepKey="setDisplayOutOfStockProduct" command="config:set cataloginventory/options/show_out_of_stock 1" />
24+
<!-- Create category -->
25+
<createData entity="SimpleSubCategory" stepKey="simplecategory"/>
26+
<!-- Create configurable product with two options -->
27+
<createData entity="ApiConfigurableProduct" stepKey="createConfigProduct">
28+
<requiredEntity createDataKey="simplecategory"/>
29+
</createData>
30+
<createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttribute"/>
31+
<createData entity="productAttributeOption1" stepKey="createConfigProductAttributeOption1">
32+
<requiredEntity createDataKey="createConfigProductAttribute"/>
33+
</createData>
34+
<createData entity="productAttributeOption2" stepKey="createConfigProductAttributeOption2">
35+
<requiredEntity createDataKey="createConfigProductAttribute"/>
36+
</createData>
37+
<createData entity="AddToDefaultSet" stepKey="createConfigAddToAttributeSet">
38+
<requiredEntity createDataKey="createConfigProductAttribute"/>
39+
</createData>
40+
<getData entity="ProductAttributeOptionGetter" index="1" stepKey="getConfigAttributeOption1">
41+
<requiredEntity createDataKey="createConfigProductAttribute"/>
42+
</getData>
43+
<getData entity="ProductAttributeOptionGetter" index="2" stepKey="getConfigAttributeOption2">
44+
<requiredEntity createDataKey="createConfigProductAttribute"/>
45+
</getData>
46+
<!-- Create child products -->
47+
<createData entity="ApiSimpleOne" stepKey="createConfigChildProduct1">
48+
<requiredEntity createDataKey="createConfigProductAttribute"/>
49+
<requiredEntity createDataKey="getConfigAttributeOption1"/>
50+
</createData>
51+
<createData entity="ApiSimpleTwo" stepKey="createConfigChildProduct2">
52+
<requiredEntity createDataKey="createConfigProductAttribute"/>
53+
<requiredEntity createDataKey="getConfigAttributeOption2"/>
54+
</createData>
55+
<createData entity="ConfigurableProductTwoOptions" stepKey="createConfigProductOption">
56+
<requiredEntity createDataKey="createConfigProduct"/>
57+
<requiredEntity createDataKey="createConfigProductAttribute"/>
58+
<requiredEntity createDataKey="getConfigAttributeOption1"/>
59+
<requiredEntity createDataKey="getConfigAttributeOption2"/>
60+
</createData>
61+
<createData entity="ConfigurableProductAddChild" stepKey="createConfigProductAddChild1">
62+
<requiredEntity createDataKey="createConfigProduct"/>
63+
<requiredEntity createDataKey="createConfigChildProduct1"/>
64+
</createData>
65+
<createData entity="ConfigurableProductAddChild" stepKey="createConfigProductAddChild2">
66+
<requiredEntity createDataKey="createConfigProduct"/>
67+
<requiredEntity createDataKey="createConfigChildProduct2"/>
68+
</createData>
69+
<magentoCron groups="index" stepKey="reindex"/>
70+
</before>
71+
72+
<after>
73+
<magentoCLI stepKey="setDisplayOutOfStockProduct" command="config:set cataloginventory/options/show_out_of_stock 0" />
74+
<deleteData createDataKey="createConfigProduct" stepKey="deleteConfigProduct"/>
75+
<deleteData createDataKey="simplecategory" stepKey="deleteSimpleCategory"/>
76+
<deleteData createDataKey="createConfigChildProduct1" stepKey="deleteConfigChildProduct1"/>
77+
<deleteData createDataKey="createConfigChildProduct2" stepKey="deleteConfigChildProduct2"/>
78+
<deleteData createDataKey="createConfigProductAttribute" stepKey="deleteConfigProductAttribute"/>
79+
<magentoCron groups="index" stepKey="reindexInvalidatedIndices"/>
80+
</after>
81+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin1"/>
82+
<amOnPage url="{{AdminProductEditPage.url($$createConfigChildProduct1.id$$)}}" stepKey="openProductEditPageToSetStatus"/>
83+
<selectOption selector="{{AdminProductFormSection.productStockStatus}}" userInput="Out of Stock" stepKey="selectOutOfStockStatus"/>
84+
<actionGroup ref="AdminFormSaveAndCloseActionGroup" stepKey="saveProductWithSetOutOfStockStatus"/>
85+
<!-- Go to configurable product page -->
86+
<amOnPage url="/{{ApiConfigurableProduct.urlKey}}2.html" stepKey="goToConfigProductPage"/>
87+
<waitForPageLoad stepKey="waitForProductPageLoad"/>
88+
<!-- Assert the out of stock child product option is disabled on storefront -->
89+
<seeElement selector="#product-options-wrapper .super-attribute-select option:disabled" stepKey="assertConfigAttributeOption1Disabled"/>
90+
</test>
91+
</tests>

app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,27 @@ define([
498498
$widget._EmulateSelected($widget._getSelectedAttributes());
499499
},
500500

501+
disableSwatchForOutOfStockProducts: function () {
502+
let $widget = this, container = this.element;
503+
504+
$.each(this.options.jsonConfig.attributes, function () {
505+
let item = this;
506+
507+
if ($widget.options.jsonConfig.canDisplayShowOutOfStockStatus) {
508+
let salableProducts = $widget.options.jsonConfig.salable[item.id],
509+
swatchOptions = container.find('.swatch-option');
510+
511+
swatchOptions.each(function (key, value) {
512+
let optionId = $(value).data('option-id');
513+
514+
if (!salableProducts.hasOwnProperty(optionId)) {
515+
$(value).attr('disabled', true).addClass('disabled');
516+
}
517+
});
518+
}
519+
});
520+
},
521+
501522
/**
502523
* Render swatch options by part of config
503524
*
@@ -888,6 +909,7 @@ define([
888909
.attr('disabled', true)
889910
.addClass('disabled')
890911
.attr('tabindex', '-1');
912+
this.disableSwatchForOutOfStockProducts();
891913
},
892914

893915
/**

0 commit comments

Comments
 (0)