Magento 2.3在自定义付款页面上添加优惠券代码



我有一个自定义支付页面(用户没有看到购物车页面,他们直接转到自定义支付页面(,我想在页面中添加优惠券字段,但不知道如何进行。

我的payment.php文件有一个执行功能,将项目添加到购物车中:

public function execute()
{
.
.
.
$this->cart->truncate();
$quote = $this->cart->getQuote();
$item = $this->addPricingPlanToCart($pricingPlan, $product->getId());
$quote = $this->cart->getQuote();
$this->quoteRepository->save($quote);
$logger->info("Final ".print_r($this->cart->getQuote()->getGrandTotal(),true));
.
.
.
}

谢谢你的任何帮助专业!如果需要更多细节,请告诉我。

试试这种方法。参考[github:曲柄ycycycops]

public function __construct(
MagentoCheckoutModelSession $checkoutSession,
...
$this->checkoutSession = $checkoutSession;
}
...
$quote = $this->checkoutSession->getQuote();
$quote->setCouponCode($coupon);
$this->quoteRepository->save($quote->collectTotals());

最新更新