0

This is the code I use, which is not working, in order to make all of active quotes for the logged user to inactive, but it keeps taking only one quote.

$quote = Mage::getSingleton('sales/quote');
$quoteID = $quote->getId();

while ($quoteID)
{

    // Set inactive 
    $quote->setIsActive(0);
    $quote->save();

    // find next inactive quote <- NOT WORKING! $quoteID STAYS THE SAME!
    $quote = Mage::getSingleton('sales/quote');
    $quoteID = $quote->getId();

}
3
  • No idea what you are trying to achieve here. Commented Feb 23, 2015 at 15:56
  • Mage::getSingleton() returns always the same instance, so at no point in your script, another quote is loaded. Commented Feb 23, 2015 at 16:43
  • fschmengler, I need to set all quotes to not active. I have a bug caused by one magento module which I must use which create a damaged quote (quote with NULL product_id). when I log to system ant there's NULL product_id in my quote. It causes error. when I set quotes to not active all is ok. I want to make quotes not active by code.
    – Elad
    Commented Feb 24, 2015 at 9:29

1 Answer 1

1

Try the following -:

if (Mage::getSingleton('customer/session')->isLoggedIn()) {
  $customer = Mage::getSingleton('customer/session')->getCustomer();
  $collection = Mage::getResourceModel('sales/quote_collection');
  $collection->getSelect()->where('(is_active=1 and customer_id='.$customer->getId().')');
  foreach($collection as $col){
      $quote = Mage::getModel('sales/quote')->load($col->getId());
      $quote->setIsActive(0);
      $quote->save();
  } //foreach
}//If clause

Hope it helps

Cheers S

1
  • Hi thank you very much loops great on all of the quotes! But still some problem. It looks like it works only when $quote->save(); is commented out. Do you have any idea why ?
    – Elad
    Commented Feb 23, 2015 at 17:45

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.