I encountered an issue with status management for order items. Each item in an order is assigned a status based on the quantities ordered, shipped, invoiced, cancelled, returned and backordered.
To my mind it would make sense to have the status equal to “Shipped” if quantity ordered = quantity shipped. This approach is also indicated on definition of the shipped status in /app/code/core/Mage/Sales/Model/Order/Item.php:
const STATUS_SHIPPED = 2; // When qty ordered – [qty canceled + qty returned] = qty shipped
That is, however, not the case. If you have the item both invoiced and shipped, it will be set to status “Mixed”. The code responsible for this is inside the getStatusId() function in the same source file:
public function getStatusId()
{
$backordered = (float)$this->getQtyBackordered();
$canceled = (float)$this->getQtyCanceled();
$invoiced = (float)$this->getQtyInvoiced();
$ordered = (float)$this->getQtyOrdered();
$refunded = (float)$this->getQtyRefunded();
$shipped = (float)$this->getQtyShipped();
$actuallyOrdered = $ordered – $canceled – $refunded;
if (!$invoiced && !$shipped && !$refunded && !$canceled && !$backordered) {
return self::STATUS_PENDING;
}
if ($shipped && !$invoiced && ($actuallyOrdered == $shipped)) {
return self::STATUS_SHIPPED;
}
if ($invoiced && !$shipped && ($actuallyOrdered == $invoiced)) {
return self::STATUS_INVOICED;
}
if ($backordered && ($actuallyOrdered == $backordered) ) {
return self::STATUS_BACKORDERED;
}
if ($refunded && $ordered == $refunded) {
return self::STATUS_REFUNDED;
}
if ($canceled && $ordered == $canceled) {
return self::STATUS_CANCELED;
}
if (max($shipped, $invoiced) < $actuallyOrdered) {
return self::STATUS_PARTIAL;
}
return self::STATUS_MIXED;
}
You can see that the status is set to shipped only if no invoice is present. I believe this is a bug, and it introduces confusion among shopowners. I think this code should be modified in the line assigning shipped status, like so:
if ($shipped && ($actuallyOrdered == $shipped) && ($actuallyOrdered == $invoiced)) {
return self::STATUS_SHIPPED;
}
If the number of invoiced items is different from the number of shipped items than the item will get a ‘Mixed’ status. This way, the mixed status could be considered as a sort of warning flag indicating that something is wrong.