function fn_required_products_get_product_data_post(&$product, &$auth) { if (!empty($product['product_id'])) { list($required) = fn_get_products(array('for_required_product' => $product['product_id'])); if (count($required)) { $product['have_required'] = 'Y'; $ids = fn_array_column($required, 'product_id'); $have = fn_required_products_get_existent($auth, $ids); $product['required_products'] = array(); fn_gather_additional_products_data($required, array('get_icon' => true, 'get_detailed' => true, 'get_options' => true, 'get_discounts' => true)); foreach ($required as $entry) { $id = $entry['product_id']; $product['required_products'][$id] = $entry; $product['required_products'][$id]['bought'] = $have && in_array($id, $have) ? 'Y' : 'N'; } if (!empty($have) && count($have) >= count($ids)) { $product['can_add_to_cart'] = 'Y'; } else { $product['can_add_to_cart'] = 'N'; } } else { $product['have_required'] = 'N'; } } }
function fn_get_banners($params = array(), $lang_code = CART_LANGUAGE) { $default_params = array('items_per_page' => 0); $params = array_merge($default_params, $params); $sortings = array('position' => '?:banners.position', 'timestamp' => '?:banners.timestamp', 'name' => '?:banner_descriptions.banner'); $condition = $limit = ''; if (!empty($params['limit'])) { $limit = db_quote(' LIMIT 0, ?i', $params['limit']); } $sorting = db_sort($params, $sortings, 'name', 'asc'); $condition = AREA == 'A' ? '' : " AND ?:banners.status = 'A' "; $condition .= fn_get_localizations_condition('?:banners.localization'); $condition .= AREA == 'A' ? '' : " AND (?:banners.type != 'G' OR ?:banner_images.banner_image_id IS NOT NULL) "; if (!empty($params['item_ids'])) { $condition .= db_quote(' AND ?:banners.banner_id IN (?n)', explode(',', $params['item_ids'])); } if (!empty($params['period']) && $params['period'] != 'A') { list($params['time_from'], $params['time_to']) = fn_create_periods($params); $condition .= db_quote(" AND (?:banners.timestamp >= ?i AND ?:banners.timestamp <= ?i)", $params['time_from'], $params['time_to']); } fn_set_hook('get_banners', $params, $condition, $sorting, $limit, $lang_code); $fields = array('?:banners.banner_id', '?:banners.type', '?:banners.target', '?:banners.status', '?:banners.position', '?:banner_descriptions.banner', '?:banner_descriptions.description', '?:banner_descriptions.url', '?:banner_images.banner_image_id'); if (fn_allowed_for('ULTIMATE')) { $fields[] = '?:banners.company_id'; } $banners = db_get_hash_array("SELECT ?p FROM ?:banners " . "LEFT JOIN ?:banner_descriptions ON ?:banner_descriptions.banner_id = ?:banners.banner_id AND ?:banner_descriptions.lang_code = ?s" . "LEFT JOIN ?:banner_images ON ?:banner_images.banner_id = ?:banners.banner_id AND ?:banner_images.lang_code = ?s" . "WHERE 1 ?p ?p ?p", 'banner_id', implode(", ", $fields), $lang_code, $lang_code, $condition, $sorting, $limit); $banner_image_ids = fn_array_column($banners, 'banner_image_id'); $images = fn_get_image_pairs($banner_image_ids, 'promo', 'M', true, false, $lang_code); foreach ($banners as $banner_id => $banner) { $banners[$banner_id]['main_pair'] = !empty($images[$banner['banner_image_id']]) ? reset($images[$banner['banner_image_id']]) : array(); } fn_set_hook('get_banners_post', $banners, $params); return array($banners, $params); }
/** * Gets identifiers of containers from array of containers data as position => data * * @param array $containers Array of containers data as position => data * @return array Array of containers ids */ public static function getIds($containers) { $container_ids = array(); if (is_array($containers)) { $container_ids = fn_array_column($containers, 'container_id'); } return $container_ids; }
function fn_sb_format_page_title() { $page_title = Tygh::$app['view']->getTemplateVars('page_title'); if (empty($page_title)) { $breadcrumbs = Tygh::$app['view']->getTemplateVars('breadcrumbs'); $breadcrumb_titles = fn_array_column($breadcrumbs, 'title'); $page_title = implode(' :: ', $breadcrumb_titles); } return $page_title; }
/** * Returns list of pages * <i>$params</i> - Array of various parameters used for element selection: * <ul> * <li>page_id - If defined and not zero, get data for the page with this id; otherwise get data for all pages</li> * <li>item_ids - A comma-delimited page identifiers list; if defined, get data for the pages with these ids; otherwise get data for all pages</li> * <li>except_id - Identifier of the page to be excluded from the result</li> * <li>parent_id - If defined and not zero, get data for the pages with this parent page id</li> * <li>active_page_id - Identifier of the page being currently shown</li> * <li>current_page_id - The same as <i>active_page_id</i></li> * * <li>add_root - If defined, additionally returns root element data</li> * <li>subpages - If defined, additionally returns subpages</li> * <li>get_tree - If defined, pages will be returned as tree; otherwise as list. Possible value: <i>plain</i></li> * <li>visible - For pages tree: show visible branch only</li> * * <li>page - Number of the current page for pagination</li> * * <li>pdescr - If defined, additionally returns descriptions. Possible value: <i>Y</i></li> * * <li>vendor_pages - If defined, try to return pages for the company defined by <i>company_id</i></li> * <li>company_id - If <i>vendor_pages</i> is defined: if defined, get data for the company with this id</li> * * <li>neighbours - If defined, try to return neighbor pages for the page with the id <i>neighbours_page_id</i></li> * <li>neighbours_page_id - If <i>neighbours</i> is defined: if defined, get neighbor pages for the page with this id</li> * * <li>limit - If defined, used to limit your MySQL query results by this value</li> * <li>sort_by - Table field to sort by, default is position</li> * <li>sort_order - Sorting direction, ascending or descending; Possible values: <i>asc</i> or <i>desc</i>, default is <i>asc</i></li> * * <li>status - If defined, returns pages only with this status. Can be comma delimited statuses list</li> * * <li>period - If defined, get pages by time period. Time period is generated by ::fn_create_periods</li> * <li>time_from - Returns pages created earlier than this time</li> * <li>time_to - Returns pages created later than this time</li> * * <li>parent_page_id - Deprecated, <i>parent_id</i> used instead</li> * <li>from_page_id - Deprecated, <i>parent_id</i> used instead</li> * </ul> * @param array $params Array of params * @param int $items_per_page Limit items per page * @param string $lang_code 2-letter language code * @return array List of pages, params */ function fn_get_pages($params = array(), $items_per_page = 0, $lang_code = CART_LANGUAGE) { /** * Changes params for selecting pages * * @param array $params Pages search params * @param int $items_per_page Items per page * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) */ fn_set_hook('get_pages_pre', $params, $items_per_page, $lang_code); $view_type = 'pages'; if (!empty($params['page_type']) && fn_is_exclusive_page_type($params['page_type'])) { $view_type .= '_' . $params['page_type']; } // Init filter $params = LastView::instance()->update($view_type, $params); $default_params = array('page_id' => 0, 'page' => 1, 'visible' => false, 'get_tree' => '', 'pdescr' => '', 'subpages' => '', 'match' => '', 'page_type' => '', 'items_per_page' => $items_per_page); if (is_array($params)) { $params = array_merge($default_params, $params); } else { $params = $default_params; } if (empty($params['pname']) && empty($params['pdescr']) && empty($params['subpages'])) { $params['pname'] = 'Y'; } $fields = array('?:pages.*'); if (!empty($params['simple'])) { $fields[] = '?:page_descriptions.page'; } else { $fields[] = '?:page_descriptions.*'; } // Define sort fields $sortings = array('position' => array('?:pages.position', '?:page_descriptions.page'), 'name' => '?:page_descriptions.page', 'timestamp' => '?:pages.timestamp', 'type' => '?:pages.page_type', 'multi_level' => array('?:pages.parent_id', '?:pages.position', '?:page_descriptions.page')); $auth =& Tygh::$app['session']['auth']; $condition = '1'; $join = $limit = $group_by = ''; if (isset($params['q']) && fn_string_not_empty($params['q'])) { $params['q'] = trim($params['q']); if ($params['match'] == 'any') { $pieces = fn_explode(' ', $params['q']); $search_type = ' OR '; } elseif ($params['match'] == 'all') { $pieces = fn_explode(' ', $params['q']); $search_type = ' AND '; } else { $pieces = array($params['q']); $search_type = ''; } $_condition = array(); foreach ($pieces as $piece) { if (strlen($piece) == 0) { continue; } $tmp = array(); if (!empty($params['pname']) && $params['pname'] == 'Y') { $tmp[] = db_quote("?:page_descriptions.page LIKE ?l", "%{$piece}%"); // check search words } if ($params['pdescr'] == 'Y') { $tmp[] = db_quote("?:page_descriptions.description LIKE ?l", "%{$piece}%"); } if (!empty($tmp)) { $_condition[] = '(' . implode(' OR ', $tmp) . ')'; } } if (!empty($_condition)) { $condition .= ' AND (' . implode($search_type, $_condition) . ')'; } } $condition .= fn_get_company_condition('?:pages.company_id'); if (isset($params['parent_id']) && $params['parent_id'] !== '') { $p_ids = array(); if ($params['subpages'] == 'Y') { $p_ids = db_get_fields("SELECT a.page_id FROM ?:pages as a LEFT JOIN ?:pages as b ON b.page_id = ?i WHERE a.id_path LIKE CONCAT(b.id_path, '/%')", $params['parent_id']); } $p_ids[] = $params['parent_id']; $condition .= db_quote(" AND ?:pages.parent_id IN (?n)", $p_ids); } if (isset($params['parent_page_id'])) { // set parent id, that was set in block properties $params['from_page_id'] = $params['parent_page_id']; } if (!empty($params['from_page_id'])) { $from_id_path = db_get_field("SELECT id_path FROM ?:pages WHERE page_id = ?i", $params['from_page_id']); $condition .= db_quote(" AND ?:pages.id_path LIKE ?l", "{$from_id_path}/%"); } if (!empty($params['status'])) { $condition .= db_quote(" AND ?:pages.status IN (?a)", $params['status']); } if (!empty($params['vendor_pages']) && empty($params['company_id'])) { return array(array(), $params); } elseif (!empty($params['company_id'])) { $condition .= db_quote(" AND ?:pages.company_id = ?i", $params['company_id']); } if (empty($params['full_search'])) { $types = fn_get_page_type_filter($params['page_type']); if ($types) { $condition .= db_quote(" AND ?:pages.page_type IN (?a)", array_keys($types)); } else { $condition .= db_quote(" AND 0"); } } if (!empty($params['visible'])) { // for pages tree: show visible branch only $page_ids = array(); if (!empty($params['current_page_id'])) { $cur_id_path = db_get_field("SELECT id_path FROM ?:pages WHERE page_id = ?i", $params['current_page_id']); if (!empty($cur_id_path)) { $page_ids = explode('/', $cur_id_path); } } if (!empty($from_id_path)) { $_page_ids = explode('/', $from_id_path); $page_ids = array_merge($page_ids, $_page_ids); $page_ids = array_unique($page_ids); } $page_ids[] = $params['page_id']; $condition .= db_quote(" AND ?:pages.parent_id IN (?n)", $page_ids); } if (!empty($params['period']) && $params['period'] != 'A') { list($params['time_from'], $params['time_to']) = fn_create_periods($params); $condition .= db_quote(" AND (?:pages.timestamp >= ?i AND ?:pages.timestamp <= ?i)", $params['time_from'], $params['time_to']); } if (!empty($params['item_ids'])) { // get only defined pages $condition .= db_quote(" AND ?:pages.page_id IN (?n)", explode(',', $params['item_ids'])); } if (!empty($params['except_id']) && (empty($params['item_ids']) || !empty($params['item_ids']) && !in_array($params['except_id'], explode(',', $params['item_ids'])))) { $condition .= db_quote(' AND ?:pages.page_id != ?i AND ?:pages.parent_id != ?i', $params['except_id'], $params['except_id']); } if (AREA != 'A') { $condition .= " AND (" . fn_find_array_in_set($auth['usergroup_ids'], '?:pages.usergroup_ids', true) . ")"; $condition .= fn_get_localizations_condition('?:pages.localization', true); $condition .= db_quote(" AND (use_avail_period = ?s OR (use_avail_period = ?s AND avail_from_timestamp <= ?i AND avail_till_timestamp >= ?i))", 'N', 'Y', TIME, TIME); } $join = db_quote('LEFT JOIN ?:page_descriptions ON ?:pages.page_id = ?:page_descriptions.page_id AND ?:page_descriptions.lang_code = ?s', $lang_code); if (!empty($params['limit'])) { $limit = db_quote(" LIMIT 0, ?i", $params['limit']); } if (!empty($params['neighbours'])) { $parent_ids = array(); if (!empty($params['neighbours_page_id'])) { $id_path = db_get_field("SELECT id_path FROM ?:pages WHERE page_id = ?i", $params['neighbours_page_id']); $parent_ids = explode('/', $id_path); if (count($parent_ids) == 1) { array_unshift($parent_ids, 0); } $params['root_id'] = $parent_ids[0]; } else { $parent_ids[] = 0; } $condition .= db_quote(" AND ?:pages.parent_id IN (?n)", array_unique($parent_ids)); } fn_set_hook('get_pages', $params, $join, $condition, $fields, $group_by, $sortings, $lang_code); if (!empty($params['get_tree'])) { $params['sort_by'] = 'multi_level'; } $sorting = db_sort($params, $sortings, 'position', 'asc'); if (!empty($group_by)) { $group_by = ' GROUP BY ' . $group_by; } // Get search conditions if (!empty($params['get_conditions'])) { return array($fields, $join, $condition); } if (!empty($params['items_per_page'])) { $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:pages.page_id)) FROM ?:pages ?p WHERE ?p ?p ?p", $join, $condition, $group_by, $sorting); $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']); } $pages = db_get_hash_array("SELECT " . implode(', ', $fields) . " FROM ?:pages ?p WHERE ?p ?p ?p ?p", 'page_id', $join, $condition, $group_by, $sorting, $limit); if (!empty($params['active_page_id']) && !empty($pages[$params['active_page_id']])) { $pages[$params['active_page_id']]['active'] = true; Registry::set('runtime.active_page_ids', explode('/', $pages[$params['active_page_id']]['id_path'])); } if (!empty($pages)) { foreach ($pages as $k => $v) { $pages[$k]['level'] = substr_count($v['id_path'], '/'); } if (!empty($params['get_tree'])) { $delete_keys = array(); foreach ($pages as $k => $v) { if (!empty($v['parent_id']) && !empty($pages[$v['parent_id']])) { $pages[$v['parent_id']]['subpages'][$v['page_id']] =& $pages[$k]; $delete_keys[] = $k; } if (!empty($v['parent_id']) && (!isset($params['root_id']) && empty($pages[$v['parent_id']]) || isset($params['root_id']) && $v['parent_id'] != $params['root_id']) && (empty($params['from_page_id']) || $params['from_page_id'] != $v['parent_id'])) { // delete pages that don't have parent. FIXME: should be done on database layer $delete_keys[] = $k; } } foreach ($delete_keys as $k) { unset($pages[$k]); } } elseif (!empty($params['item_ids'])) { $pages = fn_sort_by_ids($pages, explode(',', $params['item_ids']), 'page_id'); } if ($params['get_tree'] == 'plain') { $pages = fn_multi_level_to_plain($pages, 'subpages'); } if (!empty($params['get_children_count'])) { $where_condition = !empty($params['except_id']) ? db_quote(' AND page_id != ?i', $params['except_id']) : ''; if ($params['get_tree'] == 'plain') { $_page_ids = fn_array_column($pages, 'page_id'); } else { $_page_ids = array_keys($pages); } $children = db_get_hash_single_array("SELECT parent_id, COUNT(page_id) as children FROM ?:pages WHERE parent_id IN (?n) ?p GROUP BY parent_id", array('parent_id', 'children'), $_page_ids, $where_condition); if (!empty($children)) { if ($params['get_tree'] == 'plain') { foreach ($pages as $_id => $_p) { if (!empty($children[$_p['page_id']])) { $pages[$_id]['has_children'] = true; } } } else { foreach ($children as $k => $v) { $pages[$k]['has_children'] = !empty($v); } } } } } if (!empty($params['add_root'])) { array_unshift($pages, array('page_id' => '', 'page' => $params['add_root'])); } fn_dropdown_appearance_cut_second_third_levels($pages, 'subpages', $params); fn_set_hook('post_get_pages', $pages, $params, $lang_code); LastView::instance()->processResults($view_type, $pages, $params); return array($pages, $params); }
} return array(CONTROLLER_STATUS_OK, 'statuses.manage?type=' . $_REQUEST['type']); } if ($mode == 'update') { $status_data = fn_get_status_data($_REQUEST['status'], $_REQUEST['type']); Tygh::$app['view']->assign('status_data', $status_data); Tygh::$app['view']->assign('type', $_REQUEST['type']); Tygh::$app['view']->assign('status_params', fn_get_status_params_definition($_REQUEST['type'])); } elseif ($mode == 'manage') { $section_data = array(); $statuses = fn_get_statuses($_REQUEST['type'], array(), false, false, DESCR_SL); Tygh::$app['view']->assign('statuses', $statuses); $type = !empty($_REQUEST['type']) ? $_REQUEST['type'] : STATUSES_ORDER; Tygh::$app['view']->assign('type', $type); Tygh::$app['view']->assign('status_params', fn_get_status_params_definition($type)); $existing_statuses = fn_array_column($statuses, 'status'); // Orders only if ($type == STATUSES_ORDER) { Tygh::$app['view']->assign('title', __('order_statuses')); $existing_statuses[] = 'N'; $existing_statuses[] = 'T'; } $can_create_status = !!array_diff(range('A', 'Z'), $existing_statuses); Tygh::$app['view']->assign('can_create_status', $can_create_status); } function fn_get_status_params_definition($type) { $status_params = array(); if ($type == STATUSES_ORDER) { $status_params = array('color' => array('type' => 'color', 'label' => 'color'), 'notify' => array('type' => 'checkbox', 'label' => 'notify_customer', 'default_value' => 'Y'), 'notify_department' => array('type' => 'checkbox', 'label' => 'notify_orders_department'), 'notify_vendor' => array('type' => 'checkbox', 'label' => 'notify_vendor'), 'inventory' => array('type' => 'select', 'label' => 'inventory', 'variants' => array('I' => 'increase', 'D' => 'decrease')), 'remove_cc_info' => array('type' => 'checkbox', 'label' => 'remove_cc_info', 'default_value' => 'Y'), 'repay' => array('type' => 'checkbox', 'label' => 'pay_order_again'), 'appearance_type' => array('type' => 'select', 'label' => 'invoice_credit_memo', 'variants' => array('D' => 'default', 'I' => 'invoice', 'C' => 'credit_memo', 'O' => 'order'))); if (fn_allowed_for('ULTIMATE:FREE')) {
fn_echo('.'); $sqls_arr = array(); } } while ($end <= $max); if (count($sqls_arr) > 0) { db_query("INSERT INTO ?:se_queue (`data`, `action`, `company_id`, `lang_code`) VALUES " . join(',', $sqls_arr)); } fn_echo('.'); // // reSend all active filters // if (!fn_allowed_for('ULTIMATE:FREE') && fn_se_get_setting('use_navigation', $company_id, DEFAULT_LANGUAGE) == 'Y') { db_query("INSERT INTO ?:se_queue (`data`, `action`, `company_id`, `lang_code`) VALUES ('N;', 'facet_delete_all', '{$company_id}', '{$lang_code}')"); list($filters, ) = fn_get_product_filters(array('get_descriptions' => false, 'get_variants' => false, 'status' => 'A')); if (!empty($filters)) { $filter_ids = fn_array_column($filters, 'filter_id'); db_query("INSERT INTO ?:se_queue (`data`, `action`, `company_id`, `lang_code`) VALUES (?s, 'facet_update', '{$company_id}', '{$lang_code}')", serialize($filter_ids)); } } db_query("INSERT INTO ?:se_queue (`data`, `action`, `company_id`, `lang_code`) VALUES ('N;', 'pages_update', '{$company_id}', '{$lang_code}')"); db_query("INSERT INTO ?:se_queue (`data`, `action`, `company_id`, `lang_code`) VALUES ('N;', 'categories_update', '{$company_id}', '{$lang_code}')"); db_query("INSERT INTO ?:se_queue (`data`, `action`, `company_id`, `lang_code`) VALUES ('N;', 'end_full_import', '{$company_id}', '{$lang_code}')"); $status = true; } elseif ($q['action'] == 'start_full_import') { $status = fn_se_send_request('/api/state/update/json', $private_key, array('full_import' => 'start')); if ($status == true) { fn_se_set_import_status('processing', $company_id, $lang_code); } } elseif ($q['action'] == 'end_full_import') { $status = fn_se_send_request('/api/state/update/json', $private_key, array('full_import' => 'done')); if ($status == true) {
function fn_ult_get_statuses_post(&$statuses, &$join, &$condition, &$type, &$status_to_select, &$additional_statuses, &$exclude_parent, &$lang_code, &$company_id) { $_company_id = $company_id ?: fn_get_runtime_company_id(); if ($_company_id) { $data = db_get_hash_array("SELECT status_id, email_subj, email_header" . " FROM ?:ult_status_descriptions" . " WHERE status_id IN (?n)" . " AND company_id = ?i" . " AND lang_code = ?s", 'status_id', fn_array_column($statuses, 'status_id'), $_company_id, $lang_code); foreach ($statuses as $status => $status_data) { if (isset($data[$status_data['status_id']])) { $statuses[$status] = array_merge($statuses[$status], $data[$status_data['status_id']]); } } } }
/** * Load product count by templates * * @param array $templates */ public static function loadProductCount(array &$templates) { if (empty($templates)) { return; } $ids = fn_array_column($templates, 'template_id'); $sql = "SELECT COUNT(*) AS count, ebay_template_id FROM ?:products" . " WHERE ebay_template_id IN (?n) GROUP BY ebay_template_id"; $result = db_get_hash_array($sql, 'ebay_template_id', $ids); foreach ($templates as &$template) { $template['product_count'] = 0; if (isset($result[$template['template_id']])) { $template['product_count'] = $result[$template['template_id']]['count']; } } unset($template); }
/** * Gets full category data by its id * * @param int $category_id ID of category * @param string $lang_code 2-letters language code * @param string $field_list List of categories table' fields. If empty, data from all fields will be returned. * @param boolean $get_main_pair Get or not category image * @param boolean $skip_company_condition Select data for other stores categories. By default is false. This flag is used in ULT for displaying common categories in picker. * @param boolean $preview Category is requested in a preview mode * @param boolean $get_full_path Get full category path with all ancestors * @return mixed Array with category data. */ function fn_get_category_data($category_id = 0, $lang_code = CART_LANGUAGE, $field_list = '', $get_main_pair = true, $skip_company_condition = false, $preview = false, $get_full_path = false) { // @TODO: remove in 4.3.2, this line is needed for backward compatibility since 4.3.1 $field_list = str_replace(array('selected_layouts', 'default_layout', 'product_details_layout'), array('selected_views', 'default_view', 'product_details_view'), $field_list); /** * Changes select category data conditions * * @param int $category_id Category ID * @param array $field_list List of fields for retrieving * @param boolean $get_main_pair Get or not category image * @param boolean $skip_company_condition Select data for other stores categories. By default is false. This flag is used in ULT for displaying common categories in picker. * @param string $lang_code 2-letters language code */ fn_set_hook('get_category_data_pre', $category_id, $field_list, $get_main_pair, $skip_company_condition, $lang_code); $auth =& Tygh::$app['session']['auth']; $conditions = ''; if (AREA == 'C' && !$preview) { $conditions = "AND (" . fn_find_array_in_set($auth['usergroup_ids'], '?:categories.usergroup_ids', true) . ")"; } if (empty($field_list)) { $descriptions_list = "?:category_descriptions.*"; $field_list = "?:categories.*, {$descriptions_list}"; } if (fn_allowed_for('ULTIMATE') && !$skip_company_condition) { $conditions .= fn_get_company_condition('?:categories.company_id'); } $join = ''; /** * Changes SQL parameters before select category data * * @param int $category_id Category ID * @param array $field_list SQL fields to be selected in an SQL-query * @param string $join String with the complete JOIN information (JOIN type, tables and fields) for an SQL-query * @param string $lang_code 2-letters language code * @param string $conditions Condition params */ fn_set_hook('get_category_data', $category_id, $field_list, $join, $lang_code, $conditions); $category_data = db_get_row("SELECT {$field_list} FROM ?:categories" . " LEFT JOIN ?:category_descriptions" . " ON ?:category_descriptions.category_id = ?:categories.category_id" . " AND ?:category_descriptions.lang_code = ?s ?p" . " WHERE ?:categories.category_id = ?i ?p", $lang_code, $join, $category_id, $conditions); if (!empty($category_data)) { $category_data['category_id'] = $category_id; // Generate meta description automatically if (empty($category_data['meta_description']) && defined('AUTO_META_DESCRIPTION') && AREA != 'A') { $category_data['meta_description'] = !empty($category_data['description']) ? fn_generate_meta_description($category_data['description']) : ''; } if ($get_main_pair == true) { $category_data['main_pair'] = fn_get_image_pairs($category_id, 'category', 'M', true, true, $lang_code); } if (!empty($category_data['selected_views'])) { $category_data['selected_views'] = unserialize($category_data['selected_views']); } else { $category_data['selected_views'] = array(); } // @TODO: remove in 4.3.2 - these three (3) conditions are needed for backward compatibility since 4.3.1 if (isset($category_data['selected_views'])) { $category_data['selected_layouts'] = $category_data['selected_views']; } if (isset($category_data['default_view'])) { $category_data['default_layout'] = $category_data['default_view']; } if (isset($category_data['product_details_view'])) { $category_data['product_details_layout'] = $category_data['product_details_view']; } if ($get_full_path) { $path = explode('/', $category_data['id_path']); if ($path) { $ancestors = db_get_array("SELECT ?:categories.category_id, ?:category_descriptions.category" . " FROM ?:categories" . " LEFT JOIN ?:category_descriptions" . " ON ?:category_descriptions.category_id = ?:categories.category_id" . " AND ?:category_descriptions.lang_code = ?s" . " WHERE ?:categories.category_id IN (?n)", $lang_code, $path); $ancestors = fn_array_column(fn_sort_by_ids($ancestors, $path, 'category_id'), 'category', 'category_id'); $category_data['path_names'] = $ancestors; } } } /** * Changes category data * * @param int $category_id Category ID * @param array $field_list List of fields for retrieving * @param boolean $get_main_pair Get or not category image * @param boolean $skip_company_condition Select data for other stores categories. By default is false. This flag is used in ULT for displaying common categories in picker. * @param string $lang_code 2-letters language code * @param array $category_data Array with category fields */ fn_set_hook('get_category_data_post', $category_id, $field_list, $get_main_pair, $skip_company_condition, $lang_code, $category_data); return !empty($category_data) ? $category_data : false; }
/** * Gets additional products data * * @param array $products Array with products * @param array $params Array of flags which determines which data should be gathered * @return array Array of products with additional information */ function fn_gather_additional_products_data(&$products, $params) { /** * Change parameters for gathering additional products data * * @param array $products List of products * @param array $params Parameters for gathering data */ fn_set_hook('gather_additional_products_data_pre', $products, $params); if (empty($products)) { return; } // Set default values to input params $default_params = array('get_icon' => false, 'get_detailed' => false, 'get_additional' => false, 'get_options' => true, 'get_discounts' => true, 'get_features' => false, 'get_extra' => false, 'get_taxed_prices' => true, 'get_for_one_product' => !is_array(reset($products)) ? true : false, 'detailed_params' => true, 'features_display_on' => 'C'); $params = array_merge($default_params, $params); $auth =& $_SESSION['auth']; $allow_negative_amount = Registry::get('settings.General.allow_negative_amount'); $inventory_tracking = Registry::get('settings.General.inventory_tracking'); if ($params['get_for_one_product']) { $products = array($products); } $product_ids = fn_array_column($products, 'product_id'); if ($params['get_icon'] || $params['get_detailed']) { $products_images = fn_get_image_pairs($product_ids, 'product', 'M', $params['get_icon'], $params['get_detailed'], CART_LANGUAGE); } if ($params['get_additional']) { $additional_images = fn_get_image_pairs($product_ids, 'product', 'A', true, true, CART_LANGUAGE); } if ($params['get_options']) { $product_options = fn_get_product_options($product_ids, CART_LANGUAGE); } else { $has_product_options = db_get_hash_array("SELECT a.option_id, a.product_id FROM ?:product_options AS a WHERE a.product_id IN (?n) AND a.status = 'A'", 'product_id', $product_ids); $has_product_options_links = db_get_hash_array("SELECT c.option_id, c.product_id FROM ?:product_global_option_links AS c LEFT JOIN ?:product_options AS a ON a.option_id = c.option_id WHERE a.status = 'A' AND c.product_id IN (?n)", 'product_id', $product_ids); } /** * Changes before gathering additional products data * * @param array $product_ids Array of product identifiers * @param array $params Parameteres for gathering data * @param array $products Array of products * @param mixed $auth Array of user authentication data * @param array $products_images Array with product main images * @param array $additional_images Array with product additional images * @param array $product_options Array with product options * @param array $has_product_options Array of flags determines if product has options * @param array $has_product_options_links Array of flags determines if product has option links */ fn_set_hook('gather_additional_products_data_params', $product_ids, $params, $products, $auth, $products_images, $additional_images, $product_options, $has_product_options, $has_product_options_links); // foreach $products foreach ($products as &$_product) { $product = $_product; $product_id = $product['product_id']; // Get images if ($params['get_icon'] == true || $params['get_detailed'] == true) { if (empty($product['main_pair']) && !empty($products_images[$product_id])) { $product['main_pair'] = reset($products_images[$product_id]); } } if ($params['get_additional'] == true) { if (empty($product['image_pairs']) && !empty($additional_images[$product_id])) { $product['image_pairs'] = $additional_images[$product_id]; } } if (isset($product['price']) && !isset($product['base_price'])) { $product['base_price'] = $product['price']; // save base price (without discounts, etc...) } /** * Changes before gathering product options * * @param array $product Product data * @param mixed $auth Array of user authentication data * @param array $params Parameteres for gathering data */ fn_set_hook('gather_additional_product_data_before_options', $product, $auth, $params); // Convert product categories if (!empty($product['category_ids']) && !is_array($product['category_ids'])) { list($product['category_ids'], $product['main_category']) = fn_convert_categories($product['category_ids']); } $product['selected_options'] = empty($product['selected_options']) ? array() : $product['selected_options']; // Get product options if ($params['get_options'] && !empty($product_options[$product['product_id']])) { if (!isset($product['options_type']) || !isset($product['exceptions_type'])) { $types = db_get_row('SELECT options_type, exceptions_type FROM ?:products WHERE product_id = ?i', $product['product_id']); $product['options_type'] = $types['options_type']; $product['exceptions_type'] = $types['exceptions_type']; } if (empty($product['product_options'])) { if (!empty($product['combination'])) { $selected_options = fn_get_product_options_by_combination($product['combination']); } $product['product_options'] = !empty($selected_options) ? fn_get_selected_product_options($product['product_id'], $selected_options, CART_LANGUAGE) : $product_options[$product_id]; } $product = fn_apply_options_rules($product); if (!empty($params['get_icon']) || !empty($params['get_detailed'])) { // Get product options images if (!empty($product['combination_hash']) && !empty($product['product_options'])) { $image = fn_get_image_pairs($product['combination_hash'], 'product_option', 'M', $params['get_icon'], $params['get_detailed'], CART_LANGUAGE); if (!empty($image)) { $product['main_pair'] = $image; } } } $product['has_options'] = !empty($product['product_options']); if (!fn_allowed_for('ULTIMATE:FREE')) { $product = fn_apply_exceptions_rules($product); } // Change price $selected_options = isset($product['selected_options']) ? $product['selected_options'] : array(); foreach ($product['product_options'] as $option) { if (!empty($option['disabled'])) { unset($selected_options[$option['option_id']]); } } $product['selected_options'] = $selected_options; if (isset($product['price']) && empty($product['modifiers_price'])) { $product['base_modifier'] = fn_apply_options_modifiers($selected_options, $product['base_price'], 'P', array(), array('product_data' => $product)); $old_price = $product['price']; $product['price'] = fn_apply_options_modifiers($selected_options, $product['price'], 'P', array(), array('product_data' => $product)); if (empty($product['original_price'])) { $product['original_price'] = $old_price; } $product['original_price'] = fn_apply_options_modifiers($selected_options, $product['original_price'], 'P', array(), array('product_data' => $product)); $product['modifiers_price'] = $product['price'] - $old_price; } if (!empty($product['list_price'])) { $product['list_price'] = fn_apply_options_modifiers($selected_options, $product['list_price'], 'P', array(), array('product_data' => $product)); } if (!empty($product['prices']) && is_array($product['prices'])) { foreach ($product['prices'] as $pr_k => $pr_v) { $product['prices'][$pr_k]['price'] = fn_apply_options_modifiers($selected_options, $pr_v['price'], 'P', array(), array('product_data' => $product)); } } } else { $product['has_options'] = !empty($has_product_options[$product_id]) || !empty($has_product_options_links[$product_id]) ? true : false; $product['product_options'] = empty($product['product_options']) ? array() : $product['product_options']; } unset($selected_options); /** * Changes before gathering product discounts * * @param array $product Product data * @param mixed $auth Array of user authentication data * @param array $params Parameteres for gathering data */ fn_set_hook('gather_additional_product_data_before_discounts', $product, $auth, $params); // Get product discounts if ($params['get_discounts'] && !isset($product['exclude_from_calculate'])) { fn_promotion_apply('catalog', $product, $auth); if (!empty($product['prices']) && is_array($product['prices'])) { $product_copy = $product; foreach ($product['prices'] as $pr_k => $pr_v) { $product_copy['base_price'] = $product_copy['price'] = $pr_v['price']; fn_promotion_apply('catalog', $product_copy, $auth); $product['prices'][$pr_k]['price'] = $product_copy['price']; } } if (empty($product['discount']) && !empty($product['list_price']) && !empty($product['price']) && floatval($product['price']) && $product['list_price'] > $product['price']) { $product['list_discount'] = fn_format_price($product['list_price'] - $product['price']); $product['list_discount_prc'] = sprintf('%d', round($product['list_discount'] * 100 / $product['list_price'])); } } // FIXME: old product options scheme $product['discounts'] = array('A' => 0, 'P' => 0); if (!empty($product['promotions'])) { foreach ($product['promotions'] as $v) { foreach ($v['bonuses'] as $a) { if ($a['discount_bonus'] == 'to_fixed') { $product['discounts']['A'] += $a['discount']; } elseif ($a['discount_bonus'] == 'by_fixed') { $product['discounts']['A'] += $a['discount_value']; } elseif ($a['discount_bonus'] == 'to_percentage') { $product['discounts']['P'] += 100 - $a['discount_value']; } elseif ($a['discount_bonus'] == 'by_percentage') { $product['discounts']['P'] += $a['discount_value']; } } } } // Add product prices with taxes and without taxes if ($params['get_taxed_prices'] && AREA != 'A' && Registry::get('settings.Appearance.show_prices_taxed_clean') == 'Y' && $auth['tax_exempt'] != 'Y') { fn_get_taxed_and_clean_prices($product, $auth); } if ($params['get_features'] && !isset($product['product_features'])) { $product['product_features'] = fn_get_product_features_list($product, $params['features_display_on']); } if ($params['get_extra'] && !empty($product['is_edp']) && $product['is_edp'] == 'Y') { $product['agreement'] = array(fn_get_edp_agreements($product['product_id'])); } $product['qty_content'] = fn_get_product_qty_content($product, $allow_negative_amount, $inventory_tracking); if ($params['detailed_params']) { $product['detailed_params'] = empty($product['detailed_params']) ? $params : array_merge($product['detailed_params'], $params); } /** * Add additional data to product * * @param array $product Product data * @param mixed $auth Array of user authentication data * @param array $params Parameteres for gathering data */ fn_set_hook('gather_additional_product_data_post', $product, $auth, $params); $_product = $product; } // \foreach $products /** * Add additional data to products after gathering additional products data * * @param array $product_ids Array of product identifiers * @param array $params Parameteres for gathering data * @param array $products Array of products * @param mixed $auth Array of user authentication data */ fn_set_hook('gather_additional_products_data_post', $product_ids, $params, $products, $auth); if ($params['get_for_one_product'] == true) { $products = array_shift($products); } }