自定义折扣,PayPal实际扣款并没有计算实际折扣
自定义折扣,PayPal实际扣款并没有计算实际折扣
自定义折扣的代码,主要按照https://www.mageplaza.com/devdocs/how-add-custom-discount-magento-2.html写的.
核心代码为:
public function collect(
MagentoQuoteModelQuote $quote,
MagentoQuoteApiDataShippingAssignmentInterface $shippingAssignment,
MagentoQuoteModelQuoteAddressTotal $total
){
parent::collect($quote, $shippingAssignment, $total);
//按等级折扣
$info = SansiLocalHelperCustomer::getCache($quote->getCustomerId());
$discount = array_get($info, 'discount', 1);
$level = array_get($info, 'level');
if($discount != 1){
if($level > 0){
$label = 'Sansi Level' . $level;
}else{
$label = 'First Order';
}
//在现有折后总价上,继续打折
$sansiDiscount = round($total->getSubtotalWithDiscount() * (1 - $discount), 2);
$discountCurrency = $this->_priceCurrency->convert($sansiDiscount);
$total->addTotalAmount($label, -$discountCurrency);
$total->addBaseTotalAmount($label, -$sansiDiscount);
$total->setBaseGrandTotal($total->getBaseGrandTotal() - $sansiDiscount);
$quote->setCustomDiscount(-$discountCurrency);
$discountAmount = $total->getDiscountAmount() - $sansiDiscount;
$label = $total->getDiscountDescription() ? $total->getDiscountDescription().', '.$label : $label;
$total->setDiscountDescription($label);
$total->setDiscountAmount($discountAmount);
}
return $this;
}
实际效果,前端页面上按客户等级,出现了折扣:

支付后,后台查看预付款状态下的订单:

后台点击invoice,此处结算未计算自定义折扣:
点击 submit Invoice,实际收款后,订单实际支付金额为折扣前金额:

这个问题,上线前没有测出来,所以现在很抓狂.请各位大佬赐教.
maidoubaba 已回答

