The add to cart function is not working for configurable products on product listing page.

When selecting the configurable product options(color,size) of the product and then trying to add the product to the cart, the cart is not updating and instead I'm redirected to the product detail page.

The configurable products need to be added to the cart when on the product listing page rather than redirecting to the product detail page.

There are no errors in the console and the Network tab is also showing no errors.

After redirecting to product detail page a message appears on top that you need to select options for your item.I have already chosen the required options. enter image description here

Thanks in advance.

  • If you are redirected to the product detail it seems like not all the configurations are selected the attributes needed are selected is not in stock but it should return an error message
    – Vlad Patru
    Commented Mar 15, 2018 at 10:21

2 Answers 2


You will need to create the form on listings page for add to cart.

<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
                                                    <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
                                                    <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
                                                    <?php echo $block->getBlockHtml('formkey')?>

                                                    <button type="submit"
                                                            title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
                                                            class="btn btn-primary action tocart">
                                                        <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>

Configureabe products are combination of different variation ( i.e size, color etc ) so unless you don't select any variation you won't be able to add product into cart.

So show production configurable attributes on listing page for each product ( check default luma theme ) then customer would be able to select size / color and add to cart from listing page, but if she doesn't select any variation user will be redirected to detail page.

  • Ya even after selecting the options (color,size) i am still being redirected to product detail page.
    – a.no.one
    Commented Mar 15, 2018 at 9:53
  • did you try in different browser ? Commented Mar 15, 2018 at 9:54
  • Yes.Chrome,Firefox and safari.
    – a.no.one
    Commented Mar 15, 2018 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.