public function __construct()
{
$session = Factory::getSession();
$this->user = PhocacartUser::getUser();
$app = Factory::getApplication();
$db = Factory::getDbo();
if ((int) $this->user->id > 0) {
// DATABASE - logged in user - Singleton because of not load data from database every time wishlist instance is loaded
// 1. Not found in DATABASE - maybe user logged in now, so:
// 2. We try to find the data in SESSION, if they are still in SESSION - load them to our wishlist class and then
// 3. Store them to DATABASE as all loged in users have wishlist in database and:
// 4. Remove them from SESSION as they are stored in DATABASE
$wLDb = $this->getWishListItemdDb();
// user logged in - try to get wishlist from db
$this->items = $wLDb;
// Recheck if we have access to all products:
$query = $this->getQueryList($this->items);
if ($query) {
//echo nl2br(str_replace('#__', 'jos_', $query));
$db->setQuery($query);
$this->itemsDb = $db->loadObjectList();
$tempItems = array();
if (!empty($this->itemsDb)) {
foreach ($this->itemsDb as $k => $v) {
$id = (int) $v->id;
if (isset($this->items[$id])) {
$tempItems[$id] = $this->items[$id];
}
}
}
$this->items = $tempItems;
}
if (empty($this->items)) {
$this->items = $session->get('wishlist', array(), 'phocaCart');
if (!empty($this->items)) {
$this->updateWishListItems();
$session->set('wishlist', array(), 'phocaCart');
}
}
} else {
$this->items = $session->get('wishlist', array(), 'phocaCart');
}
}