1

I'm trying to debug code that updates inventory data when an order is placed. I have an observer that gets all order details and logs qty data after the order is placed, but I want to be able to log the qty before an order is saved for debugging purposes.

I have also tried observer sales_order_place_before. Neither observer gives me stock data from before the sale is saved and qty reduced.

<sales_order_before_save>
    <observers>
        <vampower_createebaydescription>
            <class>vampower_createebaydescription/observer</class>
            <method>logAssemblyQtyPreSale</method>
            <type>singleton</type>
        </vampower_createebaydescription>
    </observers>
</sales_order_before_save>

public function logAssemblyQtyPreSale(Varien_Event_Observer $observer)
{
    $orderData = $observer->getEvent()->getOrder();
    $LogFile = 'Update-Qty-After-Sale.log';

    Mage::log("-------------------  Before Order - Log Assembly Qty-----------------", null, $LogFile);

    if ($orderData->getId()) 
    {
        foreach ($orderData->getAllVisibleItems() as $item)
        {
            $ProductID = $item->getProductId();
            $OrderQty = $item->getQtyOrdered();
            $_product = Mage::getModel('catalog/product')->load($ProductID);
            $_stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);

            $isAssembly = $_product->getData("is_assembly");
            $ProductQty = $_stock->getQty();
            $OrderQty = $item->getQtyOrdered();

            Mage::log("  --------- ITEM IN ORDER -------", null, $LogFile);

            $LogMsg = "     " . $OrderQty . ' - ' . $item->getProductId() . ' - '.$_product->getName();

            Mage::log($LogMsg, null, $LogFile);
            Mage::log("Current Qty: " . $ProductQty, null, $LogFile);
            Mage::log("OrderQty: " . $OrderQty, null, $LogFile);
        }

    }


    Mage::log("-------------------  END - Before Order Log Assembly Qty-----------------", null, $LogFile);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.