Andrei
Andrei

Reputation: 65

Magento Error while trying to order / cancel an order that has more than one item

Hy

After the onepage checkout, in Magento, I received the following email error message ... Payment transaction failed. Reason Mage registry key "_singleton/model/observer" already exists Checkout Type onepage ....

And on the admin page, when trying to delete this oreder, same error, again:

There has been an error processing your request

Mage registry key "_singleton/model/observer" already exists

Trace:
#0 /app/Mage.php(223): Mage::throwException('Mage registry k...')
#1 /app/Mage.php(478): Mage::register('_singleton/mode...', false)
#2 /app/code/core/Mage/Core/Model/App.php(1316): Mage::getSingleton('model/observer')
#3 /app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('cataloginventor...', Array)
#4 /app/code/core/Mage/Core/Model/Abstract.php(466): Mage::dispatchEvent('cataloginventor...', Array)
#5 /app/code/core/Mage/CatalogInventory/Model/Stock/Item.php(787): Mage_Core_Model_Abstract->_afterSave()
#6 /app/code/core/Mage/Core/Model/Abstract.php(319): Mage_CatalogInventory_Model_Stock_Item->_afterSave()
#7 l/app/code/core/Mage/CatalogInventory/Model/Stock.php(210): Mage_Core_Model_Abstract->save()
#8 /app/code/core/Mage/CatalogInventory/Model/Observer.php(809): Mage_CatalogInventory_Model_Stock->backItemQty('542', 1)
#9 /app/code/core/Mage/Core/Model/App.php(1338): Mage_CatalogInventory_Model_Observer->cancelOrderItem(Object(Varien_Event_Observer))
#10 /app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Mage_CatalogInventory_Model_Observer), 'cancelOrderItem', Object(Varien_Event_Observer))
#11 /app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('sales_order_ite...', Array)

..and so on

This only happends to orders that have more than one item.

Any help will be appreciated, especially because the website is in production now.

Many thanks

Upvotes: 0

Views: 1122

Answers (2)

Alana Storm
Alana Storm

Reputation: 166066

That's a curious error -- my guess is you're dealing with a "core-hack"/edut (perhaps unintentionally) of your app/Mage.php file.

If you look at your stack trace, Magento calls

Mage::getSingleton('model/observer')

This is Magento's ways of saying "Instantiate a model/observer object, and make it a singleton instance", If you're not familiar with them, singletons are a "global" object that can only be instantiated once. If you try to instantiate a singleton again you get the original instance.

If you look at the implementation of getSingleton

#File: app/Mage.php
public static function getSingleton($modelClass='', array $arguments=array())
{
    $registryKey = '_singleton/'.$modelClass;
    if (!self::registry($registryKey)) {
        self::register($registryKey, self::getModel($modelClass, $arguments));
    }
    return self::registry($registryKey);
}

You can see the call to self::registry from your stack trace that causes the error. However, you can also see that Magento checks to make sure the registry key doesn't exist via the if (!self::registry($registryKey)) { conditional.

My guess is someone changed the definition of getSingleton, or registry or register in your app/Mage.php file. In a sock Magento system it should not be possible to receive the exact error you've posted here.

Upvotes: 1

ToxaBes
ToxaBes

Reputation: 1587

Let me add a bit of Magento 'anatomy' to Alan's answer:

From your error log:

#10 /app/code/core/Mage/Core/Model/App.php(1317): `Mage_Core_Model_App->_callObserverMethod(Object(Mage_CatalogInventory_Model_Observer), 'cancelOrderItem', Object(Varien_Event_Observer))

class: Mage_CatalogInventory_Model_Observer

model: cataloginventory/observer

method: cancelOrderItem

This mean what #2 should be:

#2 /app/code/core/Mage/Core/Model/App.php(1316): Mage::getSingleton('cataloginventory/observer')

But you have:

#2 /app/code/core/Mage/Core/Model/App.php(1316): Mage::getSingleton('model/observer')

Why it failed:

1) when Magento try to execute Mage::getSingleton('model/observer') it call getSingleton() function from Alan's answer.

2) registry don't have '_singleton/model/observer' so it try to register it:

self::register($registryKey, self::getModel($modelClass, $arguments));

3) it call self::getModel('model/observer', array())) for registration and this method fails because you don't have such model.

Again, you have 'model/observer' model in one of your xml configuration files, but Magento can't find physical file with this model.

What to do? This is occurs on 'sales_order_item_cancel' event, so try to find this string in config.xml files in third-party extension folders.

If in one of config.xml you find something like:

...
    <events>
   ...
    <sales_order_item_cancel>
        <observers>
            <inventory>
                <class>model/observer</class>
                <method>cancelOrderItem</method>
            </inventory>
        </observers>
    </sales_order_item_cancel>
    ...
    </events>
...

Just comment <sales_order_item_cancel> section. If you want to make it working, set correct value in <class>model/observer</class> section.

Upvotes: 1

Related Questions