Why does magento remove error information from a quote from a sale when the last offer item added has no errors

I was looking for Magento code (1.6.2 Community Edition) and OMG is a terribly neglected mess, but I will not talk about it here.

Looking at this code:

// Delete error from item and its quote, if it was set due to qty lack
$this->_removeErrorsFromQuoteAndItem($quoteItem, Mage_CatalogInventory_Helper_Data::ERROR_QTY);

What is in the Mage_CatalogInventory_Model_Observer class in /app/code/core/Mage/CatalogInventory/Model/Observer.php Line: 489

This creates a special error for me, try to do this (make sure that the "backorders" are not installed in the backend):

  • Add product to cart
  • Add another item to the cart.
  • Log in to the admin and change the quantity of the first product so that the requested quantity in the basket is not enough.
  • Return to the cart page.


" , ", ! , js, : " ".

, , ( ), (), .

? ? ? .

: . .

+3
2

, ( ):

  • (, ).
  • , .
  • , .
  • , , , , # 3 .

, , .

, . , _removeErrorsFromQuoteAndItem , , , ( ).

, - , sales_quote_item_qty_set_after.

public function reinitQuoteErrorState(Varien_Event_Observer $observer)
{
    $item = $observer->getEvent()->getItem();
    /** @var $item Mage_Sales_Model_Quote_Item */

    $quote = $item->getQuote();
    /** @var $quote Mage_Sales_Model_Quote */

    // Quote not loaded, do nothing since our changes are transient
    if (!$quote) return;

    // Quote already has error state, nothing to do.
    if ($quote->getHasError()) return;

    foreach ($quote->getAllItems() as $quoteItem)
    {
        if ($errorItems = $quoteItem->getErrorInfos())
        {
            foreach ($errorItems as $errorItem)
            {
                if ($errorItem['code'] == Mage_CatalogInventory_Helper_Data::ERROR_QTY)
                {
                    $quote->addErrorInfo(
                        'error',
                        'cataloginventory',
                        Mage_CatalogInventory_Helper_Data::ERROR_QTY,
                        Mage::helper('cataloginventory')->__('Not all products are available in the requested quantity')
                    );

                    return;
                }
            }
        }
    }
}

. , , XML /app/etc/modules/(:/app/etc/modules/MyCompany_MyModule.xml), , Mage_CatalogInventory_Model_Observer:: checkQuoteItemQty, .

, quoteInfo , - .

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <MyCompany_MyModule>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_CatalogInventory />
            </depends>
        </MyCompany_MyModule>
    </modules>
</config>
+4

All Articles