2016-02-09 83 views
2

我想根據所選付款方式收取額外費用。我用下面的模塊做在Magento 1
https://github.com/manishiitg/excellence_magento_blog/tree/master/Fee%20Module/app如何收取Magento 2付款費

是否有Magento的2

+0

這是Magento 2的一個類似模塊:https://www.magestyapps.com/magento-2-extensions/payment-fees-m2.html – MagestyApps

+0

這一個在Magento 2中爲我工作 - https:// www .scommerce-mage.co.uk/magento2-surcharge-or-additional-fee.html – stevensagaar

+0

看看這個支付網關的附加費用延期費用https://magecomp.com/magento-2-surcharge.html –

回答

2

我們可以使用在特定的費用模塊付款Magento 2:https://github.com/mrkhoa99/Boolfly_payment_fee

該模塊將創建一個具有特定費用的貨到付款模塊。我們可以關注this guide來創建您自己的模塊。

+0

我們如何將這添加到其他付款方式 – Kevin

+0

@Kevin我升級了我的模塊。你可以再次檢查。 –

+0

謝謝Khoa ...我已經安裝了你的模塊並進行了定製。 我會試試這個新模塊。 – Kevin

1

首先,你需要探索如何添加費訂購magento2總數的完整過程類似模塊在此鏈接:https://magento.stackexchange.com/questions/92774/how-to-add-fee-to-order-totals-in-magento2 後認爲: 創建di.xml,推動〔實施例:

<?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($車,$結果),並beforeGetAllItems($車)

<?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自定義項目, 的競爭當然是裏面Magento 2 Paypal Fee (charge) and life cycle

+0

這並沒有給出完整的答案,提供全面解決方案的答案,否則將其刪除。 – stevensagaar

+0

你說什麼,你有第一個鏈接到完整的解決方案,並使用貝寶費用簡單的技術... – Ibnab

+0

完整的解決方案是購買你的模塊,它不回答這個問題,請刪除它或回答與問題詳細信息 – stevensagaar