Ejemplo n.º 1
0
 /**
  * Cart constructor
  *
  * @param void
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     // Get user
     $juser = User::getInstance();
     //print_r($juser); die;
     //Set the user scope
     $this->warehouse->addAccessLevels($juser->getAuthorisedViewLevels());
     $this->cart = new \stdClass();
     /* Load current user cart */
     /* Check if there is a session or cookie cart */
     // Get cart from session
     $cart = $this->liftSessionCart();
     // If no session cart, try to locate a cookie cart (only for not logged in users)
     if (!$cart && $juser->get('guest')) {
         $cart = $this->liftCookie();
     }
     if ($cart) {
         // If cart found and user is logged in, verify if the cart is linked to the user cart in the DB
         if (!$juser->get('guest')) {
             if (empty($this->cart->linked) || !$this->cart->linked) {
                 // link carts if not linked (this should only happen when user logs in with a cart created while not logged in)
                 // if linking fails create a new cart
                 if (!$this->linkCarts()) {
                     $this->createCart();
                 }
             }
         } else {
             $this->cart->linked = 0;
         }
     } elseif (!$juser->get('guest')) {
         // Try to get the saved cart in the DB
         if (!$this->liftUserCart($juser->id)) {
             // If no session, no cookie, no DB cart -- create a brand new cart
             $this->createCart();
         }
     } else {
         $this->createCart();
     }
 }