Question

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?

Thanks

Was it helpful?

Solution

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;
}

Explanation:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top