我想根据选择的付款方式收取额外费用。我在magento 1中使用了以下模块 https://github.com/manishiitg/excellence_magento_blog/tree/master/Fee%20Module/app
magento 2是否有类似的模块。
答案 0 :(得分:3)
我们可以在Magento 2中使用具有特定费用模块的付款:https://github.com/mrkhoa99/Boolfly_payment_fee
此模块将创建具有特定费用的货到付款模块。我们可以按照this guide创建您自己的模块。
答案 1 :(得分:2)
首先,您需要在此链接中探索如何在magento2中为订单总计添加费用的完整过程:https://magento.stackexchange.com/questions/92774/how-to-add-fee-to-order-totals-in-magento2 在那之后 : 创建di.xml并推送exmaple:
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Model\Order">
<plugin name="update_payment_fee_order" type="Ibnab\PF\Plugin\UpdateFeeForOrder"/>
</type>
<type name="Magento\Paypal\Model\Cart">
<plugin name="update_paypal_fee_order" type="Ibnab\PF\\Plugin\UpdateFeeForOrder"/>
</type>
</config>
用于创建插件并注入afterGetAmounts($ cart,$ result)和beforeGetAllItems($ cart)
<?php
namespace Ibnab\PF\Plugin;
class UpdateFeeForOrder
{
/**
* @var \Magento\Quote\Model\QuoteFactory
*/
protected $quote;
protected $logger;
protected $_checkoutSession;
protected $_registry;
const AMOUNT_Payment = 'payment_fee';
const AMOUNT_SUBTOTAL = 'subtotal';
public function __construct(
\Magento\Quote\Model\Quote $quote,
\Psr\Log\LoggerInterface $logger,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\Registry $registry
) {
$this->quote = $quote;
$this->logger = $logger;
$this->_checkoutSession = $checkoutSession;
$this->_registry = $registry;
}
/**
* Get shipping, tax, subtotal and discount amounts all together
*
* @return array
*/
public function afterGetAmounts($cart,$result)
{
$total = $result;
$quote = $this->_checkoutSession->getQuote();
$paymentMethod = $quote->getPayment()->getMethod();
$paypalMehodList = ['payflowpro','payflow_link','payflow_advanced','braintree_paypal','paypal_express_bml','payflow_express_bml','payflow_express','paypal_express'];
if(in_array($paymentMethod,$paypalMehodList)){
$total[self::AMOUNT_SUBTOTAL] = $total[self::AMOUNT_SUBTOTAL] + $quote->getFeeAmount();
}
return $total;
}
/**
* Get shipping, tax, subtotal and discount amounts all together
*
* @return array
*/
public function beforeGetAllItems($cart)
{
$paypalTest = $this->_registry->registry('is_paypal_items')? $this->_registry->registry('is_paypal_items') : 0;
$quote = $this->_checkoutSession->getQuote();
$paymentMethod = $quote->getPayment()->getMethod();
$paypalMehodList = ['payflowpro','payflow_link','payflow_advanced','braintree_paypal','paypal_express_bml','payflow_express_bml','payflow_express','paypal_express'];
if($paypalTest < 3 && in_array($paymentMethod,$paypalMehodList)){
if(method_exists($cart , 'addCustomItem' ))
{
$cart->addCustomItem(__("Payment Fee"), 1 ,$quote->getFeeAmount());
$reg = $this->_registry->registry('is_paypal_items');
$current = $reg + 1 ;
$this->_registry->unregister('is_paypal_items');
$this->_registry->register('is_paypal_items', $current);
}
}
}
}
这里完整的修改我们测试并添加费用paypal到金额和添加费用作为自定义项目请求paypal, 竞赛课程在Magento 2 Paypal Fee (charge) and life cycle
内答案 2 :(得分:0)
您需要通过使用Magento_Checkout/js/action/select-payment-method
define(
[
'jquery',
'ko',
'Magento_Checkout/js/model/quote',
'Mageprince_Paymentfee/js/action/checkout/cart/totals'
],
function($, ko ,quote, totals) {
'use strict';
var isLoading = ko.observable(false);
return function (paymentMethod) {
quote.paymentMethod(paymentMethod);
totals(isLoading, paymentMethod['method']);
}
});
这里是完整的源代码,具有很多功能,例如在小计中添加运输/折扣,添加任意数量的付款方式费用,按特定税种分类的卡克鲁蒂税等。