Magento – Set rules for ‘Payment Information’ on Onepage Checkout

checkoutmagento-1.7onepage-checkoutpayment-methodsrules

I'd like to add in some rules for the 'Payment Information' section of the Magento Onepage Checkout.

Currently my site will show the options:

  • Debit/Credit Card
  • PayPal
  • Invoice Organisation

I'd like to only show the 'Invoice' option if they have selected a particular option within the Billing Payment section.

Which file should I edit to access the options within the Payment Section on the onepage checkout? Can anyone point me in the right direction?

Best Answer

Theres a really handy event for disabling and enabling payment methods on the fly.

Add the following into your config.xml section

<payment_method_is_active>
    <observers>
        <preorder_payment>
            <class>your_module/observers</class>
            <method>invoiceOnly</method>
        </preorder_payment>
    </observers>
</payment_method_is_active>

Then create the following function in your observer.php

/**
 * Disable all other payments
 * @param Varien_Event_Observer $observer
 */
public function invoiceOnly(Varien_Event_Observer $observer) {

    $_result = $observer->getResult();
    $_methodInstance = $observer->getMethodInstance();

    if(BILLING_CONDITION_HERE) {
        if($_methodInstance->getCode() != 'METHOD_CODE') {
            $_result->isAvailable = false;
        } else {
            $_result->isAvailable = true;
        }
    }

}

You'll need to modify the BILLING_CONDITION_HERE and the METHOD_CODE (to the invoice payment method code)

This will automatically disable everything except METHOD_CODE if the billing condition is met.

Related Topic