title: Automatic onepage checkout - quote issue
body: <p>I'm creating automated checkout feature, which will create few orders at once:</p>
  
  <p>What's wrong with that?</p>
  
  <p>This script let's say creates 4 different orders with different prodcuts, for different users, but problem lies here, each order created after first order has got subtotal and grand total of first order. How can I reset that?</p>
  
  <p>
  
  <p>Mage::app('default');</p>
  
  <pre><code>/**
   * Get the resource model
   */
  $resource = Mage::getSingleton('core/resource');
  
  /**
   * Retrieve the read connection
   */
  $readConnection = $resource-&gt;getConnection('core_read');
  $query = 'SELECT * FROM m4gsrepeated_orders WHERE execution &lt;= CURDATE()';
  $all_orders = $readConnection-&gt;fetchAll($query);
  
  
  function addCartItems($products_array) {
      $cart = Mage::getModel('checkout/cart');
      foreach($products_array as $productw) {
          $sku = $productw[0]; 
          /** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
          $productCollection = Mage::getModel( 'catalog/product' )
                  -&gt;getResourceCollection()
                  -&gt;addFieldToFilter( 'sku', $sku );
          /** @var $product Mage_Catalog_Model_Product */
          $product = $productCollection-&gt;getFirstItem();
          // you should have the product now, maybe it isn't even necessary to get the ID
          $product = $product-&gt;load($product-&gt;getId());   
          $cart-&gt;addProduct($product, $productw[1]);
      }       
      $cart-&gt;save();
  }
  
  
  foreach ($all_orders as $order) {
      //Set basic data
      Mage::getSingleton('checkout/session')-&gt;getQuote()-&gt;setReservedOrderId(null);
      $customer = Mage::getModel('customer/customer')
      -&gt;setWebsiteId(Mage::app()-&gt;getStore()-&gt;getWebsiteId())
      -&gt;load($order['user_id']);
  
      // Set as Logged In and Clear Session
      Mage::getSingleton('customer/session')-&gt;setCustomerAsLoggedIn($customer)-&gt;renewSession();
  
  
      //Set up cart
      $cart = Mage::getModel('checkout/cart')-&gt;getQuote();
  
      //get current cart items;s
      $i=1;
      foreach ($cart-&gt;getAllItems() as $item) {
          $products_current[$i][0] = $item-&gt;getProduct()-&gt;getSku();
          $products_current[$i][1] = intval($item-&gt;getQty());
          $i++;
      }
      $i=1;
  
      $cart = Mage::getModel('checkout/cart');
  
      foreach( Mage::getSingleton('checkout/session')-&gt;getQuote()-&gt;getItemsCollection() as $item ){
          $cart-&gt;removeItem( $item-&gt;getId() );
      }
  
      $products_delayed = json_decode($order['items']);
      addCartItems($products_delayed);
      $cart-&gt;save();
  
  
      //LUUUTA CREATE ORDER
  
      # Get customer default shipping information
      $customerAddressId = Mage::getSingleton('customer/session')-&gt;getCustomer()-&gt;getDefaultShipping();
      if ($customerAddressId){
          $address = Mage::getModel('customer/address')-&gt;load($customerAddressId);
          $shippingAddress = $address-&gt;getData();
      }
  
      # Get customer default billing information
      $customerAddressId = Mage::getSingleton('customer/session')-&gt;getCustomer()-&gt;getDefaultBilling();
      if ($customerAddressId){
          $address = Mage::getModel('customer/address')-&gt;load($customerAddressId);
          $billingAddress = $address-&gt;getData();
      }
      $quote = Mage::getSingleton('checkout/session')-&gt;getQuote();
      /*
      * One page checkout consists of following steps
      * (1) Customer login method aka Checkout method
      * (2) Billing information (address)
      * (3) Shipping information (address)
      * (4) Shipping method
      * (5) Payment information
      * (6) Order review, in short: DO THE ORDER
      */
      $storeId = Mage::app()-&gt;getStore()-&gt;getId();
      $checkout = Mage::getSingleton('checkout/type_onepage');
      $checkout-&gt;initCheckout();
      $checkout-&gt;saveShippingMethod('excellence_excellence'); 
  
      $quote-&gt;getShippingAddress()-&gt;setShippingMethod('excellence_excellence');
  
      $quote-&gt;getShippingAddress()-&gt;unsGrandTotal();      //clear the values so they won't take part in calculating the totals
      $quote-&gt;getShippingAddress()-&gt;unsBaseGrandTotal();
  
      $quote-&gt;getShippingAddress()-&gt;setCollectShippingRates(true)-&gt;save();
  
      $quote-&gt;getShippingAddress()-&gt;collectTotals();    //collect totals and ensure the initialization of the shipping methods
  
      $quote-&gt;collectTotals();
  
      //STEP(1)
      $checkout-&gt;saveCheckoutMethod('register');
  
      //STEP(2)
      $checkout-&gt;saveBilling($billingAddress, false);
  
      //STEP(3)
      $checkout-&gt;saveShipping($shippingAddress, false);
  
      //STEP(4)
      $checkout-&gt;saveShippingMethod('excellence_excellence'); 
  
  
      //STEP(5)
      $checkout-&gt;savePayment(array('method'=&gt;'pay'));
  
      Mage::getSingleton('checkout/type_onepage')-&gt;getQuote()-&gt;getShippingAddress()-&gt;setShippingMethod('excellence_excellence');
  
      //STEP(6)
      /*
      * $checkout-&gt;saveOrder() returns array holding empty object
      * of type Mage_Checkout_Model_Type_Onepage
      */
  
      try {
          $checkout-&gt;saveOrder();
      }
      catch (Exception $ex) {
          echo $ex-&gt;getMessage(); 
      }   
  
      //addCartItems($products_delayed);
      $cart-&gt;truncate();
      $cart-&gt;save();
      Mage::getSingleton('checkout/session')-&gt;setCartWasUpdated(true);
      Mage::getSingleton('customer/session')-&gt;logout();
      $customerAddressId = '';
  }
  </code></pre>