Back to PhocacartWishlist class

Method updateWishListItems

public
updateWishListItems
()

Method updateWishListItems - Source code

public function updateWishListItems()
{
    if ($this->user->id > 0) {
        $db = Factory::getDBO();
        //$items	= se rialize($this->items);
        $date = Factory::getDate();
        $now = $date->toSql();
        if (!empty($this->items)) {
            $q = '';
            // Unfortunately we need to run SQL query more times in foreach as
            // ON DUPLICATE KEY UPDATE can work with one SQL uqery INSERT INTO ... VALUES (a,b,c), (a2,b2,c2)
            // but it does not work with multiple columns product_id x category_id x user_id in combination
            foreach ($this->items as $k => $v) {
                if (isset($v['product_id']) && isset($v['category_id']) && (int) $v['product_id'] > 0 && (int) $v['category_id'] > 0) {
                    $q = ' INSERT INTO #__phocacart_wishlists (product_id, category_id, user_id, date)';
                    $q .= ' VALUES (' . (int) $v['product_id'] . ', ' . (int) $v['category_id'] . ', ' . (int) $this->user->id . ',  ' . $db->quote($now) . ')';
                    $q .= ' ON DUPLICATE KEY UPDATE  product_id = VALUES(product_id), category_id = VALUES(category_id), user_id = VALUES(user_id), date = VALUES(date);';
                }
            }
            if ($q != '') {
                $db->setQuery($q);
                $db->execute();
            }
            return true;
        }
        return false;
    } else {
        $session = Factory::getSession();
        $session->set('wishlist', $this->items, 'phocaCart');
    }
    return false;
}