Get all invoices in Magento

前端 未结 1 707
耶瑟儿~
耶瑟儿~ 2020-12-17 07:24

How do I get all the invoices collection?

I know that to get all the orders is:

 $orders = Mage::getModel(sales/order)->getCollection();


        
相关标签:
1条回答
  • 2020-12-17 08:02

    You need to use :

    $orders = Mage::getModel("sales/order_invoice")->getCollection();
    

    For the explanation :

    When you want to access i block/model/resource/helper/etc in magento :

    • first, you choose the right method to access it : Mage::getModel for a model

    • second, you must tell magento "which" module you want to access. You do that with the first part of the parameter string :

    Mage::getModel("sales/order_invoice")

    This string refers to the XML node of the type or resource you want to access. In your case, for accessing a model of the Mage_Sales module : take a look at the Mage_Sales's config.xml, you'll see the node to use (used for models and resourceModels) :

    [...]
    <models>
        <sales><!-- <----- THIS NODE -->
            <class>Mage_Sales_Model</class>
             <resourceModel>sales_resource</resourceModel>
         </sales>
         [...]
    
    • last part, you need to add the full access to the file you want, with folder if needed. In your case, in the Model folder of the Mage_Sales module (above xml config tells us that this folder is Mage_Sales_Model), you'll see a file Invoice.php in the Order folder : then you path is "order_invoice" and the full commande to access your model is :

    Mage::getModel("sales/order_invoice")

    0 讨论(0)
提交回复
热议问题