繁体   English   中英

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

[英]Magento 2.3 adding coupon code on a custom payment page

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

我的 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:crucycyclops]

public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
...
$this->checkoutSession = $checkoutSession;
}
...

$quote = $this->checkoutSession->getQuote();
$quote->setCouponCode($coupon);
$this->quoteRepository->save($quote->collectTotals());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM