Back to PhocacartCartDb class

Method getCartDb

public static
getCartDb
(mixed $userId, mixed $vendorId = 0, mixed $ticketId = 0, mixed $unitId = 0, mixed $sectionId = 0)

Method getCartDb - Source code

public static function getCartDb($userId, $vendorId = 0, $ticketId = 0, $unitId = 0, $sectionId = 0)
{
    if (!isset(self::$cart[$userId][$vendorId][$ticketId][$unitId][$sectionId])) {
        $db = Factory::getDBO();
        $query = ' SELECT c.cart, c.shipping, c.params_shipping, c.payment, c.params_payment, c.coupon, c.reward, c.loyalty_card_number,' . ' s.title as shippingtitle, s.method as shippingmethod, s.image as shippingimage, p.title as paymenttitle, p.method as paymentmethod, p.image as paymentimage,' . ' co.title as coupontitle, co.code as couponcode' . ' FROM #__phocacart_cart_multiple AS c' . ' LEFT JOIN #__phocacart_shipping_methods AS s ON c.shipping = s.id' . ' LEFT JOIN #__phocacart_payment_methods AS p ON c.payment = p.id' . ' LEFT JOIN #__phocacart_coupons AS co ON c.coupon = co.id' . ' WHERE c.user_id = ' . (int) $userId . ' AND c.vendor_id = ' . (int) $vendorId . ' AND c.ticket_id = ' . (int) $ticketId . ' AND c.unit_id = ' . (int) $unitId . ' AND c.section_id = ' . (int) $sectionId . ' ORDER BY c.cart';
        $db->setQuery($query);
        $cartDb = $db->loadAssoc();
        if (!empty($cartDb) && isset($cartDb['cart']) && $cartDb['cart'] != '') {
            $cartDb['cart'] = unserialize($cartDb['cart']);
            self::$cart[$userId][$vendorId][$ticketId][$unitId][$sectionId] = $cartDb;
        } else {
            $pos_payment_force = 0;
            $pos_shipping_force = 0;
            if (PhocacartPos::isPos()) {
                $app = Factory::getApplication();
                $paramsC = PhocacartUtils::getComponentParameters();
                $pos_payment_force = $paramsC->get('pos_payment_force', 0);
                $pos_shipping_force = $paramsC->get('pos_shipping_force', 0);
                if ((int) $pos_payment_force > 0) {
                    $pos_payment_force = PhocacartPayment::isPaymentMethodActive($pos_payment_force) === true ? (int) $pos_payment_force : 0;
                }
                if ((int) $pos_shipping_force > 0) {
                    $pos_shipping_force = PhocacartShipping::isShippingMethodActive($pos_shipping_force) === true ? (int) $pos_shipping_force : 0;
                }
            }
            $cartDb['cart'] = array();
            $cartDb['shipping'] = $pos_shipping_force;
            $cartDb['payment'] = $pos_payment_force;
            $cartDb['coupon'] = 0;
            $cartDb['discount'] = array();
            $cartDb['shippingtitle'] = '';
            $cartDb['shippingmethod'] = '';
            $cartDb['shippingimage'] = '';
            $cartDb['paymenttitle'] = '';
            $cartDb['paymentmethod'] = '';
            $cartDb['paymentimage'] = '';
            $cartDb['coupontitle'] = '';
            $cartDb['couponcode'] = '';
            $cartDb['reward'] = '';
            $cartDb['loyalty_card_number'] = '';
            $cartDb['params_shipping'] = array();
            $cartDb['params_payment'] = array();
            self::$cart[$userId][$vendorId][$ticketId][$unitId][$sectionId] = $cartDb;
        }
    }
    return self::$cart[$userId][$vendorId][$ticketId][$unitId][$sectionId];
}