I'm a building a function that should retrieve all the payments made in the last hour, and update the order status from pending to processing.

The problem is that, for some reason some of the orders (pending) return false when I do this:

$orderModel = Mage::getModel('sales/order');
$order = $orderModel->load($entityId);
//$order->canInvoice() --> false

Do you have any idea/ sugestion?


  • I think you should debug the canInvoice function to see what the problem might be. There are various reaons. Regards – user1638055 Jul 22 '14 at 12:11

As per invoice generation is depending upon on canInvoice() function of sales model:

// File: app/code/core/Mage/Sales/Model/Order.php
public function canInvoice()
    if ($this->canUnhold() || $this->isPaymentReview()) {
        return false;
    $state = $this->getState();
    if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
        return false;

    if ($this->getActionFlag(self::ACTION_FLAG_INVOICE) === false) {
        return false;

    foreach ($this->getAllItems() as $item) {
        if ($item->getQtyToInvoice()>0 && !$item->getLockedDoInvoice()) {
            return true;
    return false;


Condition1: if ($this->canUnhold() || $this->isPaymentReview()) means if Order state is unhold or order state is payment review (this->getState() === self::STATE_PAYMENT_REVIEW;)

Condition2: if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {

If order state is closed or complete or cancel.

Condition 3: if ($this->getActionFlag(self::ACTION_FLAG_INVOICE),If current action is invoice

Condition4: if ($item->getQtyToInvoice()>0 && !$item->getLockedDoInvoice()) { if order all item qty_to_invoice value is less than 1 and all item locked_do_invoice is null (In Sales_flat_order_item table).

Hope ,you will understand

  • Thanks for the detailed explanation, but, can you clarify the Condition 4 please – MASNathan Jul 23 '14 at 8:48

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.