function fn_projects_project_get_pages(&$pages, $params, $lang_code) { $projects_pages = array(); foreach ($pages as $idx => $page) { if (!empty($page['page_type']) && $page['page_type'] == PAGE_TYPE_PROJECTS) { $projects_pages[$idx] = $page['page_id']; if (!empty($page['description'])) { if (strpos($page['description'], PROJECTS_CUT) !== false) { list($pages[$idx]['spoiler']) = explode(PROJECTS_CUT, $page['description'], 2); } else { $pages[$idx]['spoiler'] = $page['description']; } } if (!empty($page['subpages'])) { fn_projects_project_get_pages($pages[$idx]['subpages'], $params, $lang_code); } } } if (!empty($projects_pages)) { $images = array(); $authors = db_get_hash_single_array("SELECT CONCAT(u.firstname, ' ', u.lastname) as author, b.page_id FROM ?:projects_authors as b LEFT JOIN ?:users as u ON b.user_id = u.user_id WHERE b.page_id IN (?n)", array('page_id', 'author'), $projects_pages); if (!empty($params['get_image'])) { $images = fn_get_image_pairs($projects_pages, 'projects', 'M', true, false, $lang_code); } foreach ($projects_pages as $idx => $page_id) { $pages[$idx]['main_pair'] = !empty($images[$page_id]) ? reset($images[$page_id]) : array(); $pages[$idx]['author'] = !empty($authors[$page_id]) ? $authors[$page_id] : ''; } } }
/** * Gets brief company data array: <i>(company_id => company_name)</i> * * @param array $params Array of search params: * <ul> * <li>string status - Status field from the <i>?:companies table</i></li> * <li>string item_ids - Comma separated list of company IDs</li> * <li>int displayed_vendors - Number of companies for displaying. Will be used as LIMIT condition</i> * </ul> * Global variable <i>$_REQUEST</i> can be passed as argument * @return mixed If <i>$params</i> was not empty returns array: * <ul> * <li>companies - Hash array of companies <i>(company_id => company)</i></li> * <li>count - Number of returned companies</li> * </ul> * else returns hash array of companies <i>(company_id => company)</i></li> */ function fn_get_short_companies($params = array()) { $condition = $limit = $join = $companies = ''; if (!empty($params['status'])) { $condition .= db_quote(" AND ?:companies.status = ?s ", $params['status']); } if (!empty($params['item_ids'])) { $params['item_ids'] = fn_explode(",", $params['item_ids']); $condition .= db_quote(" AND ?:companies.company_id IN (?n) ", $params['item_ids']); } if (!empty($params['displayed_vendors'])) { $limit = 'LIMIT ' . $params['displayed_vendors']; } $condition .= Registry::get('runtime.company_id') ? fn_get_company_condition('?:companies.company_id', true, Registry::get('runtime.company_id')) : ''; fn_set_hook('get_short_companies', $params, $condition, $join, $limit); $count = db_get_field("SELECT COUNT(*) FROM ?:companies {$join} WHERE 1 {$condition}"); $_companies = db_get_hash_single_array("SELECT ?:companies.company_id, ?:companies.company FROM ?:companies {$join} WHERE 1 {$condition} ORDER BY ?:companies.company {$limit}", array('company_id', 'company')); if (!fn_allowed_for('ULTIMATE')) { $companies[0] = Registry::get('settings.Company.company_name'); $companies = $companies + $_companies; } else { $companies = $_companies; } $return = array('companies' => $companies, 'count' => $count); if (!empty($params)) { unset($return['companies'][0]); return array($return); } return $companies; }
function fn_exim_set_product_feature_categories($feature_id, $feature_data, $lang_code) { static $categories_ids; if (!empty($feature_data['parent_id'])) { $categories_path = ''; $parent_feature = fn_get_product_feature_data($feature_data['parent_id']); if (!empty($parent_feature['categories_path'])) { $categories_path = $parent_feature['categories_path']; } } else { if (!empty($feature_data['categories_path'])) { $categories_path = array(); if (!isset($categories_ids)) { $categories_ids = db_get_hash_single_array('SELECT category, category_id FROM ?:category_descriptions WHERE lang_code = ?s', array('category', 'category_id'), $lang_code); } $categories = explode(',', $feature_data['categories_path']); if (!empty($categories)) { foreach ($categories as $category) { if (!empty($categories_ids[$category])) { $categories_path[] = $categories_ids[$category]; } } } $categories_path = implode(',', $categories_path); } else { $categories_path = ''; } } db_query("UPDATE ?:product_features SET categories_path = ?s WHERE feature_id = ?i", $categories_path, $feature_id); if ($feature_data['feature_type'] == 'G') { db_query("UPDATE ?:product_features SET categories_path = ?s WHERE parent_id = ?i", $categories_path, $feature_id); } return true; }
function fn_blog_post_get_pages(&$pages, $params, $lang_code) { $blog_pages = array(); foreach ($pages as $idx => $page) { if (!empty($page['page_type']) && $page['page_type'] == PAGE_TYPE_BLOG) { $blog_pages[$idx] = $page['page_id']; if (!empty($page['description'])) { if (strpos($page['description'], BLOG_CUT) !== false) { list($pages[$idx]['spoiler']) = explode(BLOG_CUT, $page['description'], 2); } else { $pages[$idx]['spoiler'] = $page['description']; } } if (!empty($params['get_image'])) { $pages[$idx]['main_pair'] = fn_get_image_pairs($page['page_id'], 'blog', 'M', true, false, $lang_code); } if (!empty($page['subpages'])) { fn_blog_post_get_pages($pages[$idx]['subpages'], $params, $lang_code); } } } if (!empty($blog_pages)) { $authors = db_get_hash_single_array("SELECT CONCAT(u.firstname, ' ', u.lastname) as author, b.page_id FROM ?:blog_authors as b LEFT JOIN ?:users as u ON b.user_id = u.user_id WHERE b.page_id IN (?n)", array('page_id', 'author'), $blog_pages); foreach ($blog_pages as $idx => $page_id) { $pages[$idx]['author'] = $authors[$page_id]; } } }
/** * Get promotions * * @param array $params array with search params * @param int $items_per_page * @param string $lang_code * @return array list of promotions in first element, filtered parameters in second */ function fn_get_promotions($params, $items_per_page = 0, $lang_code = CART_LANGUAGE) { // Init filter $params = LastView::instance()->update('promotions', $params); // Set default values to input params $default_params = array('page' => 1, 'items_per_page' => $items_per_page, 'get_hidden' => true); $params = array_merge($default_params, $params); // Define fields that should be retrieved $fields = array("?:promotions.*", "?:promotion_descriptions.name", "?:promotion_descriptions.detailed_description", "?:promotion_descriptions.short_description"); // Define sort fields $sortings = array('name' => "?:promotion_descriptions.name", 'priority' => "?:promotions.priority", 'zone' => "?:promotions.zone", 'status' => "?:promotions.status"); $condition = $join = $group = ''; $condition .= fn_get_company_condition('?:promotions.company_id'); $statuses = array('A'); if (!empty($params['get_hidden'])) { $statuses[] = 'H'; } if (!empty($params['promotion_id'])) { $condition .= db_quote(' AND ?:promotions.promotion_id IN (?n)', $params['promotion_id']); } if (!empty($params['active'])) { $condition .= db_quote(" AND IF(from_date, from_date <= ?i, 1) AND IF(to_date, to_date >= ?i, 1) AND status IN (?a)", TIME, TIME, $statuses); } if (fn_allowed_for('ULTIMATE:FREE')) { $params['zone'] = 'catalog'; } if (!empty($params['zone'])) { $condition .= db_quote(" AND ?:promotions.zone = ?s", $params['zone']); } if (!empty($params['coupon_code'])) { $condition .= db_quote(" AND (CONCAT(LOWER(?:promotions.conditions_hash), ';') LIKE ?l OR CONCAT(LOWER(?:promotions.conditions_hash), ';') LIKE ?l)", "%coupon_code={$params['coupon_code']};%", "%auto_coupons={$params['coupon_code']};%"); } if (!empty($params['coupons'])) { $condition .= db_quote(" AND ?:promotions.conditions_hash LIKE ?l", "%coupon_code=%"); } if (!empty($params['auto_coupons'])) { $condition .= db_quote(" AND ?:promotions.conditions_hash LIKE ?l", "%auto_coupons=%"); } $join .= db_quote(" LEFT JOIN ?:promotion_descriptions ON ?:promotion_descriptions.promotion_id = ?:promotions.promotion_id AND ?:promotion_descriptions.lang_code = ?s", $lang_code); fn_set_hook('get_promotions', $params, $fields, $sortings, $condition, $join); $sorting = db_sort($params, $sortings, 'name', 'desc'); $limit = ''; if (!empty($params['items_per_page'])) { $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:promotions {$join} WHERE 1 {$condition} {$group}"); $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']); } if (!empty($params['simple'])) { return db_get_hash_single_array("SELECT ?:promotions.promotion_id, ?:promotion_descriptions.name FROM ?:promotions {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}", array('promotion_id', 'name')); } else { $promotions = db_get_hash_array('SELECT ' . implode(', ', $fields) . " FROM ?:promotions {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}", 'promotion_id'); } if (!empty($params['expand'])) { foreach ($promotions as $k => $v) { $promotions[$k]['conditions'] = !empty($v['conditions']) ? unserialize($v['conditions']) : array(); $promotions[$k]['bonuses'] = !empty($v['bonuses']) ? unserialize($v['bonuses']) : array(); } } return array($promotions, $params); }
function fn_get_image($image_id, $object_type, $lang_code = CART_LANGUAGE, $get_all_alts = false) { $path = $object_type; if (!empty($image_id) && !empty($object_type)) { $image_data = db_get_row("SELECT ?:images.image_id, ?:images.image_path, ?:common_descriptions.description as alt, ?:images.image_x, ?:images.image_y FROM ?:images LEFT JOIN ?:common_descriptions ON ?:common_descriptions.object_id = ?:images.image_id AND ?:common_descriptions.object_holder = 'images' AND ?:common_descriptions.lang_code = ?s WHERE ?:images.image_id = ?i", $lang_code, $image_id); if ($get_all_alts && count(fn_get_translation_languages()) > 1) { $image_data['alt'] = db_get_hash_single_array('SELECT description, lang_code FROM ?:common_descriptions WHERE object_id = ?i AND object_holder = ?s', array('lang_code', 'description'), $image_data['image_id'], 'images'); } } fn_attach_absolute_image_paths($image_data, $object_type); return !empty($image_data) ? $image_data : false; }
/** * Get ebay sites * @param array $site_ids * @return array */ function fn_get_ebay_sites(array $site_ids = null) { $condition = ''; if ($site_ids !== null) { if (empty($site_ids)) { return array(); } $condition .= db_quote("AND site_id IN (?n)", $site_ids); } $sites = db_get_hash_single_array("SELECT * FROM ?:ebay_sites WHERE 1 {$condition}", array('site_id', 'site')); return $sites; }
function fn_get_category_desc($category_id = 0, $lang_code = CART_LANGUAGE, $as_array = false) { if (!empty($category_id)) { if (!is_array($category_id) && strpos($category_id, ',') !== false) { $category_id = explode(',', $category_id); } if (is_array($category_id) || $as_array == true) { return db_get_hash_single_array("SELECT category_id, description FROM ?:category_descriptions WHERE category_id IN (?n) AND lang_code = ?s", array('category_id', 'description'), $category_id, $lang_code); } else { return db_get_field("SELECT description FROM ?:category_descriptions WHERE category_id = ?i AND lang_code = ?s", $category_id, $lang_code); } } return false; }
function fn_exim_get_extra_fields($user_id, $lang_code = CART_LANGUAGE) { $fields = array(); $_user = db_get_hash_single_array("SELECT d.description, f.value FROM ?:profile_fields_data as f LEFT JOIN ?:profile_field_descriptions as d ON d.object_id = f.field_id AND d.object_type = 'F' AND d.lang_code = ?s WHERE f.object_id = ?i AND f.object_type = 'U'", array('description', 'value'), $lang_code, $user_id); $_profile = db_get_hash_single_array("SELECT d.description, f.value FROM ?:profile_fields_data as f LEFT JOIN ?:profile_field_descriptions as d ON d.object_id = f.field_id AND d.object_type = 'F' AND d.lang_code = ?s LEFT JOIN ?:user_profiles as p ON f.object_id = p.profile_id AND f.object_type = 'P' WHERE p.user_id = ?i", array('description', 'value'), $lang_code, $user_id); if (!empty($_user)) { $fields['user'] = $_user; } if (!empty($_profile)) { $fields['profile'] = $_profile; } if (!empty($fields)) { return YAML_Parser::serialize($fields); } return ''; }
/** * Convert Category names to its IDs * Example: * IN array( * 'some_data' => ..., * 'categories_path' => 'Electronics,Processors' * ) * OUT array( * 'some_data' => ..., * 'categories_path' => '12,52' * ) * * @param array $feature_data List of feature properties * @param string $lang_code 2-letters lang code * @return string Converted categories_path */ function fn_exim_get_features_convert_category_path($feature_data, $lang_code, $category_delimiter = '///') { $categories_path = ''; if (!empty($feature_data['parent_id'])) { $categories_path = ''; $parent_feature = fn_get_product_feature_data($feature_data['parent_id']); if (!empty($parent_feature['categories_path'])) { $categories_path = $parent_feature['categories_path']; } } else { if (!empty($feature_data['categories_path'])) { $categories_path = array(); if (!isset($categories_ids)) { $categories_ids = db_get_hash_single_array('SELECT category, category_id FROM ?:category_descriptions WHERE lang_code = ?s', array('category', 'category_id'), $lang_code); } $_categories_paths = explode(',', $feature_data['categories_path']); if (!empty($_categories_paths)) { foreach ($_categories_paths as $category_path) { if (strpos($category_path, $category_delimiter)) { $categories = explode($category_delimiter, $category_path); array_walk($categories, 'fn_trim_helper'); $cat_ids_path = array(); foreach ($categories as $category) { if (!empty($categories_ids[$category])) { $cat_ids_path[] = $categories_ids[$category]; } } $cat_ids_path = implode('/', $cat_ids_path); $__cat_id = db_get_field("SELECT category_id FROM ?:categories WHERE id_path = ?s", $cat_ids_path); if (!empty($__cat_id)) { $categories_path[] = $__cat_id; } } else { if (!empty($categories_ids[$category])) { $categories_path[] = $categories_ids[$category]; } } } } $categories_path = implode(',', $categories_path); } } return $categories_path; }
function fn_get_short_companies($params = array()) { $condition = $limit = ''; if (!empty($params['status'])) { $condition .= db_quote(" AND status = ?s ", $params['status']); } if (!empty($params['displayed_vendors'])) { $limit = 'LIMIT ' . $params['displayed_vendors']; } $condition .= defined('COMPANY_ID') ? fn_get_company_condition('company_id', true, COMPANY_ID) : ''; $count = db_get_field('SELECT COUNT(*) FROM ?:companies WHERE 1' . $condition); $_companies = db_get_hash_single_array("SELECT company_id, company FROM ?:companies WHERE 1 {$condition} ORDER BY company {$limit}", array('company_id', 'company')); $companies[0] = Registry::get('settings.Company.company_name'); $companies = $companies + $_companies; $return = array('companies' => $companies, 'count' => $count); if (!empty($params)) { unset($return['companies'][0]); return array($return); } return $companies; }
/** * Loads received language variables into language cache * * @param array $var_names Language variable that to be loaded * @param string $lang_code 2-letter language code * * @return boolean True if any of received language variables were added into cache; false otherwise */ public static function preloadLangVars($var_names, $lang_code = CART_LANGUAGE) { Registry::registerCache('lang_cache', array('language_values', 'ult_language_values'), Registry::cacheLevel('dispatch'), true); $values = Registry::get('lang_cache.' . $lang_code); if (empty($values)) { $values = array(); } $var_names = array_diff($var_names, array_keys($values)); if ($var_names) { foreach ($var_names as $index => $var_name) { $var_names[$index] = strtolower($var_name); if (isset($values[$var_name])) { unset($var_names[$index]); } } if (empty($var_names)) { return true; } $fields = array('lang.name' => true, 'lang.value' => true); $tables = array('?:language_values lang'); $left_join = array(); $condition = array(db_quote('lang.lang_code = ?s', $lang_code), db_quote('lang.name IN (?a)', $var_names)); $params = array(); fn_set_hook('get_lang_var', $fields, $tables, $left_join, $condition, $params); $joins = !empty($left_join) ? ' LEFT JOIN ' . implode(', ', $left_join) : ''; $new_values = db_get_hash_single_array('SELECT ' . implode(', ', array_keys($fields)) . ' FROM ' . implode(', ', $tables) . $joins . ' WHERE ' . implode(' AND ', $condition), array('name', 'value')); foreach ($var_names as $var_name) { if (!isset($new_values[$var_name])) { $new_values[$var_name] = '_' . $var_name; } } $values = fn_array_merge($values, $new_values); Registry::set('lang_cache.' . $lang_code, $values); return true; } return false; }
function fn_delete_corresponding_subscription($order_ids, $not_confirmed = true) { $subscriptions = db_get_hash_single_array("SELECT subscription_id, order_id FROM ?:recurring_subscriptions WHERE order_id IN (?n)", array('subscription_id', 'order_id'), $order_ids); if (!empty($subscriptions)) { if ($not_confirmed) { $_SESSION['subscriptions'] = $subscriptions; $_SESSION['order_ids'] = $order_ids; return false; } else { fn_delete_recurring_subscriptions(array_keys($subscriptions)); } } foreach ($order_ids as $v) { $subs = db_get_array("SELECT subscription_id, order_ids FROM ?:recurring_subscriptions WHERE FIND_IN_SET(?i, order_ids)", $v); if (!empty($subs)) { foreach ($subs as $val) { $new_order_ids = explode(',', $val['order_ids']); $new_order_ids = array_diff($new_order_ids, $order_ids); db_query("UPDATE ?:recurring_subscriptions SET order_ids = ?s WHERE subscription_id = ?i", implode(',', $new_order_ids), $val['subscription_id']); } } } return true; }
function fn_product_configurator_get_products_post(&$products) { foreach ($products as $pr_id => $product) { if ($product['product_type'] == 'C') { $conf_product_groups = db_get_hash_single_array("SELECT ?:conf_product_groups.group_id, ?:conf_product_groups.default_product_ids FROM ?:conf_product_groups LEFT JOIN ?:conf_groups ON ?:conf_product_groups.group_id = ?:conf_groups.group_id WHERE ?:conf_groups.status = 'A' AND ?:conf_product_groups.product_id = ?i", array('group_id', 'default_product_ids'), $product['product_id']); if (!empty($conf_product_groups)) { foreach ($conf_product_groups as $k => $v) { if (!empty($v)) { $_products = db_get_hash_single_array("SELECT ?:product_prices.product_id, ?:product_prices.price FROM ?:product_prices LEFT JOIN ?:conf_group_products ON ?:conf_group_products.product_id = ?:product_prices.product_id WHERE ?:conf_group_products.group_id = ?i AND ?:product_prices.lower_limit = 1", array('product_id', 'price'), $k); $tmp = explode(':', $v); foreach ($tmp as $pid) { if (!empty($_products[$pid]) && AREA != 'A') { $products[$pr_id]['price'] += $_products[$pid]; } } } } } } } return true; }
/** * Cleans up addons with incorrect snaphost * * @return bool Always true */ function fn_clean_up_addons() { $_addons = db_get_hash_single_array("SELECT addon, status FROM ?:addons", array('addon', 'status')); $skipped_snapshots = fn_get_storage_data('skipped_snapshots'); $skipped_snapshots = !empty($skipped_snapshots) ? explode(',', $skipped_snapshots) : array(); foreach ($_addons as $addon => $status) { $snaphost = md5(str_rot13($addon)); if (!fn_check_addon_snapshot($addon)) { if ($status == 'A') { fn_update_addon_status($addon, 'D'); $skipped_snapshots[] = $snaphost; } } elseif (in_array($snaphost, $skipped_snapshots)) { fn_update_addon_status($addon, 'A'); $skipped_snapshots = array_diff($skipped_snapshots, array($snaphost)); } } $skipped_snapshots = array_unique($skipped_snapshots); fn_set_storage_data('skipped_snapshots', implode(',', $skipped_snapshots)); return true; }
private static function _getFromDB() { $settings = db_get_hash_single_array('SELECT * FROM ?:twigmo_settings', array('name', 'value')); $store_sql = 'SELECT * FROM ?:twigmo_stores WHERE type = ?s'; $settings['admin_connection'] = db_get_row($store_sql, 'A'); $settings['customer_connections'] = db_get_hash_array($store_sql, 'company_id', 'C'); return $settings; }
$url = "discussion_manager.manage?object_type={$object['object_type']}&post_id={$post_data['post_id']}"; $view_mail->assign('url', fn_url($url, 'A', 'http', '&')); } $view_mail->assign('object_data', $object_data); $view_mail->assign('post_data', $post_data); $view_mail->assign('object_name', $object_name); $view_mail->assign('subject', fn_get_lang_var('discussion_title_' . $discussion_object_types[$object['object_type']]) . ' - ' . fn_get_lang_var($discussion_object_types[$object['object_type']])); // Send notification if needed if (!empty($email_from)) { fn_send_mail($email_to, $email_from, 'addons/discussion/notification_subj.tpl', 'addons/discussion/notification.tpl'); } } } if ($mode == 'update_posts') { if (AREA == 'A' && !empty($_REQUEST['posts']) && is_array($_REQUEST['posts'])) { $threads = db_get_hash_single_array("SELECT post_id, thread_id FROM ?:discussion_posts WHERE post_id IN (?n)", array('post_id', 'thread_id'), array_keys($_REQUEST['posts'])); $messages_exist = db_get_fields("SELECT post_id FROM ?:discussion_messages WHERE post_id IN (?n)", array_keys($_REQUEST['posts'])); $rating_exist = db_get_fields("SELECT post_id FROM ?:discussion_rating WHERE post_id IN (?n)", array_keys($_REQUEST['posts'])); foreach ($_REQUEST['posts'] as $p_id => $data) { db_query("UPDATE ?:discussion_posts SET ?u WHERE post_id = ?i", $data, $p_id); if (in_array($p_id, $messages_exist)) { db_query("UPDATE ?:discussion_messages SET ?u WHERE post_id = ?i", $data, $p_id); } else { $data['thread_id'] = $threads[$p_id]; $data['post_id'] = $p_id; db_query("INSERT INTO ?:discussion_messages ?e", $data); } if (in_array($p_id, $rating_exist)) { db_query("UPDATE ?:discussion_rating SET ?u WHERE post_id = ?i", $data, $p_id); } else { $data['thread_id'] = $threads[$p_id];
function fn_se_get_products_additionals(&$products, $company_id, $lang_code) { $product_ids = fn_se_get_ids($products, 'product_id'); if (fn_allowed_for('ULTIMATE')) { $shared_prices = db_get_hash_multi_array('SELECT product_id, (IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price, usergroup_id FROM ?:ult_product_prices WHERE company_id = ?i AND product_id IN (?n) AND lower_limit = 1', array('product_id', 'usergroup_id'), $company_id, $product_ids); $prices = db_get_hash_multi_array('SELECT product_id, (IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price, usergroup_id FROM ?:product_prices WHERE product_id IN (?n) AND lower_limit = 1', array('product_id', 'usergroup_id'), $product_ids); $product_categories = db_get_hash_multi_array("SELECT pc.product_id, c.category_id, c.usergroup_ids, c.status FROM ?:categories AS c LEFT JOIN ?:products_categories AS pc ON c.category_id = pc.category_id WHERE c.company_id = ?i AND product_id IN (?n) AND c.status IN ('A', 'H')", array('product_id', 'category_id'), $company_id, $product_ids); $shared_descriptions = db_get_hash_array("SELECT product_id, full_description FROM ?:ult_product_descriptions WHERE company_id = ?i AND product_id IN (?n) AND lang_code = ?s", 'product_id', $company_id, $product_ids, $lang_code); } else { $prices = db_get_hash_multi_array('SELECT product_id, (IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price, usergroup_id FROM ?:product_prices WHERE product_id IN (?n) AND lower_limit = 1', array('product_id', 'usergroup_id'), $product_ids); $product_categories = db_get_hash_multi_array("SELECT pc.product_id, c.category_id, c.usergroup_ids, c.status FROM ?:categories AS c LEFT JOIN ?:products_categories AS pc ON c.category_id = pc.category_id WHERE product_id IN (?n) AND c.status IN ('A', 'H')", array('product_id', 'category_id'), $product_ids); } if (Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N') { $product_options = db_get_hash_single_array("SELECT product_id, max(amount) as amount FROM ?:product_options_inventory WHERE product_id IN (?n) GROUP BY product_id", array('product_id', 'amount'), $product_ids); } $descriptions = db_get_hash_array("SELECT product_id, full_description FROM ?:product_descriptions WHERE 1 AND product_id IN (?n) AND lang_code = ?s", 'product_id', $product_ids, $lang_code); foreach ($products as &$product) { $product_id = $product['product_id']; if (isset($shared_prices[$product_id])) { $product['se_prices'] = $shared_prices[$product_id]; } elseif (isset($prices[$product_id])) { $product['se_prices'] = $prices[$product_id]; } else { $product['se_prices'] = array('0' => array('price' => 0)); } if ($product['tracking'] == ProductTracking::TRACK_WITH_OPTIONS && isset($product_options[$product_id])) { $product['amount'] = $product_options[$product_id]; } if (!empty($shared_descriptions[$product_id]['full_description'])) { $product['se_full_description'] = $shared_descriptions[$product_id]['full_description']; } elseif (!empty($descriptions[$product_id]['full_description'])) { $product['se_full_description'] = $descriptions[$product_id]['full_description']; } $product['category_ids'] = array(); $product['category_usergroup_ids'] = array(); if (!empty($product_categories[$product_id])) { foreach ($product_categories[$product_id] as $pc) { $product['category_ids'][] = $pc['category_id']; $product['category_usergroup_ids'] = array_merge($product['category_usergroup_ids'], explode(',', $pc['usergroup_ids'])); } } $product['empty_categories'] = empty($product['category_ids']) ? 'Y' : 'N'; } }
/** * Update multiple posts at once * @param array $posts posts data * @return boolean always true */ function fn_update_discussion_posts($posts) { if (!empty($posts) && is_array($posts)) { $threads = db_get_hash_single_array("SELECT post_id, thread_id FROM ?:discussion_posts WHERE post_id IN (?n)", array('post_id', 'thread_id'), array_keys($posts)); $messages_exist = db_get_fields("SELECT post_id FROM ?:discussion_messages WHERE post_id IN (?n)", array_keys($posts)); $rating_exist = db_get_fields("SELECT post_id FROM ?:discussion_rating WHERE post_id IN (?n)", array_keys($posts)); fn_delete_notification('company_access_denied'); foreach ($posts as $p_id => $data) { db_query("UPDATE ?:discussion_posts SET ?u WHERE post_id = ?i", $data, $p_id); if (in_array($p_id, $messages_exist)) { db_query("UPDATE ?:discussion_messages SET ?u WHERE post_id = ?i", $data, $p_id); } else { $data['thread_id'] = $threads[$p_id]; $data['post_id'] = $p_id; db_query("INSERT INTO ?:discussion_messages ?e", $data); } if (in_array($p_id, $rating_exist)) { db_query("UPDATE ?:discussion_rating SET ?u WHERE post_id = ?i", $data, $p_id); } else { $data['thread_id'] = $threads[$p_id]; $data['post_id'] = $p_id; db_query("INSERT INTO ?:discussion_rating ?e", $data); } } } return true; }
/** * Update addon options * * @param string $addon addon to update options for * @param string $addon_data options data * @return bool always true */ function fn_update_addon($addon, $addon_data) { fn_get_schema('settings', 'actions', 'php', false, true); // Get old options $old_options = db_get_field("SELECT options FROM ?:addons WHERE addon = ?s", $addon); $old_options = fn_parse_addon_options($old_options); $ml_options = db_get_hash_single_array("SELECT object_id, description FROM ?:addon_descriptions WHERE addon = ?s AND object_id != '' AND object_type = 'L' AND lang_code = ?s", array('object_id', 'description'), $addon, CART_LANGUAGE); foreach ($old_options as $k => $v) { if (isset($addon_data['options'][$k]) && ($v != '%ML%' && $addon_data['options'][$k] != $v || $v == '%ML%' && isset($ml_options[$k]) && $addon_data['options'][$k] != $ml_options[$k]) || !isset($addon_data['options'][$k])) { $func = 'fn_settings_actions_addons_' . $addon . '_' . $k; if (function_exists($func)) { $func($addon_data['options'][$k], $v == '%ML%' ? $ml_options[$k] : $v); } } if ($v == '%ML%') { db_query("UPDATE ?:addon_descriptions SET ?u WHERE addon = ?s AND object_id = ?s AND object_type = 'L' AND lang_code = ?s", array('description' => $addon_data['options'][$k]), $addon, $k, CART_LANGUAGE); $addon_data['options'][$k] = '%ML%'; } } if (!empty($addon_data['options'])) { foreach ($addon_data['options'] as $k => $v) { if (is_array($v)) { $addon_data['options'][$k] = '#M#' . implode('=Y&', $v) . '=Y'; } } $addon_data['options'] = serialize($addon_data['options']); } else { $addon_data['options'] = ''; } db_query("UPDATE ?:addons SET ?u WHERE addon = ?s", $addon_data, $addon); return true; }
protected function getMarketCategories() { static $market_categories = null; if (!isset($market_categories)) { $market_categories = array(); if ($this->options['market_category'] == "Y" && $this->options['market_category_object'] == "category") { $market_categories = db_get_hash_single_array("SELECT category_id, yml_market_category FROM ?:categories WHERE yml_market_category != ?s", array('category_id', 'yml_market_category'), ''); } } return $market_categories; }
function fn_reward_points_rma_recalculate_order(&$item, &$mirror_item, &$type, &$ex_data, &$amount) { if (!isset($item['extra']['exclude_from_calculate'])) { if (isset($mirror_item['extra']['points_info']['reward'])) { $item['extra']['points_info']['reward'] = floor((isset($item['primordial_amount']) ? $item['primordial_amount'] : $item['amount']) * ($mirror_item['extra']['points_info']['reward'] / $mirror_item['amount'])); } if (isset($mirror_item['extra']['points_info']['price'])) { $item['extra']['points_info']['price'] = floor((isset($item['primordial_amount']) ? $item['primordial_amount'] : $item['amount']) * ($mirror_item['extra']['points_info']['price'] / $mirror_item['amount'])); } if (in_array($type, array('O-', 'M-O+'))) { if (isset($item['extra']['points_info']['reward'])) { $points = ($type == 'O-' ? 1 : -1) * floor($amount * (!empty($item['amount']) ? $item['extra']['points_info']['reward'] / $item['amount'] : $mirror_item['extra']['points_info']['reward'] / $mirror_item['amount'])); $additional_data = db_get_hash_single_array("SELECT type,data FROM ?:order_data WHERE order_id = ?i", array('type', 'data'), $ex_data['order_id']); if (!empty($additional_data[POINTS])) { db_query('UPDATE ?:order_data SET ?u WHERE order_id = ?i AND type = ?s', array('data' => $additional_data[POINTS] + $points), $ex_data['order_id'], POINTS); } if (!empty($additional_data[ORDER_DATA_POINTS_GAIN]) && $additional_data[ORDER_DATA_POINTS_GAIN] == 'Y') { $user_id = db_get_field("SELECT user_id FROM ?:orders WHERE order_id = ?i", $ex_data['order_id']); $reason = array('return_id' => $ex_data['return_id'], 'to' => $ex_data['status_to'], 'from' => $ex_data['status_from']); fn_change_user_points($points, $user_id, serialize($reason), CHANGE_DUE_RMA); } } } } }
function fn_get_post_attributes($post, $object_id) { $attributes = fn_get_review_attributes($object_id); //get rating values for each post $ratings = db_get_hash_single_array('SELECT attr_id, rating FROM ?:review_rating WHERE post_id = ?i', array('attr_id', 'rating'), $post['post_id']); foreach ($attributes as $attribute) { $post['attributes'][$attribute['attr_id']] = $attribute; $post['attributes'][$attribute['attr_id']]['value'] = $ratings[$attribute['attr_id']]; } return $post; }
/** * Gets currensies list * * @param bool $only_avail if true get only available currensies * @return array Currencies list */ function fn_get_simple_currencies($only_avail = true) { $status_cond = $only_avail ? "WHERE status = 'A'" : ''; return db_get_hash_single_array("SELECT a.*, b.description FROM ?:currencies as a LEFT JOIN ?:currency_descriptions as b ON a.currency_code = b.currency_code AND lang_code = ?s {$status_cond} ORDER BY a.position", array('currency_code', 'description'), CART_LANGUAGE); }
/** * Gets only active languages list (as lang_code => name) * * @param bool $include_hidden if true get hiddenlanguages too * @return array languages list */ public static function getSimpleLanguages($include_hidden = false) { $language_condition = $include_hidden ? "WHERE status <> 'D'" : "WHERE status = 'A'"; if (fn_allowed_for('ULTIMATE:FREE')) { $language_condition .= db_quote(' OR lang_code = ?s', DEFAULT_LANGUAGE); } $languages = db_get_hash_single_array("SELECT lang_code, name FROM ?:languages ?p", array('lang_code', 'name'), $language_condition); $languages = self::afterFind($languages, true); return $languages; }
function fn_get_localization_data($localization_id, $lang_code = CART_LANGUAGE, $additional_data = false) { $loc_data = array(); if (!fn_allowed_for('ULTIMATE:FREE')) { $loc_data['data'] = db_get_row("SELECT a.localization_id, a.status, a.custom_weight_settings, a.weight_symbol, a.weight_unit, a.is_default, b.localization FROM ?:localizations as a LEFT JOIN ?:localization_descriptions as b ON a.localization_id = b.localization_id AND b.lang_code = ?s WHERE a.localization_id = ?i ORDER BY localization", $lang_code, $localization_id); if (empty($loc_data['data'])) { return array(); } if ($additional_data == true) { $loc_data['countries'] = db_get_hash_single_array("SELECT a.code, b.country FROM ?:countries as a LEFT JOIN ?:country_descriptions as b ON b.code = a.code AND b.lang_code = ?s LEFT JOIN ?:localization_elements as c ON c.element_type = 'C' AND c.element = a.code WHERE c.localization_id = ?i ORDER BY position", array('code', 'country'), $lang_code, $localization_id); $loc_data['currencies'] = db_get_hash_single_array("SELECT a.currency_code, a.description FROM ?:currency_descriptions as a LEFT JOIN ?:localization_elements as b ON b.element_type = 'M' AND b.element = a.currency_code WHERE b.localization_id = ?i AND a.lang_code = ?s ORDER BY position", array('currency_code', 'description'), $localization_id, $lang_code); $loc_data['languages'] = db_get_hash_single_array("SELECT a.lang_code, a.name FROM ?:languages as a LEFT JOIN ?:localization_elements as b ON b.element_type = 'L' AND b.element = a.lang_code WHERE b.localization_id = ?i ORDER BY position", array('lang_code', 'name'), $localization_id); } } return $loc_data; }
/** * Return order/orders info after the order placing * @param int $order_id * @param array $response */ public static function returnPlacedOrders($order_id, &$response, $items_per_page, $lang_code) { $order = self::getOrderInfo($order_id); $_error = false; $status = db_get_field('SELECT status FROM ?:orders WHERE order_id=?i', $order_id); if ($status == STATUS_PARENT_ORDER) { $child_orders = db_get_hash_single_array("SELECT order_id, status FROM ?:orders WHERE parent_order_id = ?i", array('order_id', 'status'), $order_id); $status = reset($child_orders); $order['child_orders'] = array_keys($child_orders); } if (!in_array($status, fn_get_order_paid_statuses())) { $_error = true; if ($status != 'B') { if (!empty($child_orders)) { array_unshift($child_orders, $order_id); } else { $child_orders = array(); $child_orders[] = $order_id; } $order_id_field = $status == 'N' ? 'processed_order_id' : 'failed_order_id'; $_SESSION['cart'][$order_id_field] = $child_orders; $cart =& $_SESSION['cart']; if (!empty($cart['failed_order_id'])) { $_ids = !empty($cart['failed_order_id']) ? $cart['failed_order_id'] : $cart['processed_order_id']; $_order_id = reset($_ids); $_payment_info = db_get_field("SELECT data\n FROM ?:order_data\n WHERE order_id = ?i AND type = 'P'", $_order_id); if (!empty($_payment_info)) { $_payment_info = unserialize(fn_decrypt_text($_payment_info)); } $_msg = !empty($_payment_info['reason_text']) ? $_payment_info['reason_text'] : ''; $_msg .= empty($_msg) ? __('text_order_placed_error') : ''; $response->addError('ERROR_FAIL_POST_ORDER', $_msg); $cart['processed_order_id'] = $cart['failed_order_id']; unset($cart['failed_order_id']); } elseif (!fn_twg_set_internal_errors($response, 'ERROR_FAIL_POST_ORDER')) { $response->addError('ERROR_FAIL_POST_ORDER', __('fail_post_order', $lang_code)); } } else { if (!fn_twg_set_internal_errors($response, 'ERROR_ORDER_BACKORDERED')) { $response->addError('ERROR_ORDER_BACKORDERED', __('text_order_backordered', $lang_code)); } } $response->returnResponse(); } $auth =& $_SESSION['auth']; $user = fn_get_user_info($auth['user_id']); $profile_points = !empty($user['points']) ? $user['points'] : 0; if (empty($order['child_orders'])) { $response->setData(array('order' => $order, 'profile_points' => $profile_points)); } else { $params = array(); if (empty($auth['user_id'])) { $params['order_id'] = $auth['order_ids']; } else { $params['user_id'] = $auth['user_id']; } list($orders, , $totals) = fn_get_orders($params, $items_per_page, true); $response->setMeta(!empty($totals['gross_total']) ? $totals['gross_total'] : 0, 'gross_total'); $response->setMeta(!empty($totals['totally_paid']) ? $totals['totally_paid'] : 0, 'totally_paid'); $response->setMeta($order, 'order'); $response->setResponseList(TwigmoOrder::getOrdersAsApiList($orders, $lang_code)); $response->setData($profile_points, 'profile_points'); $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); } }
function fn_google_sitemap_get_content($map_page = 0) { $cache_path = fn_get_cache_path(false) . 'google_sitemap/'; define('ITEMS_PER_PAGE', 500); define('MAX_URLS_IN_MAP', 50000); // 50 000 is the maximum for one sitemap file define('MAX_SIZE_IN_KBYTES', 10000); // 10240 KB || 10 Mb is the maximum for one sitemap file $sitemap_settings = Registry::get('addons.google_sitemap'); $location = Registry::get('config.http_location'); $lmod = date("Y-m-d", TIME); header("Content-Type: text/xml;charset=utf-8"); // HEAD SECTION $simple_head = <<<HEAD <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> HEAD; $simple_foot = <<<FOOT </urlset> FOOT; $index_map_url = <<<HEAD <url> <loc>{$location}/</loc> <lastmod>{$lmod}</lastmod> <changefreq>{$sitemap_settings['site_change']}</changefreq> <priority>{$sitemap_settings['site_priority']}</priority> </url> HEAD; // END HEAD SECTION // SITEMAP CONTENT $link_counter = 1; $file_counter = 1; fn_mkdir($cache_path); $file = fopen($cache_path . 'sitemap' . $file_counter . '.xml', "wb"); fwrite($file, $simple_head . $index_map_url); $languages = db_get_hash_single_array("SELECT lang_code, name FROM ?:languages WHERE status = 'A'", array('lang_code', 'name')); if ($sitemap_settings['include_categories'] == "Y") { $categories = db_get_fields("SELECT category_id FROM ?:categories WHERE FIND_IN_SET(?i, usergroup_ids) AND status = 'A' ?p", USERGROUP_ALL, fn_get_google_sitemap_company_condition('?:categories.company_id')); //Add the all active categories foreach ($categories as $category) { $links = fn_google_sitemap_generate_link('category', $category, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['categories_change'], $sitemap_settings['categories_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } if ($sitemap_settings['include_products'] == "Y") { $page = 1; $total = ITEMS_PER_PAGE; $params = $_REQUEST; $params['page'] = $page; $params['custom_extend'] = array('categories'); $params['sort_by'] = 'null'; $params['only_short_fields'] = true; while (ITEMS_PER_PAGE * ($params['page'] - 1) <= $total) { list($products, $search) = fn_get_products($params, ITEMS_PER_PAGE); $total = $search['total_items']; $params['page']++; foreach ($products as $product) { $links = fn_google_sitemap_generate_link('product', $product['product_id'], $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['products_change'], $sitemap_settings['products_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } unset($products); } if ($sitemap_settings['include_pages'] == "Y") { $pages = db_get_fields("SELECT page_id FROM ?:pages WHERE status = 'A' AND page_type != 'L' ?p", fn_get_google_sitemap_company_condition('?:pages.company_id')); //Add the all active pages foreach ($pages as $page) { $links = fn_google_sitemap_generate_link('page', $page, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['pages_change'], $sitemap_settings['pages_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } if ($sitemap_settings['include_extended'] == "Y") { $vars = db_get_fields("SELECT ?:product_feature_variants.variant_id FROM ?:product_feature_variants " . "LEFT JOIN ?:product_features ON (?:product_feature_variants.feature_id = ?:product_features.feature_id) " . "WHERE ?:product_features.feature_type = 'E' AND ?:product_features.status = 'A'"); //Add the all active extended features foreach ($vars as $var) { $links = fn_google_sitemap_generate_link('extended', $var, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['extended_change'], $sitemap_settings['extended_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } if (Registry::isExist("addons.news_and_emails") && $sitemap_settings['include_news'] == 'Y') { $news = db_get_fields("SELECT news_id FROM ?:news WHERE status = 'A' ?p", fn_get_google_sitemap_company_condition('?:news.company_id')); if (!empty($news)) { foreach ($news as $news_id) { $links = fn_google_sitemap_generate_link('news', $news_id, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['news_change'], $sitemap_settings['news_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } } if (fn_allowed_for('MULTIVENDOR') && $sitemap_settings['include_companies'] == 'Y') { $companies = db_get_fields("SELECT company_id FROM ?:companies WHERE status = 'A' ?p", fn_get_google_sitemap_company_condition('?:companies.company_id')); if (!empty($companies)) { foreach ($companies as $company_id) { $links = fn_google_sitemap_generate_link('companies', $company_id, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['companies_change'], $sitemap_settings['companies_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } } fn_set_hook('sitemap_item', $sitemap_settings, $file, $lmod, $link_counter, $file_counter); fwrite($file, $simple_foot); fclose($file); if ($file_counter == 1) { fn_rename($cache_path . 'sitemap' . $file_counter . '.xml', $cache_path . 'sitemap.xml'); } else { // Make a map index file $maps = ''; $seo_enabled = Registry::get('addons.seo.status') == 'A' ? true : false; for ($i = 1; $i <= $file_counter; $i++) { if ($seo_enabled) { $name = $location . '/sitemap' . $i . '.xml'; } else { $name = fn_url('xmlsitemap.view?page=' . $i, 'C', 'http'); } $name = htmlentities($name); $maps .= <<<MAP <sitemap> <loc>{$name}</loc> <lastmod>{$lmod}</lastmod> </sitemap> MAP; } $index_map = <<<HEAD <?xml version="1.0" encoding="UTF-8"?> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> {$maps} </sitemapindex> HEAD; $file = fopen($cache_path . 'sitemap.xml', "wb"); fwrite($file, $index_map); fclose($file); } $filename = $cache_path . 'sitemap.xml'; if (!empty($map_page)) { $name = $cache_path . 'sitemap' . $map_page . '.xml'; if (file_exists($name)) { $filename = $name; } } readfile($filename); exit; }
function fn_rma_recalculate_order($order_id, $recalculate_type, $return_id, $is_refund, $ex_data) { if (empty($recalculate_type) || empty($return_id) || empty($order_id) || !is_array($ex_data) || $recalculate_type == 'M' && !isset($ex_data['total'])) { return false; } $order = db_get_row("SELECT total, subtotal, discount, shipping_cost, status FROM ?:orders WHERE order_id = ?i", $order_id); $order_items = db_get_hash_array("SELECT * FROM ?:order_details WHERE ?:order_details.order_id = ?i", 'item_id', $order_id); $additional_data = db_get_hash_single_array("SELECT type, data FROM ?:order_data WHERE order_id = ?i", array('type', 'data'), $order_id); $order_return_info = @unserialize(@$additional_data[ORDER_DATA_RETURN]); $order_tax_info = @unserialize(@$additional_data['T']); $status_order = $order['status']; unset($order['status']); if ($recalculate_type == 'R') { $product_groups = @unserialize(@$additional_data['G']); if ($is_refund == 'Y') { $sign = $ex_data['inventory_to'] == 'I' ? -1 : 1; // What for is this section ??? if (!empty($order_return_info['returned_products'])) { foreach ($order_return_info['returned_products'] as $item_id => $item) { if (isset($item['extra']['returns'][$return_id])) { $r_item = $o_item = $item; unset($r_item['extra']['returns'][$return_id]); $r_item['amount'] = $item['amount'] - $item['extra']['returns'][$return_id]['amount']; fn_rma_recalculate_order_routine($order, $r_item, $item, 'O-', $ex_data); if (empty($r_item['amount'])) { unset($order_return_info['returned_products'][$item_id]); } else { $order_return_info['returned_products'][$item_id] = $r_item; } $o_item['primordial_amount'] = (isset($order_items[$item_id]) ? $order_items[$item_id]['amount'] : 0) + $item['extra']['returns'][$return_id]['amount']; $o_item['primordial_discount'] = @$o_item['extra']['discount']; fn_rma_recalculate_order_routine($order, $o_item, $item, 'M+', $ex_data); $o_item['amount'] = (isset($order_items[$item_id]) ? $order_items[$item_id]['amount'] : 0) + $item['extra']['returns'][$return_id]['amount']; if (isset($order_items[$item_id]['extra'])) { $o_item['extra'] = @unserialize($order_items[$item_id]['extra']); } $o_item['extra']['returns'][$return_id] = $item['extra']['returns'][$return_id]; $o_item['extra'] = serialize($o_item['extra']); if (!isset($order_items[$item_id])) { db_query("REPLACE INTO ?:order_details ?e", $o_item); } else { db_query("UPDATE ?:order_details SET ?u WHERE item_id = ?i AND order_id = ?i", $o_item, $item_id, $order_id); } } } } // Check all the products and update their amount and cost. foreach ($order_items as $item_id => $item) { $item['extra'] = @unserialize($item['extra']); if (isset($item['extra']['returns'][$return_id])) { $o_item = $item; $o_item['amount'] = $o_item['amount'] + $sign * $item['extra']['returns'][$return_id]['amount']; unset($o_item['extra']['returns'][$return_id]); if (empty($o_item['extra']['returns'])) { unset($o_item['extra']['returns']); } fn_rma_recalculate_order_routine($order, $o_item, $item, '', $ex_data); if (empty($o_item['amount'])) { db_query("DELETE FROM ?:order_details WHERE item_id = ?i AND order_id = ?i", $item_id, $order_id); } else { $o_item['extra'] = serialize($o_item['extra']); db_query("UPDATE ?:order_details SET ?u WHERE item_id = ?i AND order_id = ?i", $o_item, $item_id, $order_id); } if (!isset($order_return_info['returned_products'][$item_id])) { $r_item = $item; unset($r_item['extra']['returns']); $r_item['amount'] = $item['extra']['returns'][$return_id]['amount']; } else { $r_item = $order_return_info['returned_products'][$item_id]; $r_item['amount'] = $r_item['amount'] + $item['extra']['returns'][$return_id]['amount']; } fn_rma_recalculate_order_routine($order, $r_item, $item, 'M-O+', $ex_data); $r_item['extra']['returns'][$return_id] = $item['extra']['returns'][$return_id]; $order_return_info['returned_products'][$item_id] = $r_item; fn_rma_update_order_taxes($order_tax_info, $item_id, $item['amount'], $o_item['amount'], $order); } } $_ori_data = array('order_id' => $order_id, 'type' => ORDER_DATA_RETURN, 'data' => $order_return_info); } $shipping_info = array(); if ($product_groups) { $_total = 0; foreach ($product_groups as $key_group => $group) { if (isset($group['chosen_shippings'])) { foreach ($group['chosen_shippings'] as $key_shipping => $shipping) { $_total += $shipping['rate']; } } } foreach ($product_groups as $key_group => $group) { if (isset($group['chosen_shippings'])) { foreach ((array) $ex_data['shipping_costs'] as $shipping_id => $cost) { foreach ($group['chosen_shippings'] as $key_shipping => $shipping) { $shipping_id = $shipping['shipping_id']; $product_groups[$key_group]['chosen_shippings'][$key_shipping]['rate'] = fn_format_price($_total ? $shipping['rate'] / $_total * $cost : $cost / count($product_groups)); $product_groups[$key_group]['shippings'][$shipping_id]['rate'] = fn_format_price($_total ? $shipping['rate'] / $_total * $cost : $cost / count($product_groups)); if (empty($shipping_info[$shipping_id])) { $shipping_info[$shipping_id] = $product_groups[$key_group]['shippings'][$shipping_id]; } $shipping_info[$shipping_id]['rates'][$key_group] = $product_groups[$key_group]['shippings'][$shipping_id]['rate']; } } } } db_query("UPDATE ?:order_data SET ?u WHERE order_id = ?i AND type = 'G'", array('data' => serialize($product_groups)), $order_id); fn_update_shipping_taxes($order_tax_info, $shipping_info, $order); } $order['total'] -= $order['shipping_cost']; $order['shipping_cost'] = isset($ex_data['shipping_costs']) ? array_sum($ex_data['shipping_costs']) : $order['shipping_cost']; $order['total'] += $order['shipping_cost']; $order['total'] = $order['total'] < 0 ? 0 : $order['total']; if (!empty($order_tax_info)) { db_query("UPDATE ?:order_data SET ?u WHERE order_id = ?i AND type = 'T'", array('data' => serialize($order_tax_info)), $order_id); } } elseif ($recalculate_type == 'M') { $order['total'] = $order['total'] + $ex_data['total']; $_ori_data = array('order_id' => $order_id, 'type' => ORDER_DATA_RETURN, 'data' => array('return' => fn_format_price((isset($order_return_info['return']) ? $order_return_info['return'] : 0) - $ex_data['total']), 'returned_products' => isset($order_return_info['returned_products']) ? $order_return_info['returned_products'] : '')); $return_products = db_get_hash_array("SELECT * FROM ?:rma_return_products WHERE return_id = ?i AND type = ?s", 'item_id', $return_id, RETURN_PRODUCT_ACCEPTED); foreach ((array) $return_products as $item_id => $v) { $v['extra']['product_options'] = @unserialize($v['extra']['product_options']); if ($ex_data['inventory_to'] == 'D' || $ex_data['status_to'] == RMA_DEFAULT_STATUS) { fn_update_product_amount($v['product_id'], $v['amount'], @$v['extra']['product_options'], '-'); } elseif ($ex_data['inventory_to'] == 'I') { fn_update_product_amount($v['product_id'], $v['amount'], $v['extra']['product_options'], '+'); } } } if ($is_refund == 'Y') { if (isset($_ori_data['data']['return']) && floatval($_ori_data['data']['return']) == 0) { unset($_ori_data['data']['return']); } if (empty($_ori_data['data']['returned_products'])) { unset($_ori_data['data']['returned_products']); } if (!empty($_ori_data['data'])) { $_ori_data['data'] = serialize($_ori_data['data']); db_query("REPLACE INTO ?:order_data ?e", $_ori_data); } else { db_query("DELETE FROM ?:order_data WHERE order_id = ?i AND type = ?s", $order_id, ORDER_DATA_RETURN); } } foreach ($order as $k => $v) { $order[$k] = fn_format_price($v); } db_query("UPDATE ?:orders SET ?u WHERE order_id = ?i", $order, $order_id); if (fn_allowed_for('MULTIVENDOR')) { $_SESSION['cart'] = isset($_SESSION['cart']) ? $_SESSION['cart'] : array(); $cart =& $_SESSION['cart']; $action = 'save'; fn_mve_place_order($order_id, $action, $status_order, $cart); } }
/** * Copy all layout data from one layout to another by ID * @param integer $from_layout_id source layout ID * @param integer $to_layout_id target layout ID * @return boolean true on success, false - otherwise */ public function copyById($from_layout_id, $to_layout_id) { $from_layout = $this->get($from_layout_id); if (empty($from_layout)) { return false; } $object_ids = array(); $location = Location::instance($from_layout_id)->copy($to_layout_id); $target_company_id = 0; if (fn_allowed_for('ULTIMATE')) { $target_company_id = db_get_field("SELECT company_id FROM ?:bm_layouts WHERE layout_id = ?i", $to_layout_id); } // Copy logos $types = fn_get_logo_types(); foreach ($types as $type => $data) { if (!empty($data['for_layout'])) { $object_ids[$type] = fn_create_logo(array('type' => $type, 'layout_id' => $to_layout_id), $target_company_id); } } $logo_ids = db_get_hash_single_array("SELECT logo_id, type FROM ?:logos WHERE layout_id = ?i AND type IN (?a)", array('type', 'logo_id'), $from_layout_id, array_keys($object_ids)); foreach ($logo_ids as $type => $logo_id) { fn_clone_image_pairs($object_ids[$type], $logo_id, 'logos'); } return true; }