Back to PhocacartCart class

Method updateItemsDb

protected
updateItemsDb
()

Method updateItemsDb - Source code

/*
 * UPDATE - protected internal function to update only database
 */
protected function updateItemsDb()
{
    $db = Factory::getDBO();
    $items = serialize($this->items);
    $date = Factory::getDate();
    $now = $date->toSql();
    // Update multiple cart (include vendor, ticket)
    $query = ' SELECT user_id, vendor_id, ticket_id, unit_id, section_id FROM #__phocacart_cart_multiple' . ' WHERE user_id = ' . (int) $this->user->id . ' AND vendor_id = ' . (int) $this->vendor->id . ' AND ticket_id = ' . (int) $this->ticket->id . ' AND unit_id = ' . (int) $this->unit->id . ' AND section_id = ' . (int) $this->section->id . ' ORDER BY user_id LIMIT 1';
    $db->setQuery($query);
    $result = $db->loadRow();
    if (!empty($result)) {
        $query = 'UPDATE #__phocacart_cart_multiple' . ' SET cart = ' . $db->quote($items) . ',' . ' coupon = ' . (int) $this->coupon['id'] . ',' . ' date = ' . $db->quote($now) . ' WHERE user_id = ' . (int) $this->user->id . ' AND vendor_id = ' . (int) $this->vendor->id . ' AND ticket_id = ' . (int) $this->ticket->id . ' AND unit_id = ' . (int) $this->unit->id . ' AND section_id = ' . (int) $this->section->id;
        $db->setQuery($query);
        $db->execute();
    } else {
        if ((int) $this->user->id == 0 && (int) $this->vendor->id == 0) {
            // Not possible now
            // guests do not store cart to database
            // if userid == 0: 1) guest (not possible) 2) vendor uses pos (vendor must be > 0)
            // if vendorid == 0: 1) standard eshop - userid must be > 0)
            // ticket can be always zero
        } else {
            // COUPONMOVE
            $query = 'INSERT INTO #__phocacart_cart_multiple (user_id, vendor_id, ticket_id, unit_id, section_id, cart, coupon, date)' . ' VALUES (' . (int) $this->user->id . ', ' . (int) $this->vendor->id . ', ' . (int) $this->ticket->id . ', ' . (int) $this->unit->id . ', ' . (int) $this->section->id . ', ' . $db->quote($items) . ', ' . (int) $this->coupon['id'] . ', ' . $db->quote($now) . ');';
            $db->setQuery($query);
            $db->execute();
        }
    }
    // Update single cart (no vendor, no ticket)
    /*$query = 'INSERT INTO #__phocacart_cart (user_id, cart, date)'
                    .' VALUES ('.(int)$this->user->id.', '.$db->quote($items).', '.$db->quote($now).')'
                    .' ON DUPLICATE KEY UPDATE cart = VALUES (cart), date = VALUES (date)';
    
            $db->setQuery($query);
            $db->execute();*/
    return true;
}