Back to PhocacartCompare class

Method __construct

public
__construct
()

Method __construct - Source code

// real products (real products are stored in compare items but can differ, e.g. if product will be unpublished)
public function __construct()
{
    $session = Factory::getSession();
    $app = Factory::getApplication();
    $db = Factory::getDbo();
    $this->items = $session->get('compare', array(), 'phocaCart');
    // 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;
    }
}