I am creating my own resources by extending the Magento REST API, and I'm stuck on what object class should be returned on _retrieveCollection() for my API to render properly on both XML and JSON output.

My code is, roughly, as follows:

class Company_Module_Model_Api2_Invoice extends Mage_Api2_Model_Resource
    protected function _retrieveCollection()
        //just can't get the proper object to return here. :(    


    protected function _retrieve() {
        $invoice_increment_id = $this->getRequest()->getParam('invoice_id');
        $invoice = Mage::getModel("sales/order_invoice")->loadByIncrementId($invoice_increment_id);
        return $invoice;

        //Mage_Sales_Model_Order_Invoice is a Mage_Sales_Model_Abstract
        //which in turn is a Mage_Core_Model_Abstract
        //Having a Mage_Core_Model_Abstract as a return renders perfectly
        //as json or xml :)

        //Also works with Mage_Sales_Model_Order which is a  
        //Mage_Sales_Model_Abstract which in turn is a

    protected function _create() {
         //no matter what you return, this doesn't render any output.

    protected function _delete() {
         //no matter what you return, this doesn't render any output.   

So the question is: What is the return type for _retrieveCollection()?


@danny-dev-nz is correct with Mage_Sales_Model_Resource_Order_Invoice_Collection (and I guess any Mage_Core_Model_Resource_Db_Abstract)

I realized my problem is Magento versions. This is straightforward on a Magento installation.

protected function _retrieveCollection()

     $order_increment_id = $this->getRequest()->getParam('order_id');
     $order = Mage::getModel("sales/order")->loadByIncrementId($order_increment_id);
     $invoices = $order->getInvoiceCollection();
     return $invoices;       


Output on Magento "" enter image description here

Output on Magento "" is quirky:

enter image description here

4 Answers 4


Have you tried Mage_Sales_Model_Resource_Order_Invoice_Collection .

Using factory method Mage::getResourceModel("sales/order_invoice_collection").

  • Great! Though I discovered that this works on Magento 1.9, but not on 1.7. Updated question for this :)
    – Ardee Aram
    Aug 21, 2014 at 4:04

Just to add, after experimenting and tweaking, I discovered the following data types to be a valid return for _retrieveCollection():

  • Mage_Core_Model_Resource_Db_Abstract
  • String
  • Non-nested array of strings, (member nested array would come out as empty array). array("a","b","c") is fine while array("a",array("b","c")) is not.
  • associative array with string as key, and string as value (objects on key nor value will NOT work)

you simply create a Varien_data_collection, fill it up with varien objects and return the collection:

    $collection = new Varien_Data_Collection(); 

    foreach ($products_collection as $product) {

        $prod = $product_model->load( $product->getProductId() );

        $v_product = array(
                    'id' => $prod->getId(), 
                    'name' => $prod->getName(),
                    'price' => $prod->getPrice(),

        $varienObject = new Varien_Object();

    return $collection;
retrieveCollection function give return null value.

and function _retrieve() did not give any result as it return as an obeject. you need convert obeject to to array format

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.