我已经用了 贝宝/付款费扩展 为付款方式添加费用。

enter image description here

问题是未计算税收(21%)的付款费用。该插件不支持它。您能给我一些提示,我如何扩展插件,以便计算出付款费用并包含在税收行中(可以在图像中看到)。

编辑:我相信,这是我需要修改收集方法的课程:

class FlyWebdesign_PaypalFee_Model_Sales_Quote_Address_Total_Paymentcharge extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
    public function __construct()
    {
        $this->setCode('payment_charge');
    }

    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        $address->setPaymentCharge(0);
        $address->setBasePaymentCharge(0);

        $items = $address->getAllItems();
        if (!count($items)) {
            return $this;
        }

        $paymentMethod = $address->getQuote()->getPayment()->getMethod();
        if ($paymentMethod) { 
            $amount = Mage::helper('paymentcharge')->getPaymentCharge($paymentMethod, $address->getQuote());
            $address->setPaymentCharge($amount);
            $address->setBasePaymentCharge($amount);
        }

        $address->setGrandTotal($address->getGrandTotal() + $address->getPaymentCharge());
        $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentCharge());
        return $this;
    }

    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        $amount = $address->getPaymentCharge();
        if (($amount!=0)) {
            $address->addTotal(array(
                'code' => $this->getCode(),
                'title' => Mage::helper('sales')->__('Payment Charge'),
                'full_info' => array(),
                'value' => $amount
            ));
        }
        return $this;
    }
}

可能还需要定制这些类:

FlyWebdesign_PaypalFee_Model_Sales_Order_Creditmemo_Total_Paymentcharge
FlyWebdesign_PaypalFee_Model_Sales_Order_Invoice_Total_Paymentcharge
有帮助吗?

解决方案

好吧,这就是我得到的

我已经修改了flywebdesign_paypalfee_model_sales_quote_ address_total_paymentcharge(例如

<?php

/**
 * @category   FlyWebdesign
 * @package    FlyWebdesign_PaypalFee
 */
class FlyWebdesign_PaypalFee_Model_Sales_Quote_Address_Total_Paymentcharge extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
    protected $_calculator = null;

    public function __construct()
    {
        $this->setCode('payment_charge');
        $this->_calculator  = Mage::getSingleton('tax/calculation');
    }

    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        $address->setPaymentCharge(0);
        $address->setBasePaymentCharge(0);

        $items = $address->getAllItems();
        if (!count($items)) {
            return $this;
        }

        $paymentMethod = $address->getQuote()->getPayment()->getMethod();
        if ($paymentMethod) { 
            $amount = Mage::helper('paymentcharge')->getPaymentCharge($paymentMethod, $address->getQuote());
            $address->setPaymentCharge($amount);
            $address->setBasePaymentCharge($amount);

            /* clime: tax calculation start */
            $calc               = $this->_calculator;
            $store              = $address->getQuote()->getStore();
            $addressTaxRequest  = $calc->getRateRequest(
                $address->getQuote()->getShippingAddress(),
                $address->getQuote()->getBillingAddress(),
                $address->getQuote()->getCustomerTaxClassId(),
                $store
            );

            $paymentTaxClass = Mage::getStoreConfig('payment/'.$paymentMethod.'/payment_tax_class');
            $addressTaxRequest->setProductClassId($paymentTaxClass);

            $rate          = $calc->getRate($addressTaxRequest);
            $taxAmount     = $calc->calcTaxAmount($amount, $rate, false, true);
            $baseTaxAmount = $calc->calcTaxAmount($amount, $rate, false, true);

            $address->setPaymentTaxAmount($taxAmount);
            $address->setBasePaymentTaxAmount($baseTaxAmount);

            $address->setTaxAmount($address->getTaxAmount() + $taxAmount);
            $address->setBaseTaxAmount($address->getBaseTaxAmount() + $baseTaxAmount);
            /* clime: tax calculation end */
        }
        //clime: tax added
        $address->setGrandTotal($address->getGrandTotal() + $address->getPaymentCharge() + $address->getPaymentTaxAmount());
        //clime: tax added
        $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentCharge() + $address->getBasePaymentTaxAmount()); 

        return $this;
    }

    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        $amount = $address->getPaymentCharge();
        if (($amount!=0)) {
            $address->addTotal(array(
                'code' => $this->getCode(),
                'title' => Mage::helper('sales')->__('Payment Charge'),
                'full_info' => array(),
                'value' => $amount
            ));
        }
        return $this;
    }
}

