title: Magento Cart: Check for items empties cart
body: <p>I am new to Magento, but I thought I had a grasp on it until today. Here is my problem.</p>
  
  <p>I am writing a new Observer to add a coupon to the cart on page load. The coupon code is passed in the URL and I desire the code to be passable through ANY working URL.</p>
  
  <p>For example: <a href="http://magento/?coupon=MYCOUPON" rel="nofollow noreferrer">http://magento/?coupon=MYCOUPON</a></p>
  
  <p>I am catching on the event "controller_front_init_routers" to capture the coupon code.</p>
  
  <p>I have the observer working, but if I already have an item in the cart and I pass a coupon code my cart appears empty, here is how I am adding the coupon:</p>
  
  <pre><code>    public function applyCoupon($observer){
          $coupon_code = $observer-&gt;getEvent()-&gt;getData('front')-&gt;getRequest()-&gt;getParam('coupon');
          if(!empty($coupon_code)){
              Mage::getSingleton('checkout/session')-&gt;setData('coupon_code', $coupon_code);
              Mage::getSingleton('checkout/cart')-&gt;getQuote()-&gt;setCouponCode($coupon_code)-&gt;save();
  
              Mage::log('Coupon Code: '. $coupon_code);
          }
      }
  </code></pre>
  
  <p>It seems that anytime I call Mage::getSingleton('checkout/session')->anything() I lose the session for the cart.</p>
  
  <p>I thought maybe I simply needed to fetch the current cart ID and load it, but I can't seem to find a way to do that either.</p>
  
  <p>Has any one had experience in this, maybe has a solution?</p>