To hide some payment methods based on shipping method you don't need to observe things at all:
Every methods(in one page check out) post the methods which are chosen to the next level. So you can get the shipping method which are chosen, in payment method level. Just print the post things in
app/design/frontend/base/default/template/checkout/onepage/payment/methods.phtml
in this add below one,
<?php print_r($_POST); ?>
So now you can get the shipping methods which are chosen previous step. And note it, so now, you can add just simple logic (if else) condition in same file for hiding payment.
For example here I want hide check / money order
payment method, if shipping method is flat
. Here the payment method code is checkmo
. you can get payment method code by simply printing that variable like echo $_code = $_method->getCode();
in same file. so here just add simple if else ,
<?php
$methods = $this->getMethods();
$oneMethod = count($methods) <= 1;
?>
<?php if (empty($methods)): ?>
<dt>
<?php echo $this->__('No Payment Methods') ?>
</dt>
<?php else:
foreach ($methods as $_method):
echo $_code = $_method->getCode();
if($_POST['shipping_method'] == 'flatrate_flatrate') {
if($_code == 'checkmo') {
continue;
}
}
?>
Here,
if($_POST['shipping_method'] == 'flatrate_flatrate') {
if($_code == 'checkmo') {
continue;
}
}
checks the shipping method and skip the payment method which we don't want to display. That's it. Please comment here if you have any doubt.
Note:
shipping_method => flatrate_flatrate
payment_method => checkmo
Best Answer
First of all,you need to track how
a cart item is cart from Sales Category
as magento system does notsave the category details at checkout relate tables.
As per as
magento system collectRates
function of shipping method is responsible for a shipping will shown or not on Checkout
.There
collectRates
method you canget cart item details on
bySolution: need to save
category id
atsales_flat_quote_item
table during cart then on basic ofthis field disable shipment method.