How to redirect on checkout page, after add to cart click on bundle product?
-
14-03-2021 - |
문제
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.
해결책
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
.
제휴하지 않습니다 magento.stackexchange