1

我按照本教程(http://www.magentocommerce.com/wiki/5_-_modules_and_development/payment/create-payment-method-module)中创建付款方式的步骤操作一切正常,但我需要额外的功能。

  • 如果选择付款方式,则在总额中额外收取 6% 的费用。

我也使用这个模块 - http://www.magentocommerce.com/magento-connect/payment-method-charge-4050.html但我需要 2 个条件。这就是我创建新付款方式的原因。

  • 第一种付款方式 - 6% 的费用
  • 第二种付款方式 - 2% 的费用

提前致谢。

4

2 回答 2

1

您很可能只想创建一个观察者来做您需要的事情:

您需要四处寻找要挂钩的正确观察者事件,但是这里有一个示例观察者方法:

public function updateShippingAmount( $observer )
{
   $MyPaymentMethod = Mage::getSingleton('namespace/mypaymentmethod');

   $order = $observer->getEvent()->getOrder();
   $payment = $order->getPayment()->getData();

   if( $payment['method'] == $MyPaymentMethod->getCode() )
   {
       $shipping_amount =  $order->getShippingAmount();
       $order->setShippingAmount( $shipping_amount + $MyPaymentMethod->getPostHandlingCost() );
   }
}

取自这篇文章:

更多关于如何创建观察者的阅读:

于 2012-04-30T15:52:25.883 回答
1

最近我有同样的要求,我通过实现事件观察器方法来解决。
事实上,您可以通过实现称为事件的任何条件为任何运输方法添加任何额外的运输成本,sales_quote_collect_totals_before
并且观察者模型方法(虽然是虚拟代码)看起来像:

public function salesQuoteCollectTotalsBefore(Varien_Event_Observer $observer)
    {
        /**@var Mage_Sales_Model_Quote $quote */
        $quote = $observer->getQuote();
        $someConditions = true; //this can be any condition based on your requirements
        $newHandlingFee = 15;
        $store    = Mage::app()>getStore($quote>getStoreId());
        $carriers = Mage::getStoreConfig('carriers', $store);
        foreach ($carriers as $carrierCode => $carrierConfig) {
            if($carrierCode == 'fedex'){
                if($someConditions){
                    Mage::log('Handling Fee(Before):' . $store->getConfig("carriers/{$carrierCode}/handling_fee"), null, 'shipping-price.log');
                    $store->setConfig("carriers/{$carrierCode}/handling_type", 'F'); #F - Fixed, P - Percentage                  
                    $store->setConfig("carriers/{$carrierCode}/handling_fee", $newHandlingFee);

                    ###If you want to set the price instead of handling fee you can simply use as:
                    #$store->setConfig("carriers/{$carrierCode}/price", $newPrice);

                    Mage::log('Handling Fee(After):' . $store->getConfig("carriers/{$carrierCode}/handling_fee"), null, 'shipping-price.log');
                }
            }
        }
    }
于 2014-01-06T12:50:33.780 回答