自定义折扣,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 已回答
按这个教程下来。我没有支付成功(paypal快捷支付)!也很抓狂啊
'response' =>
array (
'TIMESTAMP' => '2021-11-20T07:08:29Z',
'CORRELATIONID' => 'd27248b8461d5',
'ACK' => 'Failure',
'VERSION' => '72.0',
'BUILD' => '56144363',
'L_ERRORCODE0' => '10413',
'L_SHORTMESSAGE0' => 'Transaction refused because of an invalid argument. See additional error messages for details.',
'L_LONGMESSAGE0' => 'The totals of the cart item amounts do not match order amounts.',
'L_SEVERITYCODE0' => 'Error',
),
) [] []
maidoubaba 已回答