Skip to content

Add to Cart broken on lists view with redirect to cart enabled. #32301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<element name="ProductPriceByName" type="text" selector="//*[@id='product-comparison']//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var1}}')]]//span[@class='price']" parameterized="true"/>
<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"/>
<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"/>
<element name="ProductAddToCartButton" type="button" selector=".product-item-photo[title='{{productName}}'] ~ .product-item-actions button[type='submit']" parameterized="true" timeout="30"/>
<element name="removeFirstItem" type="button" selector="table.table-comparison a.delete"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
action="<?= $block->escapeUrl($this->helper(Magento\Catalog\Helper\Product\Compare::class)->getAddToCartUrl($item)) ?>"
method="post">
<?= $block->getBlockHtml('formkey') ?>
<button type="submit" class="action tocart primary">
<button type="submit" class="action tocart primary" disabled>
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
</button>
</form>
Expand Down Expand Up @@ -144,15 +144,13 @@
</tbody>
</table>
</div>
<?php if (!$block->isRedirectToCartEnabled()) :?>
<script type="text/x-magento-init">
{
"[data-role=tocart-form]": {
"catalogAddToCart": {}
}
<script type="text/x-magento-init">
{
"[data-role=tocart-form]": {
"catalogAddToCart": {}
}
</script>
<?php endif; ?>
}
</script>
<?php else :?>
<div class="message info empty"><div><?= $block->escapeHtml(__('You have no items to compare.')) ?></div></div>
<?php endif; ?>
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,13 @@ $_helper = $block->getData('outputHelper');
</ol>
</div>
<?= $block->getToolbarHtml() ?>
<?php if (!$block->isRedirectToCartEnabled()): ?>
<script type="text/x-magento-init">
{
"[data-role=tocart-form], .form.map.checkout": {
"catalogAddToCart": {
"product_sku": "<?= $escaper->escapeJs($_product->getSku()) ?>"
}
<script type="text/x-magento-init">
{
"[data-role=tocart-form], .form.map.checkout": {
"catalogAddToCart": {
"product_sku": "<?= $escaper->escapeJs($_product->getSku()) ?>"
}
}
</script>
<?php endif; ?>
}
</script>
<?php endif; ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<!-- Add Product to Cart from the category page and check message -->
<actionGroup name="StorefrontAddSimpleProductToCartFromComparisonListActionGroup">
<annotations>
<description>Add simple product from comparison page to the cart. Starts on products comparison page.</description>
</annotations>
<arguments>
<argument name="productName" type="string" defaultValue="{{SimpleProduct.name}}"/>
</arguments>

<waitForElement selector="{{StorefrontProductCompareMainSection.ProductAddToCartButton(productName)}}" stepKey="waitForAddToCartButton"/>
<click selector="{{StorefrontProductCompareMainSection.ProductAddToCartButton(productName)}}" stepKey="clickAddToCartButton"/>
<waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/>
<see selector="{{StorefrontMessagesSection.success}}" userInput="You added {{productName}} to your shopping cart." stepKey="assertSuccessMessage"/>
</actionGroup>
</actionGroups>
14 changes: 13 additions & 1 deletion app/code/Magento/Checkout/Test/Mftf/Data/CheckoutConfigData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,16 @@
<data key="label">No</data>
<data key="value">0</data>
</entity>
</entities>
<entity name="EnableRedirectToShoppingCart">
<data key="path">checkout/cart/redirect_to_cart</data>
<data key="scope_id">0</data>
<data key="label">Yes</data>
<data key="value">1</data>
</entity>
<entity name="DisableRedirectToShoppingCart">
<data key="path">checkout/cart/redirect_to_cart</data>
<data key="scope_id">0</data>
<data key="label">No</data>
<data key="value">0</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontAddSimpleProductToCartWithRedirectToShoppingCartTest">
<annotations>
<stories value="Shopping Cart"/>
<features value="Checkout"/>
<title value="Add simple product to shopping cart with 'redirect to shopping cart' enabled."/>
<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."/>
<testCaseId value="MC-41079"/>
<useCaseId value="MC-40983"/>
<severity value="CRITICAL"/>
<group value="shoppingCart"/>
<group value="checkout"/>
</annotations>

<before>
<!--Enable redirect to shopping cart.-->
<magentoCLI command="config:set {{EnableRedirectToShoppingCart.path}} {{EnableRedirectToShoppingCart.value}}" stepKey="enableRedirectToShippingCart"/>
<!--Create test data.-->
<createData entity="_defaultCategory" stepKey="category"/>
<createData entity="SimpleProduct" stepKey="product">
<requiredEntity createDataKey="category"/>
</createData>
</before>
<after>
<!--Disable redirect to shopping cart.-->
<magentoCLI command="config:set {{DisableRedirectToShoppingCart.path}} {{DisableRedirectToShoppingCart.value}}" stepKey="disableRedirectToShippingCart"/>
<!--Delete test data.-->
<deleteData createDataKey="product" stepKey="deleteSimpleProduct"/>
<deleteData createDataKey="category" stepKey="deleteCategory"/>
<magentoCron groups="index" stepKey="reindexInvalidatedIndices"/>
</after>

<!--Try to add simple product to shopping cart.-->
<actionGroup ref="StorefrontNavigateToCategoryUrlActionGroup" stepKey="goToCategoryPage">
<argument name="categoryUrl" value="$category.custom_attributes[url_key]$"/>
</actionGroup>
<actionGroup ref="StorefrontAddSimpleProductToCartActionGroup" stepKey="addProductToCart">
<argument name="product" value="$product$"/>
</actionGroup>
<seeInCurrentUrl url="{{CheckoutCartPage.url}}" stepKey="verifyCartRedirectAfterAddingProductFromCategoryPage"/>
<!-- Add product to compare list -->
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
<argument name="productUrl" value="$product.custom_attributes[url_key]$"/>
</actionGroup>
<actionGroup ref="StorefrontAddProductToCompareActionGroup" stepKey="addProductToCompare">
<argument name="productVar" value="$product$"/>
</actionGroup>
<!--Try to add simple product to shopping cart from compare products page.-->
<actionGroup ref="SeeProductInComparisonListActionGroup" stepKey="checkProductInComparisonList">
<argument name="productVar" value="$product$"/>
</actionGroup>
<actionGroup ref="StorefrontAddSimpleProductToCartFromComparisonListActionGroup" stepKey="addProductToCartFromComparisonList">
<argument name="productName" value="$product.name$"/>
</actionGroup>
<seeInCurrentUrl url="{{CheckoutCartPage.url}}" stepKey="verifyCartRedirectAfterAddingProductFromComparisonList"/>
</test>
</tests>