1

I need to redirect the specific product page when i click the add to cart button in the category page. instead of add the product to the shopping cart in magento 2.3.2

If anyone know the answer please share the exact code and folder structure since i'm new to magento.

enter image description here

1 Answer 1

2

you just need to override list.phtml file in your theme

app/design/frontend/Vendor/Theme/Magento_Catalog/templates/product/list.phtml

and replace the code below:

From

<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form"
      data-product-sku="<?= $block->escapeHtml($_product->getSku()) ?>"
      action="<?= $block->escapeUrl($postParams['action']) ?>"
      method="post">
    <input type="hidden"
           name="product"
           value="<?=  $postParams['data']['product'] ?>">
    <input type="hidden" name="<?=  Action::PARAM_NAME_URL_ENCODED ?>"
           value="<?=  $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
    <?= $block->getBlockHtml('formkey') ?>
    <button type="submit"
            title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>"
            class="action tocart primary">
        <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
    </button>
</form>

To

<button title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>"
        class="action primary">
    <a href="<?= $_product->getProductUrl() ?>"><span><?= $block->escapeHtml(__('Add to Cart')) ?></span></a>
</button>

Hope this will help you!

3
  • Hello Naresh, I have copied core list.phtml file code and replaced the code which you have shared. but still if i click the add to cart button, add the product to the shopping cart. instead of open the specific product.
    – Ramesh R
    Commented Dec 11, 2019 at 14:07
  • Code updated. please check with updated code and let me know it's working for you or not Commented Dec 12, 2019 at 2:35
  • thank you naresh. it's working fine.
    – Ramesh R
    Commented Dec 12, 2019 at 7:35

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.