protected function getCart($user_id, $get_cart_products = false) { list($carts) = fn_get_carts(array('user_id' => $user_id, 'company_id' => $this->getCompanyId())); if (!$carts) { return array(); } $cart = reset($carts); if ($get_cart_products) { $params = array(); if (fn_allowed_for('ULTIMATE')) { $params['c_company_id'] = $cart['company_id']; } $cart['products'] = fn_get_cart_products($cart['user_id'], $params); } return $cart; }
if ($mode == 'm_delete_all') { if (!empty($_SESSION['abandoned_carts'])) { if (fn_allowed_for('ULTIMATE')) { foreach ($_SESSION['abandoned_carts'] as $company_id => $user_ids) { fn_delete_user_cart($user_ids, $company_id); } } else { fn_delete_user_cart($_SESSION['abandoned_carts']); } } } return array(CONTROLLER_STATUS_OK, 'cart.cart_list'); } if ($mode == 'cart_list') { $item_types = fn_get_cart_content_item_types(); list($carts_list, $search) = fn_get_carts($_REQUEST, Registry::get('settings.Appearance.admin_elements_per_page')); if (!empty($_REQUEST['user_id'])) { if (fn_allowed_for('ULTIMATE') && !empty($_REQUEST['c_company_id'])) { $cart_products = db_get_array("SELECT ?:user_session_products.item_id, ?:user_session_products.item_type, ?:user_session_products.product_id, ?:user_session_products.amount, ?:user_session_products.price, ?:user_session_products.extra, ?:product_descriptions.product" . " FROM ?:user_session_products" . " LEFT JOIN ?:product_descriptions ON ?:user_session_products.product_id = ?:product_descriptions.product_id AND ?:product_descriptions.lang_code = ?s" . " WHERE ?:user_session_products.user_id = ?i AND ?:user_session_products.company_id = ?i AND ?:user_session_products.type = 'C' AND ?:user_session_products.item_type IN (?a)", DESCR_SL, $_REQUEST['user_id'], $_REQUEST['c_company_id'], $item_types); } else { $cart_products = db_get_array("SELECT ?:user_session_products.item_id, ?:user_session_products.item_type, ?:user_session_products.product_id, ?:user_session_products.amount, ?:user_session_products.price, ?:user_session_products.extra, ?:product_descriptions.product" . " FROM ?:user_session_products" . " LEFT JOIN ?:product_descriptions ON ?:user_session_products.product_id = ?:product_descriptions.product_id AND ?:product_descriptions.lang_code = ?s" . " WHERE ?:user_session_products.user_id = ?i AND ?:user_session_products.type = 'C' AND ?:user_session_products.item_type IN (?a)", DESCR_SL, $_REQUEST['user_id'], $item_types); } if (!empty($cart_products)) { foreach ($cart_products as $key => $product) { $cart_products[$key]['extra'] = unserialize($product['extra']); } } Tygh::$app['view']->assign('cart_products', $cart_products); Tygh::$app['view']->assign('sl_user_id', $_REQUEST['user_id']); } if (!empty($carts_list) && is_array($carts_list)) {
} if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($mode == 'm_delete') { if (!empty($_REQUEST['user_ids'])) { fn_detele_user_cart($_REQUEST['user_ids']); } } elseif ($mode == 'm_all_delete') { if (!empty($_SESSION['abandoned_carts'])) { fn_detele_user_cart($_SESSION['abandoned_carts']); } } return array(CONTROLLER_STATUS_OK, "cart.cart_list"); } if ($mode == 'cart_list') { $item_types = fn_get_cart_content_item_types(); list($carts_list, $search) = fn_get_carts($_REQUEST); if (!empty($_REQUEST['user_id'])) { $cart_products = db_get_array("SELECT ?:user_session_products.item_id, ?:user_session_products.item_type, ?:user_session_products.product_id, ?:user_session_products.amount, ?:user_session_products.price, ?:user_session_products.extra, ?:product_descriptions.product FROM ?:user_session_products LEFT JOIN ?:product_descriptions ON ?:user_session_products.product_id = ?:product_descriptions.product_id AND ?:product_descriptions.lang_code = ?s WHERE ?:user_session_products.user_id = ?i AND ?:user_session_products.type = 'C' AND ?:user_session_products.item_type IN (?a)", DESCR_SL, $_REQUEST['user_id'], $item_types); if (!empty($cart_products)) { foreach ($cart_products as $key => $product) { $cart_products[$key]['extra'] = unserialize($product['extra']); } } $view->assign('cart_products', $cart_products); $view->assign('sl_user_id', $_REQUEST['user_id']); } if (!empty($carts_list) && is_array($carts_list)) { $all_cart_products = db_get_hash_array("SELECT user_id, SUM(amount) as count, SUM(amount) as sum, SUM(amount * price) as total FROM ?:user_session_products WHERE user_id IN (?n) AND type = 'C' AND item_type IN (?a) GROUP BY user_id", 'user_id', array_keys($carts_list), $item_types); foreach ($carts_list as $u_id => $cart) { if (!empty($all_cart_products[$u_id])) { $carts_list[$u_id]['cart_products'] = $all_cart_products[$u_id]['count'];