for handling payment method display in cart we use event handling we use config.xml in module or in custom module
app/code/local/regitration/field/etc/config.xml
<?xml version="1.0"?>
<config>
<frontend>
<events>
<payment_method_is_active>
<observers>
<Regitration_Field_Model_observer>
<class>Regitration_Field_Model_observer</class>
<method>payment_method_is_active</method>
</Regitration_Field_Model_observer>
</observers>
</payment_method_is_active>
</events>
</frontend>
</config>
define action in observer file
app/code/local/regitration/field/model/observer.php
<?php
class Regitration_Field_Model_observer {
public function payment_method_is_active($observer){
$event = $observer->getEvent();
$method = $event->getMethodInstance();
$result = $event->getResult();
$session = Mage::getSingleton('checkout/session')->getQuote();
$shippiingcarriers = $session->getShippingAddress()->getShippingMethod();
if ($shippiingcarriers == 'flatrate_flatrate' ){
if($method->getCode() == 'cashondelivery' OR $method->getCode() == 'checkmo' OR $method->getCode() == 'paypal_standard' or $method->getCode()=='purchaseorder'){
$result->isAvailable = false;
}else{
$result->isAvailable = true;
}
}
}
}
?>
app/code/local/regitration/field/etc/config.xml
<?xml version="1.0"?>
<config>
<frontend>
<events>
<payment_method_is_active>
<observers>
<Regitration_Field_Model_observer>
<class>Regitration_Field_Model_observer</class>
<method>payment_method_is_active</method>
</Regitration_Field_Model_observer>
</observers>
</payment_method_is_active>
</events>
</frontend>
</config>
define action in observer file
app/code/local/regitration/field/model/observer.php
<?php
class Regitration_Field_Model_observer {
public function payment_method_is_active($observer){
$event = $observer->getEvent();
$method = $event->getMethodInstance();
$result = $event->getResult();
$session = Mage::getSingleton('checkout/session')->getQuote();
$shippiingcarriers = $session->getShippingAddress()->getShippingMethod();
if ($shippiingcarriers == 'flatrate_flatrate' ){
if($method->getCode() == 'cashondelivery' OR $method->getCode() == 'checkmo' OR $method->getCode() == 'paypal_standard' or $method->getCode()=='purchaseorder'){
$result->isAvailable = false;
}else{
$result->isAvailable = true;
}
}
}
}
?>
No comments:
Post a Comment