3

Steps to reproduce:

  1. Click create order button in sales -> orders.
  2. Add product to order that has a stock qty of 0 and has its backorder setting that allows backorders.
  3. Complete order

Expected result:

The sales_order_flat_item qty_backordered field for the item ordered is set to the appropriate backordered value.

Result : The sales_order_flat_item qty_backordered is NULL.

Any suggestions on how to fix this. We rely on the qty_backordered field for order management.

5

I dove in the code responsible for saving the qty_backorders field and ended up in

Mage_CatalogInventory_Model_Observer::checkQuoteItemQty

On line 432 and 532, you'll see this line;

$quoteItem->setBackorders($result->getItemBackorders());

This value is actually set when you are in the order screen in the backend (not when the order is actually submitted, but before). The system should at this point set the 'backorders' column in sales_flat_quote_item to this value. But, there isn't one! I think this is one of those infamous never-finished features of Magento that lingers around in the codebase.

Before we go on, I must insist you find another way to keep track of backorders than this half-finished (or non-existing) functionality, like creating your own extension with models & tables especially for this purpose. I can't vouch for any weird side effects that might occur when using this code.

But for the sake of answering your specific question, I'll continue.

There are two things that need to be done; we need to add the column to the table and the data needs to be actually saved.

Adding the column to the table is easy with one query;

ALTER TABLE sales_flat_quote_item ADD backorders INT(11) NULL;

Be sure to clear the cache and reindex before continuing.

Now, find the two lines I've mentioned above (432 and 532) and add after that line the following code;

try {
    $quoteItem->save();
} catch(Exception $e) {
    Mage::logException($e);
}

Of course, to adhere to Magento best practices, you should create your own custom module and extend Mage_CatalogInventory_Model_Observer and put the mentioned query in an install script.

Now, the backorder value should be set in the database in both the sales_flat_quote_item and sales_flat_order_item tables (columns backorders and qty_backordered respectively) and you can retrieve it using the regular $quoteItem->getBackorders() and $orderItem->getQtyBackordered().

0

We had the same issue with this. I know it's an older question but i want to share the right solution for others.

The quote object will set the super-mode flag when you create order as backend user. The observer method for checking inventory stuff will be ignored if the flag is set.

You fix this with overwrite the observer method like the lines below or patch the observer directly in the core:

<?php

class YourNamespace_CatalogInventory_Model_Observer extends Mage_CatalogInventory_Model_Observer
{
    public function checkQuoteItemQty($observer)
    {
        $superModeWasActive = false;
        $quoteItem = $observer->getEvent()->getItem();

        if ($quoteItem->getQuote()->getIsSuperMode()) {
            $superModeWasActive = true;
            $quoteItem->getQuote()->setIsSuperMode(false);
        }

        parent::checkQuoteItemQty($observer);

        if ($superModeWasActive) {
            $quoteItem->getQuote()->setIsSuperMode(true);
        }

        return $this;
    }
}

This issue is also in the official magento bugreporting system and is open since 3 years ago: https://magento.com/tech-resources/bug-tracking/issue/index/id/97/

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.