function fn_twg_set_response_categories(&$response, $params, $items_per_page = 0, $lang_code = CART_LANGUAGE) { if (empty($items_per_page)) { $result = fn_twg_api_get_categories($params, $lang_code); $response->setMeta(db_get_field("SELECT COUNT(*) FROM ?:categories"), 'total_items'); $response->setResponseList($result); } else { $default_params = array('depth' => 0, 'page' => 1); $params = array_merge($default_params, $params); $params['type'] = 'plain_tree'; $categories = fn_twg_api_get_categories($params, $lang_code); if (!empty($categories)) { $total = count($categories['category']); $params['page'] = !empty($params['page']) ? $params['page'] : 1; fn_paginate($params['page'], $total, $items_per_page); $view = fn_twg_get_view_object(); $pagination = $view->getTemplateVars('pagination'); $start = $pagination['prev_page'] * $pagination['items_per_page']; $end = $start + $items_per_page; $result = array(); for ($i = $start; $i < $end; $i++) { if (!isset($categories['category'][$i])) { break; } $result[] = $categories['category'][$i]; } $response->setResponseList(array('category' => $result)); $pagination_params = array('items_per_page' => !empty($items_per_page) ? $items_per_page : TWG_RESPONSE_ITEMS_LIMIT, 'page' => !empty($_REQUEST['page']) ? $_REQUEST['page'] : 1); fn_twg_set_response_pagination($response, $pagination_params); } } $category_id = !empty($params['id']) ? $params['id'] : 0; if (!empty($category_id)) { $parent_data = db_get_row("SELECT a.parent_id, b.category\n FROM ?:categories AS a\n LEFT JOIN ?:category_descriptions AS b\n ON a.parent_id = b.category_id\n WHERE a.category_id = ?i AND b.lang_code = ?s", $category_id, $lang_code); if (!empty($parent_data)) { $response->setMeta($parent_data['parent_id'], 'grand_id'); $response->setMeta($parent_data['category'], 'grand_category'); } $response->setMeta($category_id, 'category_id'); $category_data = array_pop(db_get_array("SELECT category, description\n FROM ?:category_descriptions\n WHERE category_id = ?i AND lang_code = ?s", $params['category_id'], $lang_code)); $response->setMeta($category_data['category'], 'category_name'); $response->setMeta($category_data['description'], 'description'); } }
} elseif ($meta['object'] == 'categories') { $object = fn_twg_get_api_category_data($_REQUEST['id'], $lang_code); $title = 'category'; } elseif ($meta['object'] == 'order') { $order_id = !empty($_REQUEST['id']) ? $_REQUEST['id'] : 0; TwigmoOrder::checkIfOrderAllowed($order_id, $_SESSION['auth'], $response); $object = TwigmoOrder::getOrderInfo($order_id); $title = 'order'; } elseif ($meta['object'] == 'ga_orders_info') { $order_id = !empty($_REQUEST['id']) ? $_REQUEST['id'] : 0; TwigmoOrder::checkIfOrderAllowed($order_id, $_SESSION['auth'], $response); $order_info = TwigmoOrder::getOrderInfo($order_id); if (!empty($order_info['is_parent_order']) && $order_info['is_parent_order'] == 'Y') { $order_info['child_ids'] = implode(',', db_get_fields("SELECT order_id FROM ?:orders WHERE parent_order_id = ?i", $order_id)); } $view = fn_twg_get_view_object(); $view->assign('order_info', $order_info); $mode = 'complete'; include_once Registry::get('config.dir.addons') . 'google_analytics/controllers/frontend/checkout.post.php'; foreach ($orders_info as &$order_info) { if (isset($order_info['products'])) { $order_info['items'] = array_values($order_info['products']); unset($order_info['products']); } } $response->setData($orders_info); $response->returnResponse(); } elseif ($meta['object'] == 'users') { $_auth =& $_SESSION['auth']; if (!empty($_auth['user_id'])) { $response->setData(fn_twg_get_user_info($_auth['user_id']));