23

Does the sales/quote object work differently than other objects when loading? See the following..

Works:

$quote = Mage::getModel('sales/quote')->getCollection()
    ->addFieldToFilter('entity_id', $quoteId)
    ->getFirstItem();
print_r($quote->getData()); // shows right data

Does not work:

$quote = Mage::getModel('sales/quote')->load($quoteId);
print_r($quote->getData()); // empty

Both $quote are of the correct of class, Mage_Sales_Model_Quote.

  • with 5 upvotes i dont understand how this question is marked as off-topic and non-reproducible. this problem can be reproduced. Simply load a quote on frontend order view page and on admin order view page, it will work differently.webbiedave's answer works perfectly in this scenario. – Reena Parekh Jul 16 '15 at 6:02
29

Set the store first:

$store = Mage::getSingleton('core/store')->load(1);

$quote = Mage::getModel('sales/quote')->setStore($store)->load($quoteId);
2

Nope, Mage_Sales_Model_Quote is like all the other db based models. You make something wrong. Maybe hardcode the $quoteId? Are you sure it is correct? Both codes should work.

  • Yeah, I've tried using the an integer in place of $quoteId. I'm starting to think maybe $quoteId needs to be a string or something. My script is currently running, so I'll check tomorrow. – musicliftsme Mar 20 '14 at 22:38
  • Hmm, it does not work on another instance, either, with the quote entity ID hard-corded in string or integer. Fabian, have you tried the piece of the code I've posted? – musicliftsme Mar 21 '14 at 14:11
  • 1
    While the model is just like other db models, the resource model Mage_Sales_Model_Resource_Quote implements a hardcoded filter on store id by _getLoadSelect(). The way around it is to use Mage::getResourceSingleton('sales/quote')->loadByIdWithoutStore($quote, $order->getQuoteId()). Now if only I can tell it to NOT load a full customer object and start a session, I'm a happy camper. – Melvyn Dec 22 '14 at 6:50
  • 3
    For anyone facing the same: it's the SalesRule/Model/Observer.php that instantiates a session on quote items load. Just to get to the customerGroupId. I've solved this by rewrite Sales_Model_Quote and setting the customer group id in Mage::registry and teaching Mage_SalesRule_Model_Observer->addProductAttributes to first look there. – Melvyn Dec 22 '14 at 8:31
  • 2
    Just saw this. I voted to re-open. Thanks Melvyn. – musicliftsme May 18 '15 at 13:51
0

You could use

$quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($quoteId);

It works in Magnto Enterprise ver. 1.14.2.4

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.