0

I have an ajax script where I use Mage::getSingleton('adminhtml/session_quote')->getQuote()->getId() however the result is always null.

1

This can happen if you load Magento for the frontend instead of the backend.

$ajaxCWD = realpath(dirname(__FILE__));
$_SERVER['SCRIPT_FILENAME'] = realpath($ajaxCWD.'/index.php');
require_once(realpath($ajaxCWD.'/app/Mage.php'));
$vararr = get_defined_vars();
foreach ($vararr as $varName => $varValue)
  $GLOBALS[$varName] = $varValue;
Mage::init();
Mage::getSingleton('core/session', array('name'=>'frontend'));
$_SERVER['SCRIPT_FILENAME'] = $originalScriptFileName;
[...]
error_log(gettype(Mage::getSingleton('adminhtml/session_quote')->getQuote()->getId()));

will always return "NULL"

To fix this you have to load Magento explicitly for the admin session.

[...]
//Mage::getSingleton('core/session', array('name'=>'frontend'));
Mage::getSingleton('core/session', array('name'=>'adminhtml'));
[...]
error_log(Mage::getSingleton('adminhtml/session_quote')->getQuote()->getId());

Now it should work.

| improve this answer | |

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.