7

I'm looking for the exact point in the codebase where Magento decreases the quantity of a product after payment. I have noticed that it happens after payment authorize and not capture, if I am correct.

2 Answers 2

3

Magento is decreasing /increasing the quality using basically event observer on class Mage_CatalogInventory_Model_Stock.There lot event code is written there which in call at config.xml.Just see config.xml of Mage_CatalogInventory

Events:

    <sales_quote_item_qty_set_after>
        <observers>
            <inventory>
                <class>cataloginventory/observer</class>
                <method>checkQuoteItemQty</method>
            </inventory>
        </observers>
    </sales_quote_item_qty_set_after>
    <checkout_submit_all_after>
        <observers>
            <inventory>
                <class>cataloginventory/observer</class>
                <method>checkoutAllSubmitAfter</method>
            </inventory>
        </observers>
    </checkout_submit_all_after>
    <sales_model_service_quote_submit_before>
        <observers>
            <inventory>
                <class>cataloginventory/observer</class>
                <method>subtractQuoteInventory</method>
            </inventory>
        </observers>
    </sales_model_service_quote_submit_before>
    <sales_model_service_quote_submit_success>
        <observers>
            <inventory>
                <class>cataloginventory/observer</class>
                <method>reindexQuoteInventory</method>
            </inventory>
        </observers>
    </sales_model_service_quote_submit_success>
    <sales_model_service_quote_submit_failure>
        <observers>
            <inventory>
                <class>cataloginventory/observer</class>
                <method>revertQuoteInventory</method>
            </inventory>
        </observers>
    </sales_model_service_quote_submit_failure>
    <sales_order_item_cancel>
        <observers>
            <inventory>
                <class>cataloginventory/observer</class>
                <method>cancelOrderItem</method>
            </inventory>
        </observers>
    </sales_order_item_cancel>
    <sales_order_creditmemo_save_after>
        <observers>
            <inventory>
                <class>cataloginventory/observer</class>
                <method>refundOrderInventory</method>
            </inventory>
        </observers>
    </sales_order_creditmemo_save_after>

and as schmengler said the

class Mage_CatalogInventory_Model_Stock responsive for that cases.

On Class Mage_CatalogInventory_Model_Observer function

subtractQuoteInventory() decrement the stock depends on getInventoryProcessed() flag value which Sales quote Object element.

On order place order Magento fire checkout_submit_all_after and sales_model_service_quote_submit_before event which is called observer [cataloginventory/observe -checkoutAllSubmitAfter].

If those event is not fire then it not possible reduce stock qty.

On this class function revertQuoteInventory() revert quantity when quote is failed to convert to order [sales_model_service_quote_submit_failure] and Mage::getSingleton('cataloginventory/stock')->revertProductsSale($items);

7

It actually happens after placing the order, independent of the payment method.

The responsible code is in Mage_CatalogInventory_Model_Stock

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.