我按照本教程中创建付款方式的步骤(http://www.magentocommerce.com/wiki/5_-_modules_and_development/payment/create-payment-method-module),一切正常,但我需要额外的功能。
我也使用这个模块 - http://www.magentocommerce.com/magento-connect/payment-method-charge-4050.html但我需要2个条件。这就是我创建新付款方式的原因。
提前致谢。
答案 0 :(得分: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() );
}
}
取自本文:
更多关于如何创建观察者的阅读材料:
答案 1 :(得分: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');
}
}
}
}