我已经修改了插件的system.xml,以增加付款费的管理现场税类。接下来,我实际上并没有像以前想到的那样更改插件的creditme_total_paymentardar和iveoice_total_paymentcharge,但是我已经在plugin的config.xml中添加了以下重写(在模型部分):

        <sales>
            <rewrite>
                <order_invoice_total_tax>FlyWebdesign_PaypalFee_Model_Sales_Order_Invoice_Total_Tax</order_invoice_total_tax>
                <order_creditmemo_total_tax>FlyWebdesign_PaypalFee_Model_Sales_Order_Creditmemo_Total_Tax</order_creditmemo_total_tax>
            </rewrite>
        </sales>

在这两个新文件(原始Magento源文件的副本 - 其中之一是:/app/code/core/mage/sales/model/model/model/order/invoice/total/tax.php),我已将以下内容添加到Collect中order_invoice_total_tax的方法:

    if ($this->_canIncludePaymentTax($invoice)) {
        $totalTax           += $order->getPaymentTaxAmount();
        $baseTotalTax       += $order->getBasePaymentTaxAmount();
        $invoice->setPaymentTaxAmount($order->getPaymentTaxAmount());
        $invoice->setBasePaymentTaxAmount($order->getBasePaymentTaxAmount());
    }

我还将此方法添加到了课堂上。

protected function _canIncludePaymentTax($invoice)
{
    $includePaymentTax = true;
    /**
     * Check payment amount in previous invoices
     */
    foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
        if ($previusInvoice->getPaymentAmount() && !$previusInvoice->isCanceled()) {
            $includePaymentTax = false;
        }
    }
    return $includePaymentTax;
}

我已经将其添加到其他类订单的收集方法中

if ($invoice = $creditmemo->getInvoice()) {
    $paymentTaxAmount     = $invoice->getPaymentTaxAmount();
    $basePaymentTaxAmount = $invoice->getBasePaymentTaxAmount();
    $totalTax            += $paymentTaxAmount;
    $baseTotalTax        += $basePaymentTaxAmount;
} else {
    $paymentTaxAmount     = $order->getPaymentTaxAmount();
    $basePaymentTaxAmount = $order->getBasePaymentTaxAmount();
    $totalTax            += $paymentTaxAmount;
    $baseTotalTax        += $basePaymentTaxAmount;
}
$creditmemo->setPaymentTaxAmount($paymentTaxAmount);
$creditmemo->setBasePaymentTaxAmount($basePaymentTaxAmount);

我还需要为插件制作以下SQL升级脚本

<?php
/* @var $installer Mage_Customer_Model_Entity_Setup */

$installer = $this;
$installer->startSetup();

$installer->addAttribute('quote_address', 'payment_tax_amount', array('type' => 'decimal'));
$installer->addAttribute('quote_address', 'base_payment_tax_amount', array('type' => 'decimal'));
$installer->addAttribute('order', 'payment_tax_amount', array('type' => 'decimal'));
$installer->addAttribute('order', 'base_payment_tax_amount', array('type' => 'decimal'));
$installer->addAttribute('invoice', 'payment_tax_amount', array('type' => 'decimal'));
$installer->addAttribute('invoice', 'base_payment_tax_amount', array('type' => 'decimal'));
$installer->addAttribute('creditmemo', 'payment_tax_amount', array('type' => 'decimal'));
$installer->addAttribute('creditmemo', 'base_payment_tax_amount', array('type' => 'decimal'));

$installer->endSetup();

然后我将其添加到插件的config.xml-部分 <fieldsets><sales_convert_quote_address>

        <payment_tax_amount><to_order>*</to_order></payment_tax_amount>
        <base_payment_tax_amount><to_order>*</to_order></base_payment_tax_amount>

就我的测试而言,这对我有用。但是,我仍然想解决一些未解决的(潜在的)麻烦。

  • 如果基本货币不是存储货币,则可能具有指定付款金额的潜在问题(不确定在这种情况下Magento的行为如何)

  • 始终考虑在管理员中指定的金额排除税款(没有选择更改)

  • 付款费的税费不会以全部税收摘要(如果启用)为一行

顺便说一句,我的Magento版本是1.7.0.2

其他提示

我找到了我的解决方案,用于类似的开发人员。

有一个

    $this->_addAmount($address->getExtraTaxAmount());
    $this->_addBaseAmount($address->getBaseExtraTaxAmount());

在mage_tax_model_sales_total_quote_tax中

所以请打电话

    $address->setExtraTaxAmount($address->getExtraTaxAmount() + $taxFeeAmount);
    $address->setBaseExtraTaxAmount($address->getBaseExtraTaxAmount() + $taxBaseFeeAmount);

在您的自定义总计中

嗯,搜索解决方案也许更好。

  1. 您可以修改Magento购物车价格规则,以添加折扣的费用 http://php.quicoto.com/extra-fee-shopping-cart-price-rules-magento/

  2. 然后,您可以添加一个规则说:如果付款方式是,请向购物车添加费用。该费用将与您的付款费用相同。您可以翻译该字段。

这样,也将计算费用。

许可以下: CC-BY-SA归因
scroll top