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?
2 Answers
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. May 29, 2018 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. May 30, 2018 at 7:37
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. May 28, 2018 at 19:47
-
Do you know how to efficiently convert those arrays on a collection, so I can display on a grid? May 28, 2018 at 19:57
-