Domanda

I need to integrate small stuff.

When I will click add to cart ( bundle product ) then only product added successfully in cart page and then redirect into the checkout page.

So please let me help. Please make sure only bundle product.

È stato utile?

Soluzione

You can use observer/event at here.

Create Observer event on checkout_cart_add_product_complete.

and set return return_url to request Url as checkout page url when you doing to add to cart.

Observer class:

<?php
namespace StackExchange\Magento\Observer;

use Magento\Framework\Event\ObserverInterface;

class CheckoutCartAddProductComplete implements ObserverInterface
{

    /**
     * @var \Magento\Framework\UrlInterface
     */
    private $url;

    public function __construct(
         \Magento\Framework\UrlInterface $url      
    ) {

        $this->url = $url;
    }
    public function execute(\Magento\Framework\Event\Observer $observer) 
    {
        $product = $observer->getEvent()->getProduct();
        $request= $observer->getEvent()->getRequest();
        if($product->getTypeId() !== 'bundle'){
            return ;
        }
        /**
         * 
         */
        $checkoutUrl = $this->url->getUrl('checkout');
        $request->setParam('return_url',$checkoutUrl);
        return $this;
    }

}

Note that: This solution is work When Setting when After Adding a Product Redirect to Shopping Cart = Yes.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top