【问题标题】:Magento 2.3 adding coupon code on a custom payment pageMagento 2.3 在自定义支付页面上添加优惠券代码
【发布时间】:2020-07-05 02:50:36
【问题描述】:

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

我的 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));
  .
  .
  .
  }

感谢您的任何帮助亲! 如果需要更多详细信息,请告诉我。

【问题讨论】:

    标签: php magento magento2 payment coupon


    【解决方案1】:

    试试这个方法。参考[github: crankycyclops]

    public function __construct(
    \Magento\Checkout\Model\Session $checkoutSession,
    ...
    $this->checkoutSession = $checkoutSession;
    }
    ...
    
    $quote = $this->checkoutSession->getQuote();
    $quote->setCouponCode($coupon);
    $this->quoteRepository->save($quote->collectTotals());
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      相关资源
      最近更新 更多