1

I'm creating a partial invoice and I'm unable to get the qty invoiced to send it to the payment gateway.

The code I'd written in my model for capture() is:

        if ($order->hasInvoices()) {
            foreach ($order->getInvoiceCollection() as $invoice) {
                foreach ($invoice->getAllItems() as $item) {
                    Mage::log($item->getQtyInvoiced()); // getting qty = 0
                }
            }
        }

also, for the next time I do want to create the invoice then $order->hasInvoices() returning false.

Is the above code is right? Any note on debug the invoice items will be appreciated.

2
  • What do you mean when you say 'also, for the next time I do want to create the invoice then $order->hasInvoices() returning false'?
    – Moose
    Commented Mar 20, 2014 at 6:09
  • means, if I'd invoiced 2 out of 5 items in the order then 3 of them are left to be invoiced later. and later on, if I do invoice the rest of them or less then the number left then there is no log entry(no execution of if() block) Commented Mar 20, 2014 at 6:11

2 Answers 2

2

The getQtyInvoiced() method you are using does not exist. You need to use

$item->getQty();

Then you should be all set.

P.S. For a full list of functions applicable to this object, refer to app/code/core/Mage/Sales/Model/Order/Invoice/Item.php

5
  • I know, but magento internally has magic functions getter and setter. and in table sales_flat_order_item there is a column qty_invoiced Commented Mar 20, 2014 at 6:12
  • From what I understand the "getter/setter" methods are applicable for custom models, not predefined ones. Let me know how it pans out using the getQty() method.
    – Moose
    Commented Mar 20, 2014 at 6:14
  • you were right. getQty() is working fine. but what about the next time I create the remaining invoice. if ($order->hasInvoices()) { block does not execute. why? Commented Mar 20, 2014 at 7:19
  • 1
    To call the value in qty_invoiced column use getQtyInvoiced()
    – NathanielR
    Commented Jun 22, 2015 at 11:24
  • Be careful, getQtyInvoiced() seems to represent the ALREADY INVOICED quantity in Magento 1.9.2 - it is not the amount that will be paid for with the current invoice .. Commented Aug 11, 2015 at 14:28
-2

Try this

if ($order->hasInvoices()) {
            foreach ($order->getInvoiceCollection() as $invoice) {
                foreach ($invoice->getAllItems() as $item) {
                    Mage::log($item->getQty());
                }
            }
        }
2
  • getQty() is working now. but for the next time if ($order->hasInvoices()) { block does not execute. why? Commented Mar 20, 2014 at 7:19
  • 1
    This is essentially the exact answer that I posted?
    – Moose
    Commented Mar 20, 2014 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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