0

I need to get a collection of all payment methods and list the quantity of orders on each of them, how can I do that programmatically?

1

You can make the array to collection in the following way:

$allActivePaymentMethods = Mage::getModel('payment/config')->getActiveMethods();
$collection = new Varien_Data_Collection();
foreach($allActivePaymentMethods as $row){
   $data=array('id'=>$row->getId(),'store'=>$row->getStore());
   $rowObj = new Varien_Object();
   $rowObj->setData($data);
   $collection->addItem($rowObj);
}

//now you can get the data using collection way
foreach($collection as $_data){
  print_r($_data->getData());
}
  • It kinda of worked, but it's making a collection with null values, however, when I print_r the array(not the collection) it's returning an array with these values: Array ( [id] => free [store] => ) Array ( [id] => cashondelivery [store] => ) Array ( [id] => paypal_billing_agreement [store] => ) I need to make my collection show those values, and also need to show the quantity of orders made with the payment method in question. – Pedro de Albuquerque May 29 '18 at 12:25
  • Actually there is object in each array, So you need to build the data array before converting to an object. I have modified the answer, it should work. – Prasanta Hatui May 30 '18 at 7:37
0

These are class methods app/code/core/Mage/Payment/Model/Config.php

To get a list with all payments active and inactive:

$allAvailablePaymentMethods = Mage::getModel('payment/config')->getAllMethods();

To get a list with all active payment methods:

$allActivePaymentMethods = Mage::getModel('payment/config')->getActiveMethods();

To get a list with all credit cards that Magento supports:

$allCcTypes = Mage::getModel('payment/config')->getCcTypes();
  • I tried this solution a while ago and can't use that because I need a collection, not an array, also tried to convert those arrays to a collection object but for no avail. – Pedro de Albuquerque May 28 '18 at 19:47
  • Do you know how to efficiently convert those arrays on a collection, so I can display on a grid? – Pedro de Albuquerque May 28 '18 at 19:57
  • Sorry, but I do not know how to implement it. – Evgeniy Kapelko May 28 '18 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.