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 番目の支払い方法 - 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 に答える