public static function getCart() { // this acts as a singleton, in that it wil only fetch the cart from 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(); $update = false; // loop through and check if product hasn't been deleted. Remove from cart session if not found. foreach ($cart as $cartitem) { $product = StoreProduct::getByID((int) $cartitem['product']['pID']); if ($product) { // check that we dont have a non-quantity product in cart with a quantity > 1 if (!$product->allowQuantity() && $cartitem['product']['qty'] > 0) { $cartitem['product']['qty'] = 1; $update = true; } $include = true; if ($cartitem['product']['variation']) { if (!StoreProductVariation::getByID($cartitem['product']['variation'])) { $include = false; } } if ($include) { $checkeditems[] = $cartitem; } } else { $update = true; } } if ($update) { Session::set('vividstore.cart', $checkeditems); } self::$cart = $checkeditems; } return self::$cart; }
public function setVariation($variation) { if (is_object($variation)) { $this->variation = $variation; } elseif (is_integer($variation)) { $variation = StoreProductVariation::getByID($variation); if ($variation) { $this->variation = $variation; } } }