Example #1
0
 public static function getCart()
 {
     // this acts as a singleton, in that it wil only fetch the cart form the session and check it for validity once per request
     if (!isset(self::$cart)) {
         $cart = Session::get('vividstore.cart');
         if (!is_array($cart)) {
             Session::set('vividstore.cart', array());
             $cart = array();
         }
         $db = Database::get();
         $checkeditems = array();
         $removal = false;
         // loop through and check if product hasn't been deleted. Remove from cart session if not found.
         foreach ($cart as $cartitem) {
             $exists = $db->GetOne("SELECT pID FROM VividStoreProducts WHERE pID=? ", $cartitem['product']['pID']);
             if (!empty($exists)) {
                 $checkeditems[] = $cartitem;
             } else {
                 $removal = true;
             }
         }
         if ($removal) {
             Session::set('vividstore.cart', $checkeditems);
         }
         self::$cart = $checkeditems;
     }
     return self::$cart;
 }
Example #2
0
 public static function clear()
 {
     $cart = self::getCart();
     unset($cart);
     Session::set('vividstore.cart', null);
     self::$cart = null;
 }