quantity; } return $amount; } /** * * Get the cart array * **/ public static function get_cart(){ self::create_cart(); return $_SESSION[Config::$sitename]['cart'][Auth::user_id()]; } /** * * Clear the cart * **/ public static function clear_cart(){ $_SESSION[Config::$sitename]['cart'][Auth::user_id()] = array(); } public static function products(){ return self::$products; } public static function load_products(){ if(!Config::$cart_table) return; # create a collection for the products table $col = new Collection(Config::$cart_table); # loop through the products in the cart foreach(self::get_cart() as $id => $qty){ # select those products by their ids # field, value, use_quotes, or $col->where('id', $id, true, true); } # if there is any products in the cart at all if($_SESSION[Config::$sitename]['cart'][Auth::user_id()]){ # then load them all into the collection $col->get(); } # clear the static products array self::$products = []; # for each item in the collection foreach($col->items as $product){ # add a quantity property to the model $product->quantity = $_SESSION[Config::$sitename]['cart'][Auth::user_id()][$product->id]; # add the product object into the products array self::$products[] = $product; } } /** * * Create the cart array if it doesn't already exist * **/ private static function create_cart(){ if(!isset($_SESSION[Config::$sitename]['cart'][Auth::user_id()])){ $_SESSION[Config::$sitename]['cart'][Auth::user_id()] = array(); } } } if(Config::$database['database']){ Cart::load_products(); }