Magento - dynamically disable criteria-based payment method

I have an extremely simple module that allows a customer to "Buy on an account." The module does not really do anything special (it was just modified from the Cash On Delivery module.)

The only problem is that I offer this payment method for logging in.

So far, my module looks like this:

BuyOnAccount/ etc/ config.xml system.xml Model/ PaymentMethod.php 

Content of PaymentMethod.php:

 class MyCompany_BuyOnAccount_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract { protected $_code = 'buyonaccount'; protected $_isInitializeNeeded = true; protected $_canUseInternal = false; protected $_canUseForMultishipping = false; } 

The configuration and system xml files contain the usual thing (please let me know if you want to see the code and I will edit)

Therefore, I must disable the module if the user has not logged in (but, obviously, only for the current client session!)

Any ideas?

thanks

+4
source share
1 answer

You can simply add a method to your billing model called isAvailable(Mage_Sales_Model_Quote $quote) , which returns bool . For example, in your situation, you can add something like:

 public function isAvailable($quote = null) { $isLoggedIn = Mage::helper('customer')->isLoggedIn(); return parent::isAvailable($quote) && $isLoggedIn; } 

The payment method Mage_Payment_Model_Method_Free that comes with Magento is an example of a payment method that uses this: it will only show if the total amount of the basket is zero.

+5
source

Source: https://habr.com/ru/post/1389480/


All Articles