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
//Mage_Core_Model_Abstract
}
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()?
UPDATE:
@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 1.9.0.1 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 "1.9.0.1"
Output on Magento "1.7.0.2" is quirky: