Question

1)

When a user first places an order the state will be 'new' which I understand makes the order non visible.

Given this state we can assign statuses like 'new' and 'pending' which I believe makes the order visible.

2)

If the order's payment method is set to 'auth & capture' or if either 'invoice' or 'ship' is completed for an order but not both then the state will be 'processing`.

For such orders, statuses can be 'shipped' or 'invoiced'.

3.

If both are completed then the state will be completed as will the status.

So my doubt is how magento understand particular state is new or processing or completed ?

is there any event-observer functionality for this?

I mean if user clicks place order button any observer will trigger?

Is there any definition for each state?

Was it helpful?

Solution

This happens in the model sales/order (so Mage_Sales_Model_Order). It has a _beforeSave() method which calls a method called _checkState(). Inside that _checkState() method (only part of it):

if (!$this->isCanceled()
    && !$this->canUnhold()
    && !$this->canInvoice()
    && !$this->canShip()) {
    if (0 == $this->getBaseGrandTotal() || $this->canCreditmemo()) {
        if ($this->getState() !== self::STATE_COMPLETE) {
            $this->_setState(self::STATE_COMPLETE, true, '', $userNotification);
        }
    }
    /**
     * Order can be closed just in case when we have refunded amount.
     * In case of "0" grand total order checking ForcedCanCreditmemo flag
     */
    elseif (floatval($this->getTotalRefunded()) || (!$this->getTotalRefunded()
        && $this->hasForcedCanCreditmemo())
    ) {
        if ($this->getState() !== self::STATE_CLOSED) {
            $this->_setState(self::STATE_CLOSED, true, '', $userNotification);
        }
    }
}

if ($this->getState() == self::STATE_NEW && $this->getIsInProcess()) {
    $this->setState(self::STATE_PROCESSING, true, '', $userNotification);
}

So depending on your state of the order, e.g. see the last two lines if the state was new and the order has getIsInProcess() (which basically checks for invoices / shipmments), then the state will be changed to processing.

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