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.

  • 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 Mar 20 '14 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) – Mohammad Faisal Mar 20 '14 at 6:11
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

  • I know, but magento internally has magic functions getter and setter. and in table sales_flat_order_item there is a column qty_invoiced – Mohammad Faisal Mar 20 '14 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 Mar 20 '14 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? – Mohammad Faisal Mar 20 '14 at 7:19
  • 1
    To call the value in qty_invoiced column use getQtyInvoiced() – NathanielR Jun 22 '15 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 .. – Manuel Arwed Schmidt Aug 11 '15 at 14:28
-2

Try this

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

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.