Skip to content

Commit 373c220

Browse files
committed
MC-40983: Add to Cart broken on lists view with redirect to cart enabled.
1 parent d3f202a commit 373c220

File tree

6 files changed

+117
-19
lines changed

6 files changed

+117
-19
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
<element name="ProductPriceByName" type="text" selector="//*[@id='product-comparison']//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var1}}')]]//span[@class='price']" parameterized="true"/>
1515
<element name="ProductImageByName" type="text" selector="//*[@id='product-comparison']//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var1}}')]]//img[@class='product-image-photo']" parameterized="true"/>
1616
<element name="ProductAttributeByCodeAndProductName" type="text" selector="//*[@id='product-comparison']//tr[.//th[./span[contains(text(), '{{var1}}')]]]//td[count(//*[@id='product-comparison']//tr//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var2}}')]]/preceding-sibling::td)+1]/div" parameterized="true"/>
17+
<element name="ProductAddToCartButton" type="button" selector=".product-item-photo[title='{{productName}}'] ~ .product-item-actions button[type='submit']" parameterized="true" timeout="30"/>
1718
</section>
1819
</sections>

app/code/Magento/Catalog/view/frontend/templates/product/compare/list.phtml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
action="<?= $block->escapeUrl($this->helper(Magento\Catalog\Helper\Product\Compare::class)->getAddToCartUrl($item)) ?>"
7474
method="post">
7575
<?= $block->getBlockHtml('formkey') ?>
76-
<button type="submit" class="action tocart primary">
76+
<button type="submit" class="action tocart primary" disabled>
7777
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
7878
</button>
7979
</form>
@@ -144,15 +144,13 @@
144144
</tbody>
145145
</table>
146146
</div>
147-
<?php if (!$block->isRedirectToCartEnabled()) :?>
148-
<script type="text/x-magento-init">
149-
{
150-
"[data-role=tocart-form]": {
151-
"catalogAddToCart": {}
152-
}
147+
<script type="text/x-magento-init">
148+
{
149+
"[data-role=tocart-form]": {
150+
"catalogAddToCart": {}
153151
}
154-
</script>
155-
<?php endif; ?>
152+
}
153+
</script>
156154
<?php else :?>
157155
<div class="message info empty"><div><?= $block->escapeHtml(__('You have no items to compare.')) ?></div></div>
158156
<?php endif; ?>

app/code/Magento/Catalog/view/frontend/templates/product/list.phtml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,13 @@ $_helper = $block->getData('outputHelper');
154154
</ol>
155155
</div>
156156
<?= $block->getToolbarHtml() ?>
157-
<?php if (!$block->isRedirectToCartEnabled()): ?>
158-
<script type="text/x-magento-init">
159-
{
160-
"[data-role=tocart-form], .form.map.checkout": {
161-
"catalogAddToCart": {
162-
"product_sku": "<?= $escaper->escapeJs($_product->getSku()) ?>"
163-
}
157+
<script type="text/x-magento-init">
158+
{
159+
"[data-role=tocart-form], .form.map.checkout": {
160+
"catalogAddToCart": {
161+
"product_sku": "<?= $escaper->escapeJs($_product->getSku()) ?>"
164162
}
165163
}
166-
</script>
167-
<?php endif; ?>
164+
}
165+
</script>
168166
<?php endif; ?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
<!-- Add Product to Cart from the category page and check message -->
12+
<actionGroup name="StorefrontAddSimpleProductToCartFromComparisonListActionGroup">
13+
<annotations>
14+
<description>Add simple product from comparison page to the cart. Starts on products comparison page.</description>
15+
</annotations>
16+
<arguments>
17+
<argument name="productName" type="string" defaultValue="{{SimpleProduct.name}}"/>
18+
</arguments>
19+
20+
<waitForElement selector="{{StorefrontProductCompareMainSection.ProductAddToCartButton(productName)}}" stepKey="waitForAddToCartButton"/>
21+
<click selector="{{StorefrontProductCompareMainSection.ProductAddToCartButton(productName)}}" stepKey="clickAddToCartButton"/>
22+
<waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/>
23+
<see selector="{{StorefrontMessagesSection.success}}" userInput="You added {{productName}} to your shopping cart." stepKey="assertSuccessMessage"/>
24+
</actionGroup>
25+
</actionGroups>

app/code/Magento/Checkout/Test/Mftf/Data/CheckoutConfigData.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,16 @@
3232
<data key="label">No</data>
3333
<data key="value">0</data>
3434
</entity>
35-
</entities>
35+
<entity name="EnableRedirectToShoppingCart">
36+
<data key="path">checkout/cart/redirect_to_cart</data>
37+
<data key="scope_id">0</data>
38+
<data key="label">Yes</data>
39+
<data key="value">1</data>
40+
</entity>
41+
<entity name="DisableRedirectToShoppingCart">
42+
<data key="path">checkout/cart/redirect_to_cart</data>
43+
<data key="scope_id">0</data>
44+
<data key="label">No</data>
45+
<data key="value">0</data>
46+
</entity>
47+
</entities>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<test name="StorefrontAddSimpleProductToCartWithRedirectToShoppingCartTest">
10+
<annotations>
11+
<stories value="Shopping Cart"/>
12+
<features value="Checkout"/>
13+
<title value="Add simple product to shopping cart with 'redirect to shopping cart' enabled."/>
14+
<description value="Verify, user able add simple product to shopping cart from category page and compare products page when 'redirect to shopping cart' is enabled."/>
15+
<testCaseId value="MC-41079"/>
16+
<useCaseId value="MC-40983"/>
17+
<severity value="CRITICAL"/>
18+
<group value="shoppingCart"/>
19+
<group value="checkout"/>
20+
</annotations>
21+
22+
<before>
23+
<!--Enable redirect to shopping cart.-->
24+
<magentoCLI command="config:set {{EnableRedirectToShoppingCart.path}} {{EnableRedirectToShoppingCart.value}}" stepKey="enableRedirectToShippingCart"/>
25+
<!--Create test data.-->
26+
<createData entity="_defaultCategory" stepKey="category"/>
27+
<createData entity="SimpleProduct" stepKey="product">
28+
<requiredEntity createDataKey="category"/>
29+
</createData>
30+
</before>
31+
<after>
32+
<!--Disable redirect to shopping cart.-->
33+
<magentoCLI command="config:set {{DisableRedirectToShoppingCart.path}} {{DisableRedirectToShoppingCart.value}}" stepKey="disableRedirectToShippingCart"/>
34+
<!--Delete test data.-->
35+
<deleteData createDataKey="product" stepKey="deleteSimpleProduct"/>
36+
<deleteData createDataKey="category" stepKey="deleteCategory"/>
37+
<magentoCron groups="index" stepKey="reindexInvalidatedIndices"/>
38+
</after>
39+
40+
<!--Try to add simple product to shopping cart.-->
41+
<actionGroup ref="StorefrontNavigateToCategoryUrlActionGroup" stepKey="goToCategoryPage">
42+
<argument name="categoryUrl" value="$category.custom_attributes[url_key]$"/>
43+
</actionGroup>
44+
<actionGroup ref="StorefrontAddSimpleProductToCartActionGroup" stepKey="addProductToCart">
45+
<argument name="product" value="$product$"/>
46+
</actionGroup>
47+
<seeInCurrentUrl url="{{CheckoutCartPage.url}}" stepKey="verifyCartRedirectAfterAddingProductFromCategoryPage"/>
48+
<!-- Add product to compare list -->
49+
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
50+
<argument name="productUrl" value="$product.custom_attributes[url_key]$"/>
51+
</actionGroup>
52+
<actionGroup ref="StorefrontAddProductToCompareActionGroup" stepKey="addProductToCompare">
53+
<argument name="productVar" value="$product$"/>
54+
</actionGroup>
55+
<!--Try to add simple product to shopping cart from compare products page.-->
56+
<actionGroup ref="SeeProductInComparisonListActionGroup" stepKey="checkProductInComparisonList">
57+
<argument name="productVar" value="$product$"/>
58+
</actionGroup>
59+
<actionGroup ref="StorefrontAddSimpleProductToCartFromComparisonListActionGroup" stepKey="addProductToCartFromComparisonList">
60+
<argument name="productName" value="$product.name$"/>
61+
</actionGroup>
62+
<seeInCurrentUrl url="{{CheckoutCartPage.url}}" stepKey="verifyCartRedirectAfterAddingProductFromComparisonList"/>
63+
</test>
64+
</tests>

0 commit comments

Comments
 (0)