I am using Magento 1.4.1.1 and i want to disable payment option for some products.i want to show only Cash on Delivery method for some products and need to hide other.
First create a product attribute (name : 'magepal_payment_filter_by_product', type : yes/no) to identify these products.
E.g base of Magento v1.7 you could
Auto enable payment module programmatically see https://stackoverflow.com/a/14023210/1191288
Enable all applicable payment module and filter which module to show where
In /app/code/local/MagePal/PaymentFilterByProduct/etc/config.xml
1.0.1
MagePal_PaymentFilterByProduct_Helper
MagePal_PaymentFilterByProduct_Helper_Payment_Data
In /app/code/local/MagePal/PaymentFilterByProduct/Helper/Payment/Data.php
getStore()) || !$quote){
return $methods;
}
//get a list of product in cart
$cart = Mage::getSingleton('checkout/session');
$specialProductInCart = array();
foreach ($cart->getQuote()->getAllItems() as $item) {
$specialProductInCart[] = $item->getMagepalPaymentFilterByProduct();
}
// if special product in cart
// need to if check $item->getMagepalPaymentFilterByProduct() return 'yes/no' or '0/1)
if(in_array('yes', $specialProductInCart)){
$filter_csv = Mage::getStoreConfig('paymentfilterbyproduct/filter_option/paymentfilter_special_products', Mage::app()->getStore());
}
else{
$filter_csv = Mage::getStoreConfig('paymentfilterbyproduct/filter_option/paymentfilter_all_product', Mage::app()->getStore());
}
$filter_array = explode(",", $filter_csv);
foreach ($methods as $k => $method){
if(!in_array($method->getCode(), $filter_array))
unset($methods[$k]);
}//methods
return $methods;
}
}
In /app/code/local/MagePal/PaymentFilterByProduct/etc/system.xml
900
magepal
1000
1
1
1
text
1
1
1
1
select
adminhtml/system_config_source_yesno
50
1
1
1
text
2
1
1
1
Please enable all applicable payment methods in system payment config
multiselect
MagePal_PaymentFilterByProduct_ActivePaymentMethod
30
1
1
1
multiselect
MagePal_PaymentFilterByProduct_ActivePaymentMethod
40
1
1
1
In /app/code/local/MagePal/PaymentFilterByProduct/Helper/Data.php
In /app/code/local/MagePal/PaymentFilterByProduct/ActivePaymentMethod.php
getActiveMethods();
foreach ($payments as $paymentCode=>$paymentModel) {
if($paymentModel->canUseCheckout() == 1){
$paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
$methods[$paymentCode] = array(
'label' => $paymentTitle,
'value' => $paymentCode,
);
}
}
return $methods;
}
}
In /app/etc/modules/MagePal_PaymentFilterByProduct.xml
true
local