I want to redirect to cart page after adding the product into cart, I know there is a provision in config but I have a custom product type and that config is not working for that product.

That configuration setting is working for simple and other products but not for the custom product type.

So Is there any way I can do this thing programmatically using plugins or anything else.

2 Answers 2

  1. app/code/Vendor/Module/etc/frontend/di.xml

    <?xml version="1.0"?>
        <type name="Magento\Checkout\Controller\Cart\Add">
            <plugin name="interceptAddProductToCartRedirect" type="Vendor\Module\Plugin\Checkout\Cart\Add" sortOrder="1" disabled="false"/>
  2. app/code/Vendor/Module/Plugin/Checkout/Cart/Add.php

    namespace Vendor\Module\Plugin\Checkout\Cart;
    use Magento\Framework\UrlInterface;
    use Magento\Framework\App\Request\Http;
    use Psr\Log\LoggerInterface;
    class Add
        protected $url;
        protected $request;
        protected $logger;
        public function __construct(
            UrlInterface $url,
            Http $request,
            LoggerInterface $logger
            $this->_url = $url;
            $this->_request = $request;
            $this->_logger = $logger;
         * Redirect to checkout/cart after Adding product to cart
         * @param \Magento\Checkout\Controller\Cart\Add $subject
         * @param \Closure $proceed
         * @return mixed
        public function aroundExecute(\Magento\Checkout\Controller\Cart\Add $subject, \Closure $proceed)
            $result = $proceed();
            $this->_logger->info("Add to cart plugin OK");
            if (!$this->_request->isAjax()) {
                return $result;
            return $result;
  3. app/code/Vendor/Module/view/frontend/layout/catalog_product_view.xml

    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <referenceBlock name="product.info.addtocart">
                <action method="setTemplate">
                    <argument name="template" xsi:type="string">Vendor_Module::product/view/addtocart.phtml</argument>
  4. copy addtocart.phtml from :


    into :


    then add "bindSubmit": true like this :

    <script type="text/x-magento-init">
        "#product_addtocart_form": {
            "Magento_Catalog/js/validate-product": {
                "bindSubmit": true, <!-- HERE -->

  5. generate DI configuration & flush cache storage

    php bin/magento s:d:c
    php bin/magento c:f

    Good luck.


please refere the below links. This may help you.


How can I redirect to the cart page programmatically?

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.