Esempio n. 1
0
function fn_get_ebay_shippings($site_id, $service_type, $international = false)
{
    $condition = db_quote('site_id = ?i AND FIND_IN_SET(?s, service_type)', $site_id, $service_type);
    $condition .= db_quote(' AND is_international = ?s', $international == true ? 'Y' : 'N');
    $shippings = db_get_hash_multi_array("SELECT * FROM ?:ebay_shippings WHERE {$condition} ORDER BY name ASC", array('category', 'service_id'));
    return $shippings;
}
Esempio n. 2
0
function fn_get_all_states($lang_code = CART_LANGUAGE, $extended = false, $avail_only = true)
{
    $avail_cond = $avail_only == true ? " WHERE a.status = 'A' " : '';
    if ($extended == true) {
        return db_get_array("SELECT a.state_id, a.code, b.state, c.country FROM ?:states as a LEFT JOIN ?:state_descriptions as b ON b.state_id = a.state_id AND b.lang_code = ?s LEFT JOIN ?:country_descriptions as c ON c.code = a.country_code AND c.lang_code = ?s {$avail_cond} ORDER BY a.country_code, b.state", $lang_code, $lang_code);
    } else {
        return db_get_hash_multi_array("SELECT a.country_code, a.code, b.state FROM ?:states as a LEFT JOIN ?:state_descriptions as b ON b.state_id = a.state_id AND b.lang_code = ?s {$avail_cond} ORDER BY a.country_code, b.state", array('country_code'), $lang_code);
    }
}
Esempio n. 3
0
function fn_get_all_cities($avail_only = true, $lang_code = CART_LANGUAGE)
{
    $avail_cond = $avail_only == true ? " WHERE a.status = 'A' AND b.status = 'A'" : '';
    //return db_get_hash_multi_array("SELECT a.country_code, a.code, b.state FROM ?:states as a LEFT JOIN ?:state_descriptions as b ON b.state_id = a.state_id AND b.lang_code = ?s $avail_cond ORDER BY a.country_code, b.state", array('country_code'), $lang_code);
    $countries = db_get_hash_multi_array("SELECT a.country_code, a.code as state_id, b.code, c.city, b.city_id FROM ?:states as a " . "LEFT JOIN ?:rus_cities as b ON b.state_id = a.state_id " . "LEFT JOIN ?:rus_city_descriptions as c ON c.city_id = b.city_id AND c.lang_code = ?s " . "{$avail_cond} ORDER BY a.country_code, b.code, c.city", array('country_code'), $lang_code);
    $rus_countries = db_get_hash_array("SELECT city_id, city FROM ?:rus_city_descriptions WHERE lang_code = ?s", 'city_id', 'ru');
    $cities = array();
    foreach ($countries as $c_code => $states) {
        foreach ($states as $city) {
            if (!empty($city['city_id'])) {
                $cities[$c_code][$city['state_id']][] = array('code' => $city['code'], 'city' => empty($city['city']) ? $rus_countries[$city['city_id']]['city'] : $city['city']);
            }
        }
    }
    return $cities;
}
Esempio n. 4
0
 /**
  * Gets list of grids
  * @static
  * @param  array $params input params
  * @return array Array of grids as container_id => array(grid_id => block data)
  */
 public static function getList($params = array())
 {
     /**
      * Prepares params for SQL query before getting grids
      * @param array $params input params
      * @param string $lang_code 2 letter language code
      */
     fn_set_hook('get_grids_pre', $params);
     $condition = $join = '';
     $fields = array('*');
     if (!empty($params['container_ids'])) {
         $condition .= db_quote(" AND g.container_id IN (?n)", $params['container_ids']);
     }
     if (!empty($params['simple'])) {
         $fields = array('g.grid_id', 'g.container_id');
     }
     $grids = db_get_hash_multi_array("SELECT " . implode(', ', $fields) . " FROM ?:bm_containers as c " . "LEFT JOIN ?:bm_grids as g ON g.container_id = c.container_id ?p" . "WHERE 1 ?p ORDER BY g.order, g.parent_id, g.grid_id ASC", array('container_id', 'grid_id'), $join, $condition);
     /**
      * Processes grids list after getting it
      * @param array $grids Array of grids data
      */
     fn_set_hook('get_grids_post', $grids);
     return $grids;
 }
Esempio n. 5
0
 /**
  * Copies all layout data from one layout to another by their IDs.
  *
  * @param integer $source_layout_id Source layout ID
  * @param integer $target_layout_id Target layout ID
  *
  * @return boolean True on success, false - otherwise
  */
 public function copyById($source_layout_id, $target_layout_id)
 {
     $source_layout = $this->get($source_layout_id);
     if (empty($source_layout)) {
         return false;
     }
     // Copy locations, their containers, grids and blocks to the target layout
     Location::instance($source_layout_id)->copy($target_layout_id);
     $source_layout_company_id = 0;
     $target_layout_company_id = 0;
     if (fn_allowed_for('ULTIMATE')) {
         $source_layout_company_id = $source_layout['company_id'];
         $target_layout_company_id = db_get_field("SELECT company_id FROM ?:bm_layouts WHERE layout_id = ?i", $target_layout_id);
     }
     // Copy logos
     /**
      * Get the list of logos, bounded to source layout and given company.
      * List has the following format:
      *
      * [
      *   logo_type => [
      *      style_id => logo_id,
      *      ...
      *   ],
      *   ...
      * ]
      */
     $source_layout_logos = db_get_hash_multi_array('SELECT `type`, `style_id`, `logo_id` FROM ?:logos WHERE `layout_id` = ?i AND `company_id` = ?i', array('type', 'style_id', 'logo_id'), $source_layout_id, $source_layout_company_id);
     $logo_types = fn_get_logo_types();
     foreach ($logo_types as $logo_type => $logo_type_metadata) {
         if (empty($logo_type_metadata['for_layout']) || empty($source_layout_logos[$logo_type])) {
             continue;
         }
         foreach ($source_layout_logos[$logo_type] as $source_layout_style_id => $source_layout_logo_id) {
             $created_target_layout_logo_id = fn_update_logo(array('type' => $logo_type, 'layout_id' => $target_layout_id, 'style_id' => $source_layout_style_id), $target_layout_company_id);
             fn_clone_image_pairs($created_target_layout_logo_id, $source_layout_logo_id, 'logos');
         }
     }
     return true;
 }
Esempio n. 6
0
        }
        $_suffix = ".manage";
    }
    if ($mode == 'run') {
        return array(CONTROLLER_STATUS_REDIRECT, "exim.sync_vendors");
    }
    return array(CONTROLLER_STATUS_OK, "settings{$_suffix}?section_id={$section_id}");
}
//
// OUPUT routines
//
if ($mode == 'manage') {
    $descr = fn_settings_descr_query('subsection_id', 'U', CART_LANGUAGE, 'settings_subsections', 'object_string_id');
    $subsections = db_get_hash_array("SELECT ?:settings_subsections.*, ?:settings_descriptions.description, ?:settings_descriptions.object_string_id, ?:settings_descriptions.object_type FROM ?:settings_subsections ?p WHERE ?:settings_subsections.section_id = ?s ORDER BY  ?:settings_descriptions.description", 'subsection_id', $descr, $section_id);
    $descr = fn_settings_descr_query('option_id', 'O', CART_LANGUAGE, 'settings');
    $options = db_get_hash_multi_array("SELECT ?:settings.*, IF(?:settings.subsection_id = '', 'main', ?:settings.subsection_id) as subsection_id, ?:settings_descriptions.description, ?:settings_descriptions.tooltip, ?:settings_descriptions.object_type FROM ?:settings ?p WHERE ?:settings.section_id = ?s ORDER BY ?:settings_descriptions.description", array('subsection_id'), $descr, $section_id);
    $descr = fn_settings_descr_query('variant_id', 'V', CART_LANGUAGE, 'settings_variants');
    fn_get_schema('settings', 'variants', 'php', false, true);
    foreach ($options as $sid => $sct) {
        $ssid = $sid == 'main' ? '' : $sid;
        $elements = db_get_array("SELECT ?:settings_elements.*, ?:settings_descriptions.description FROM ?:settings_elements LEFT JOIN ?:settings_descriptions ON ?:settings_elements.element_id = ?:settings_descriptions.object_id AND ?:settings_descriptions.object_type = 'H' AND ?:settings_descriptions.lang_code = ?s WHERE ?:settings_elements.section_id = ?s AND ?:settings_elements.subsection_id = ?s ORDER BY ?:settings_elements.position", CART_LANGUAGE, $section_id, $ssid);
        foreach ($elements as $k => $v) {
            if (!empty($v['handler']) && $v['element_type'] == 'I') {
                $args = explode(',', $v['handler']);
                $func = array_shift($args);
                if (function_exists($func)) {
                    $elements[$k]['info'] = call_user_func_array($func, $args);
                } else {
                    $elements[$k]['info'] = "No function: {$func}";
                }
            }
Esempio n. 7
0
/**
 * Gets product prices.
 *
 * @param int $product_id Product identifier
 * @param array $product_data Array of product data. Result data will be saved in this variable.
 * @param array $auth Array of user authentication data (e.g. uid, usergroup_ids, etc.)
 * @param int $company_id Company identifier.
 */
function fn_get_product_prices($product_id, &$product_data, $auth, $company_id = 0)
{
    if (fn_allowed_for('ULTIMATE') && $company_id) {
        $table_name = '?:ult_product_prices';
        $condition = db_quote(' AND prices.company_id = ?i', $company_id);
    } else {
        $table_name = '?:product_prices';
        $condition = '';
    }
    // For customer
    if (AREA == 'C') {
        $_prices = db_get_hash_multi_array("SELECT prices.product_id, prices.lower_limit, usergroup_id, prices.percentage_discount, IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100) as price FROM {$table_name} prices WHERE prices.product_id = ?i {$condition} AND lower_limit > 1 AND prices.usergroup_id IN (?n) ORDER BY lower_limit", array('usergroup_id'), $product_id, array_merge(array(USERGROUP_ALL), $auth['usergroup_ids']));
        if (!fn_allowed_for('ULTIMATE:FREE')) {
            // If customer has usergroup and prices defined for this usergroup, get them
            if (!empty($auth['usergroup_ids'])) {
                foreach ($auth['usergroup_ids'] as $ug_id) {
                    if (!empty($_prices[$ug_id]) && sizeof($_prices[$ug_id]) > 0) {
                        if (empty($product_data['prices'])) {
                            $product_data['prices'] = $_prices[$ug_id];
                        } else {
                            foreach ($_prices[$ug_id] as $comp_data) {
                                $add_elm = true;
                                foreach ($product_data['prices'] as $price_id => $price_data) {
                                    if ($price_data['lower_limit'] == $comp_data['lower_limit']) {
                                        $add_elm = false;
                                        if ($price_data['price'] > $comp_data['price']) {
                                            $product_data['prices'][$price_id] = $comp_data;
                                        }
                                        break;
                                    }
                                }
                                if ($add_elm) {
                                    $product_data['prices'][] = $comp_data;
                                }
                            }
                        }
                    }
                }
                if (!empty($product_data['prices'])) {
                    $tmp = array();
                    foreach ($product_data['prices'] as $price_id => $price_data) {
                        $tmp[$price_id] = $price_data['lower_limit'];
                    }
                    array_multisort($tmp, SORT_ASC, $product_data['prices']);
                }
            }
        }
        // else, get prices for not members
        if (empty($product_data['prices']) && !empty($_prices[0]) && sizeof($_prices[0]) > 0) {
            $product_data['prices'] = $_prices[0];
        }
        // Other - get all
    } else {
        $product_data['prices'] = db_get_array("SELECT prices.product_id, prices.lower_limit, usergroup_id, prices.percentage_discount, IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100) as price FROM {$table_name} prices WHERE product_id = ?i {$condition} ORDER BY usergroup_id, lower_limit", $product_id);
    }
}
Esempio n. 8
0
/**
 * Check if product has certain features
 *
 * @param array $promotion promotion data
 * @param array $product product data
 * @return mixed feature value if found, boolean false otherwise
 */
function fn_promotions_check_features($promotion, $product)
{
    $features = db_get_hash_multi_array("SELECT feature_id, variant_id, value, value_int FROM ?:product_features_values WHERE product_id = ?i AND lang_code = ?s", array('feature_id'), $product['product_id'], CART_LANGUAGE);
    if (!empty($features) && !empty($promotion['condition_element']) && !empty($features[$promotion['condition_element']])) {
        $f = $features[$promotion['condition_element']];
        $result = array();
        foreach ($f as $v) {
            $result[] = !empty($v['variant_id']) ? $v['variant_id'] : ($v['value_int'] != '' ? $v['value_int'] : $v['value']);
        }
        return $result;
    }
    return false;
}
Esempio n. 9
0
/**
 * Gets image pairs (icon, detailed)
 *
 * @param array/int $object_ids List of Object IDs or Object ID
 * @param string $object_type Type: product, category, banner, etc.
 * @param string $pair_type (M)ain or (A)dditional
 * @param bool $get_icon
 * @param bool $get_detailed
 * @param string $lang_code 2-letters code
 * @return array Pair data
 */
function fn_get_image_pairs($object_ids, $object_type, $pair_type, $get_icon = true, $get_detailed = true, $lang_code = CART_LANGUAGE)
{
    /**
     * Changes input params for fn_get_image_pairs function
     *
     * @param  array/int $object_ids   List of Object IDs or Object ID
     * @param  string    $object_type  Type: product, category, banner, etc.
     * @param  string    $pair_type    (M)ain or (A)dditional
     * @param  bool      $get_icon
     * @param  bool      $get_detailed
     * @param  string    $lang_code    2-letters code
     * @return array     Pair data
     */
    fn_set_hook('get_image_pairs_pre', $object_ids, $object_type, $pair_type, $get_icon, $get_detailed, $lang_code);
    $icon_pairs = $detailed_pairs = $pairs_data = array();
    $cond = is_array($object_ids) ? db_quote("AND ?:images_links.object_id IN (?n)", $object_ids) : db_quote("AND ?:images_links.object_id = ?i", $object_ids);
    if ($get_icon == true || $get_detailed == true) {
        if ($get_icon == true) {
            $join_cond = "?:images_links.image_id = ?:images.image_id";
            $icon_pairs = db_get_array("SELECT ?:images_links.*, ?:images.image_path, ?:common_descriptions.description AS alt, ?:images.image_x, ?:images.image_y, ?:images.image_id as images_image_id" . " FROM ?:images_links" . " LEFT JOIN ?:images ON {$join_cond}" . " 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_links.object_type = ?s AND ?:images_links.type = ?s {$cond}" . " ORDER BY ?:images_links.position, ?:images_links.pair_id", $lang_code, $object_type, $pair_type);
        }
        if ($get_detailed == true) {
            $join_cond = db_quote("?:images_links.detailed_id = ?:images.image_id");
            $detailed_pairs = db_get_array("SELECT ?:images_links.*, ?:images.image_path, ?:common_descriptions.description AS alt, ?:images.image_x, ?:images.image_y, ?:images.image_id as images_image_id" . " FROM ?:images_links" . " LEFT JOIN ?:images ON {$join_cond}" . " 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_links.object_type = ?s AND ?:images_links.type = ?s {$cond}" . " ORDER BY ?:images_links.position, ?:images_links.pair_id", $lang_code, $object_type, $pair_type);
        }
        foreach ((array) $object_ids as $object_id) {
            $pairs_data[$object_id] = array();
        }
        // Convert the received data to the standard format in order to keep the backward compatibility
        foreach ($icon_pairs as $pair) {
            $_pair = array('pair_id' => $pair['pair_id'], 'image_id' => $pair['image_id'], 'detailed_id' => $pair['detailed_id'], 'position' => $pair['position']);
            if (!empty($pair['images_image_id'])) {
                //get icon data if exist
                $icon = fn_attach_absolute_image_paths($pair, $object_type);
                $_pair['icon'] = array('image_path' => $icon['image_path'], 'alt' => $icon['alt'], 'image_x' => $icon['image_x'], 'image_y' => $icon['image_y'], 'http_image_path' => $icon['http_image_path'], 'https_image_path' => $icon['https_image_path'], 'absolute_path' => $icon['absolute_path'], 'relative_path' => $icon['relative_path']);
            }
            $pairs_data[$pair['object_id']][$pair['pair_id']] = $_pair;
        }
        // -foreach icon_pairs
        foreach ($detailed_pairs as $pair) {
            $pair_id = $pair['pair_id'];
            $object_id = $pair['object_id'];
            if (!empty($pairs_data[$object_id][$pair_id]['detailed_id'])) {
                $detailed = fn_attach_absolute_image_paths($pair, 'detailed');
                $pairs_data[$object_id][$pair_id]['detailed'] = array('image_path' => $detailed['image_path'], 'alt' => $detailed['alt'], 'image_x' => $detailed['image_x'], 'image_y' => $detailed['image_y'], 'http_image_path' => $detailed['http_image_path'], 'https_image_path' => $detailed['https_image_path'], 'absolute_path' => $detailed['absolute_path'], 'relative_path' => $detailed['relative_path']);
            } elseif (empty($pairs_data[$object_id][$pair_id]['pair_id'])) {
                $pairs_data[$object_id][$pair_id] = array('pair_id' => $pair['pair_id'], 'image_id' => $pair['image_id'], 'detailed_id' => $pair['detailed_id'], 'position' => $pair['position']);
                if (!empty($pair['images_image_id'])) {
                    //get detailed data if exist
                    $detailed = fn_attach_absolute_image_paths($pair, 'detailed');
                    $pairs_data[$object_id][$pair_id]['detailed'] = array('image_path' => $detailed['image_path'], 'alt' => $detailed['alt'], 'image_x' => $detailed['image_x'], 'image_y' => $detailed['image_y'], 'http_image_path' => $detailed['http_image_path'], 'https_image_path' => $detailed['https_image_path'], 'absolute_path' => $detailed['absolute_path'], 'relative_path' => $detailed['relative_path']);
                }
            }
        }
        // -foreach detailed_pairs
    } else {
        $pairs_data = db_get_hash_multi_array("SELECT pair_id, image_id, detailed_id, object_id FROM ?:images_links WHERE object_type = ?s AND type = ?s {$cond}", array('object_id', 'pair_id'), $object_type, $pair_type);
    }
    /**
     * Changes pair data informatin
     *
     * @param array/int $object_ids   List of Object IDs or Object ID
     * @param string    $object_type  Type: product, category, banner, etc.
     * @param string    $pair_type    (M)ain or (A)dditional
     * @param bool      $get_icon
     * @param bool      $get_detailed
     * @param string    $lang_code    2-letters code
     * @param array     $pairs_data   Pairs data
     */
    fn_set_hook('get_image_pairs_post', $object_ids, $object_type, $pair_type, $get_icon, $get_detailed, $lang_code, $pairs_data);
    if (is_array($object_ids)) {
        return $pairs_data;
    } else {
        if ($pair_type == 'A') {
            return $pairs_data[$object_ids];
        } else {
            return !empty($pairs_data[$object_ids]) ? reset($pairs_data[$object_ids]) : array();
        }
    }
}
Esempio n. 10
0
/**
 * Gets full information about particular statuses
 * @param string $type One letter status type
 * @param array $status_to_select Array of statuses that should be retrieved. If empty, all statuses will be retrieved
 * @param boolean $additional_statuses Flag that determines whether additional (hidden) statuses should be retrieved
 * @param boolean $exclude_parent Flag that determines whether parent statuses should be excluded
 * @param string $lang_code Language code
 * @param int $company_id Company identifier
 * @return Statuses
 */
function fn_get_statuses($type = STATUSES_ORDER, $status_to_select = array(), $additional_statuses = false, $exclude_parent = false, $lang_code = DESCR_SL, $company_id = 0)
{
    fn_set_hook('get_statuses_pre', $type, $status_to_select, $additional_statuses, $exclude_parent, $lang_code, $company_id);
    $join = db_quote(" LEFT JOIN ?:status_descriptions ON ?:status_descriptions.status = ?:statuses.status AND ?:status_descriptions.type = ?:statuses.type AND ?:status_descriptions.lang_code = ?s", $lang_code);
    $condition = db_quote(" AND ?:statuses.type = ?s", $type);
    $condition .= !empty($status_to_select) ? db_quote(" AND ?:statuses.status IN (?a)", $status_to_select) : '';
    fn_set_hook('get_statuses', $join, $condition, $type, $status_to_select, $additional_statuses, $exclude_parent, $lang_code, $company_id);
    $statuses = db_get_hash_array("SELECT ?:statuses.*, ?:status_descriptions.*" . " FROM ?:statuses" . $join . " WHERE 1 {$condition}", 'status');
    $statuses_params = db_get_hash_multi_array("SELECT param, value, status FROM ?:status_data WHERE type = ?s", array('status', 'param'), $type);
    foreach ($statuses as $status => $status_data) {
        $statuses[$status]['params'] = array();
        if (isset($statuses_params[$status])) {
            foreach ($statuses_params[$status] as $param_name => $param_data) {
                $statuses[$status]['params'][$param_name] = $param_data['value'];
            }
        }
    }
    if ($type == STATUSES_ORDER && $additional_statuses && empty($status_to_select)) {
        $statuses[STATUS_INCOMPLETED_ORDER] = array('status' => STATUS_INCOMPLETED_ORDER, 'description' => __('incompleted', '', $lang_code), 'type' => STATUSES_ORDER, 'params' => array('inventory' => 'I'));
        if (empty($exclude_parent)) {
            $statuses[STATUS_PARENT_ORDER] = array('status' => STATUS_PARENT_ORDER, 'description' => __('parent_order', '', $lang_code), 'type' => STATUSES_ORDER, 'params' => array('inventory' => 'I'));
        }
    }
    fn_set_hook('get_statuses_post', $statuses, $join, $condition, $type, $status_to_select, $additional_statuses, $exclude_parent, $lang_code, $company_id);
    return $statuses;
}
Esempio n. 11
0
function fn_twg_api_get_product_options($product, $lang_code = CART_LANGUAGE)
{
    $condition = $_status = $join = '';
    $extra_variant_fields = '';
    $option_ids = $variants_ids = $options = array();
    $_status .= " AND status = 'A'";
    $product_ids = $product['product_id'];
    $join = db_quote(" LEFT JOIN ?:product_options_descriptions as b\n         ON a.option_id = b.option_id AND b.lang_code = ?s ", $lang_code);
    $fields = "a.*, b.option_name, b.option_text, b.description, b.inner_hint, b.incorrect_message, b.comment";
    if (!empty($product_ids)) {
        $_options = db_get_hash_multi_array("SELECT " . $fields . " FROM ?:product_options as a " . $join . " WHERE a.product_id IN (?n)" . $condition . $_status . " ORDER BY a.position", array('product_id', 'option_id'), $product_ids);
        $fields = "c.product_id AS cur_product_id, a.*, " . "b.option_name, b.option_text, b.description, b.inner_hint, " . "b.incorrect_message, b.comment";
        $global_options = db_get_hash_multi_array("SELECT {$fields}" . " FROM ?:product_options as a" . " LEFT JOIN ?:product_options_descriptions as b ON a.option_id = b.option_id AND b.lang_code = ?s" . " LEFT JOIN ?:product_global_option_links as c ON c.option_id = a.option_id" . " WHERE c.product_id IN (?n) AND a.product_id = 0" . $condition . $_status . " ORDER BY a.position", array('cur_product_id', 'option_id'), $lang_code, $product_ids);
        foreach ((array) $product_ids as $product_id) {
            $_opts = (empty($_options[$product_id]) ? array() : $_options[$product_id]) + (empty($global_options[$product_id]) ? array() : $global_options[$product_id]);
            $options[$product_id] = fn_sort_array_by_key($_opts, 'position');
        }
    } else {
        //we need a separate query for global options
        $options = db_get_hash_multi_array("SELECT a.*, b.option_name, b.option_text, b.description, b.inner_hint, b.incorrect_message, b.comment" . " FROM ?:product_options as a" . $join . " WHERE a.product_id = 0" . $condition . $_status . " ORDER BY a.position", array('product_id', 'option_id'));
    }
    foreach ($options as $product_id => $_options) {
        $option_ids = array_merge($option_ids, array_keys($_options));
    }
    if (empty($option_ids)) {
        if (is_array($product_ids)) {
            return $options;
        } else {
            return !empty($options[$product_ids]) ? $options[$product_ids] : array();
        }
    }
    $_status = " AND a.status='A'";
    $v_fields = "a.variant_id, a.option_id, a.position, a.modifier, " . "a.modifier_type, a.weight_modifier, a.weight_modifier_type, " . "{$extra_variant_fields} b.variant_name";
    $v_join = db_quote("LEFT JOIN ?:product_option_variants_descriptions as b\n         ON a.variant_id = b.variant_id\n         AND b.lang_code = ?s", $lang_code);
    $v_condition = db_quote("a.option_id IN (?n) {$_status}", array_unique($option_ids));
    $v_sorting = "a.position, a.variant_id";
    $variants = db_get_hash_multi_array("SELECT {$v_fields} FROM ?:product_option_variants as a {$v_join} WHERE {$v_condition} ORDER BY {$v_sorting}", array('option_id', 'variant_id'));
    foreach ($variants as $option_id => $_variants) {
        $variants_ids = array_merge($variants_ids, array_keys($_variants));
    }
    if (isset($variants_ids) && empty($variants_ids)) {
        return is_array($product_ids) ? $options : $options[$product_ids];
    }
    $image_pairs = fn_get_image_pairs(array_unique($variants_ids), 'variant_image', 'V', true, true, $lang_code);
    foreach ($variants as $option_id => &$_variants) {
        foreach ($_variants as $variant_id => &$_variant) {
            $_variant['image_pair'] = !empty($image_pairs[$variant_id]) ? reset($image_pairs[$variant_id]) : array();
        }
    }
    foreach ($options as $product_id => &$_options) {
        foreach ($_options as $option_id => &$_option) {
            // Add variant names manually, if this option is "checkbox"
            if ($_option['option_type'] == 'C' && !empty($variants[$option_id])) {
                foreach ($variants[$option_id] as $variant_id => $variant) {
                    $variants[$option_id][$variant_id]['variant_name'] = $variant['position'] == 0 ? __('no') : __('yes');
                }
            }
            $_option['variants'] = !empty($variants[$option_id]) ? $variants[$option_id] : array();
        }
    }
    return is_array($product_ids) ? $options : $options[$product_ids];
}
Esempio n. 12
0
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_multi_array("SELECT p.profile_id, d.description, f.value, c.section, c.field_id 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' LEFT JOIN ?:profile_fields as c ON f.field_id = c.field_id WHERE p.user_id = ?i", array('field_id', 'section'), $lang_code, $user_id);
    if (!empty($_user)) {
        $fields['user'] = $_user;
    }
    if (!empty($_profile)) {
        $fields['profile'] = $_profile;
    }
    if (!empty($fields)) {
        return fn_exim_json_encode($fields);
    }
    return '';
}
Esempio n. 13
0
function fn_banners_install()
{
    $banners = db_get_hash_multi_array("SELECT ?:banners.banner_id, ?:banner_images.banner_image_id, ?:banner_images.lang_code FROM ?:banners LEFT JOIN ?:banner_images ON ?:banner_images.banner_id = ?:banners.banner_id", array('lang_code', 'banner_id'));
    $langs = array_keys(Languages::getAll());
    $need_clone_langs = array_diff($langs, array_keys($banners));
    if (!empty($need_clone_langs)) {
        $clone_lang = DEFAULT_LANGUAGE;
        if (in_array(DEFAULT_LANGUAGE, $need_clone_langs)) {
            $clone_lang = 'en';
        }
        foreach ($banners[$clone_lang] as $banner_id => &$banner) {
            $banner['main_pair'] = fn_get_image_pairs($banner['banner_image_id'], 'promo', 'M', true, false, $clone_lang);
        }
        foreach ($need_clone_langs as $need_clone_lang) {
            fn_banners_clone($banners[$clone_lang], $need_clone_lang);
        }
    }
    foreach ($banners['en'] as $banner_id => &$banner) {
        $banner['main_pair'] = fn_get_image_pairs($banner['banner_image_id'], 'promo', 'M', true, false, 'en');
    }
    if (!in_array('en', $langs)) {
        $banner_images_ids = db_get_fields("SELECT banner_image_id FROM ?:banner_images WHERE lang_code = ?s", 'en');
        foreach ($banner_images_ids as $banner_image_id) {
            fn_delete_image_pairs($banner_image_id, 'promo');
        }
        if (!empty($banner_images_ids)) {
            db_query("DELETE FROM ?:banner_images WHERE banner_image_id IN (?n)", $banner_images_ids);
        }
    }
    return true;
}
Esempio n. 14
0
function fn_get_ebay_shippings($service_type, $international = false)
{
    $site_id = Ebay::instance()->site_id;
    $condition = db_quote('site_id = ?i AND FIND_IN_SET(?s, service_type)', $site_id, $service_type);
    $condition .= db_quote(' AND is_international = ?s', $international == true ? 'Y' : 'N');
    $shippings = db_get_hash_multi_array("SELECT * FROM ?:ebay_shippings WHERE {$condition} ORDER BY name ASC", array('category', 'service_id'));
    if (empty($shippings)) {
        fn_set_notification('W', __('warning'), __('wait_for_shippings_cached'));
        register_shutdown_function('fn_register_ebay_shippings', $site_id);
    }
    return $shippings;
}
Esempio n. 15
0
 //
 // Delete selected usergroups
 //
 if ($mode == 'm_delete') {
     if (!empty($_REQUEST['usergroup_ids'])) {
         fn_delete_usergroups($_REQUEST['usergroup_ids']);
     }
     $suffix .= '.manage';
 }
 if ($mode == 'bulk_update_status') {
     if (!empty($_REQUEST['link_ids'])) {
         $new_status = $action == 'approve' ? 'A' : 'D';
         db_query("UPDATE ?:usergroup_links SET status = ?s WHERE link_id IN(?n)", $new_status, $_REQUEST['link_ids']);
         $force_notification = fn_get_notification_rules($_REQUEST);
         if (!empty($force_notification['C'])) {
             $usergroup_links = db_get_hash_multi_array("SELECT * FROM ?:usergroup_links WHERE link_id IN(?n)", array('user_id', 'usergroup_id'), $_REQUEST['link_ids']);
             foreach ($usergroup_links as $u_id => $val) {
                 fn_send_usergroup_status_notification($u_id, array_keys($val), $new_status);
             }
         }
     }
     $suffix = ".requests";
 }
 if ($mode == 'delete') {
     if (!empty($_REQUEST['usergroup_id'])) {
         fn_delete_usergroups((array) $_REQUEST['usergroup_id']);
     }
     return array(CONTROLLER_STATUS_REDIRECT, 'usergroups.manage');
 }
 if ($mode == 'update_status') {
     $user_data = fn_get_user_info($_REQUEST['user_id']);
Esempio n. 16
0
/**
 * Sets main category to category of product owner company
 * @param type $product_id product ID
 * @param type $product_data product data
 */
function fn_ult_update_product_categories_pre($product_id, &$product_data)
{
    if (empty($product_data['main_category']) && !empty($product_data['category_ids'])) {
        $companies = db_get_hash_multi_array("SELECT category_id, company_id FROM ?:categories WHERE category_id IN (?n)", array('company_id', 'category_id'), $product_data['category_ids']);
        if (!empty($companies[$product_data['company_id']])) {
            $product_data['main_category'] = key($companies[$product_data['company_id']]);
        }
    }
}
use Tygh\Registry;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
if ($mode == 'manage') {
    $posts = Registry::get('view')->getTemplateVars('posts');
    $ids = array();
    foreach ($posts as $k => $v) {
        $ids[] = $v['post_id'];
        //get review attributes available for each post
        if (($v['type'] == 'R' || $v['type'] == 'B') && $v['object_type'] == 'P') {
            $posts[$k]['attributes'] = fn_get_review_attributes($v['object_id']);
        }
    }
    //get rating values for each post
    $ratings = db_get_hash_multi_array('SELECT post_id, attr_id, rating FROM ?:review_rating WHERE post_id IN (?n)', array('post_id', 'attr_id', 'rating'), $ids);
    foreach ($posts as $k => $post) {
        if (isset($post['attributes'])) {
            foreach ($post['attributes'] as $key => $attribute) {
                $posts[$k]['attributes'][$key]['value'] = isset($ratings[$post['post_id']][$attribute['attr_id']]) ? $ratings[$post['post_id']][$attribute['attr_id']] : 0;
            }
        }
    }
    //get additional field message title
    $_titles = db_get_array('SELECT post_id, message_title FROM ?:discussion_messages WHERE post_id IN (?n)', $ids);
    foreach ($_titles as $v) {
        $titles[$v['post_id']] = $v['message_title'];
    }
    foreach ($posts as $k => $v) {
        if (isset($titles[$v['post_id']])) {
            $posts[$k]['message_title'] = $titles[$v['post_id']];
Esempio n. 18
0
/**
 * Prepares SQL query for the table condition
 *
 * @param array $table_condition Report data query parameters
 * @param bool|string $alias Table alias
 * @return string Report data select condition
 */
function fn_proceed_table_conditions($table_condition, $alias = false)
{
    $order_ids = '';
    $ord_field = empty($alias) ? "order_id" : $alias . ".order_id";
    if (!empty($table_condition['status'])) {
        $st_field = empty($alias) ? "status" : $alias . ".status";
        $order_ids .= db_quote(" AND {$st_field} IN (?a)", $table_condition['status']);
    }
    $st_field = empty($alias) ? "status" : $alias . ".status";
    $order_ids .= db_quote(" AND {$st_field} != ?s", 'T');
    $st_field = empty($alias) ? "is_parent_order" : $alias . ".is_parent_order";
    $order_ids .= db_quote(" AND {$st_field} != ?s", 'Y');
    if (Registry::get('runtime.company_id')) {
        $st_field = empty($alias) ? "company_id" : $alias . ".company_id";
        $order_ids .= db_quote(" AND {$st_field} = ?i", Registry::get('runtime.company_id'));
    }
    if (!empty($table_condition['order'])) {
        $order_ids .= db_quote(" AND {$ord_field} IN (?n)", $table_condition['order']);
    }
    if (!empty($table_condition['user'])) {
        $usr_field = empty($alias) ? "user_id" : $alias . ".user_id";
        $order_ids .= db_quote(" AND {$usr_field} IN (?n)", $table_condition['user']);
    }
    if (!empty($table_condition['payment'])) {
        $pm_field = empty($alias) ? "payment_id" : $alias . ".payment_id";
        $order_ids .= db_quote(" AND {$pm_field} IN (?n)", $table_condition['payment']);
    }
    if (!empty($table_condition['product'])) {
        $order_products = db_get_fields("SELECT order_id FROM ?:order_details WHERE product_id IN (?n) ORDER BY order_id", $table_condition['product']);
        if (!empty($order_products)) {
            $order_ids .= db_quote(" AND {$ord_field} IN (?n)", $order_products);
        }
    }
    if (!empty($table_condition['category'])) {
        $order_products = db_get_fields("SELECT a.order_id FROM ?:order_details as a LEFT JOIN ?:products_categories as b ON a.product_id = b.product_id WHERE b.category_id IN (?n) ORDER BY a.order_id", $table_condition['category']);
        if (!empty($order_products)) {
            $order_ids .= db_quote(" AND {$ord_field} IN (?n)", $order_products);
        } else {
            $order_ids .= " AND {$ord_field} IN ('')";
        }
    }
    if (!empty($table_condition['location'])) {
        $states = db_get_fields("SELECT a.code FROM ?:states AS a LEFT JOIN ?:destination_elements AS b ON a.state_id = b.element WHERE b.destination_id IN (?n) AND b.element_type = 'S'", $table_condition['location']);
        $countries = db_get_fields("SELECT element FROM ?:destination_elements WHERE destination_id IN (?n) AND element_type = 'C'", $table_condition['location']);
        $countries_with_states = array();
        // group states by countries
        if (!empty($countries)) {
            $countries_with_states = db_get_hash_multi_array("SELECT country_code, code, 1 AS value" . " FROM ?:states" . " WHERE status = ?s" . " AND country_code IN (?a)", array('country_code', 'code', 'value'), "A", $countries);
            foreach ($countries as $country_code) {
                if (isset($countries_with_states[$country_code])) {
                    $countries_with_states[$country_code] = array_intersect(array_keys($countries_with_states[$country_code]), $states);
                } else {
                    $countries_with_states[$country_code] = array();
                }
            }
        }
        // states behind groups
        if (!empty($countries_with_states)) {
            $states = array_diff($states, call_user_func_array('array_merge', $countries_with_states));
        }
        $ss_field = empty($alias) ? "s_state" : $alias . ".s_state";
        $cs_field = empty($alias) ? "s_country" : $alias . ".s_country";
        $location_condition = array();
        if (!empty($countries_with_states)) {
            foreach ($countries_with_states as $country_code => $country_states) {
                $condition = db_quote(" {$cs_field} = ?l", $country_code);
                if ($country_states) {
                    $condition .= db_quote(" AND {$ss_field} IN (?a)", $country_states);
                }
                $location_condition[] = $condition;
            }
        }
        if (!empty($states)) {
            $location_condition[] = db_quote(" {$ss_field} IN (?a)", $states);
        }
        if ($location_condition) {
            $order_ids .= " AND (" . implode(" OR ", $location_condition) . ')';
        }
    }
    return $order_ids;
}
Esempio n. 19
0
function fn_get_banners_statistics($params)
{
    $condition = '';
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
    } else {
        $params['period'] = 'A';
        $params['time_from'] = '';
        $params['time_to'] = '';
    }
    if (!empty($params['time_from'])) {
        $condition .= db_quote(" AND timestamp >= ?i", $params['time_from']);
    }
    if (!empty($params['time_to'])) {
        $condition .= db_quote(" AND timestamp <= ?i", $params['time_to']);
    }
    $log = db_get_hash_multi_array("SELECT type, COUNT(type) as number, banner_id FROM ?:stat_banners_log WHERE 1 ?p GROUP BY banner_id, type ORDER BY timestamp DESC", array('banner_id', 'type'), $condition);
    foreach ($log as $b_id => $v) {
        if (!empty($v['C']['number']) && !empty($v['V']['number'])) {
            $log[$b_id]['conversion'] = sprintf('%.2f', $v['C']['number'] / $v['V']['number'] * 100);
            if (floatval($log[$b_id]['conversion']) == intval($log[$b_id]['conversion'])) {
                $log[$b_id]['conversion'] = intval($log[$b_id]['conversion']);
            }
        }
    }
    $banner_ids = array_keys($log);
    if (!empty($banner_ids)) {
        $_params = array('item_ids' => implode(',', $banner_ids));
        list($banners) = fn_get_banners($_params);
    } else {
        $banners = array();
    }
    $data = array('log' => $log, 'banners' => $banners);
    return array($data, $params, count($banner_ids));
}
Esempio n. 20
0
    if (!empty($_REQUEST['rem_global_section']) && $_REQUEST['rem_global_section'] == 'Y') {
        db_query("UPDATE ?:settings SET is_global = 'N' WHERE section_id = ?s", $section_id);
    }
    // \FOR DEVELOPMENT PURPOSES ONLY!!!
    return array(CONTROLLER_STATUS_OK, "settings_dev.manage?section_id={$section_id}");
}
if ($mode == 'manage') {
    //
    // OUPUT routines
    //
    $descr = fn_settings_descr_query('section_id', 'S', CART_LANGUAGE, 'settings_sections', 'object_string_id');
    $sections = db_get_hash_array("SELECT ?:settings_sections.*, ?:settings_descriptions.description FROM ?:settings_sections {$descr} ORDER BY ?:settings_descriptions.description", 'section_id');
    $descr = fn_settings_descr_query('subsection_id', 'U', CART_LANGUAGE, 'settings_subsections', 'object_string_id');
    $subsections = db_get_hash_array("SELECT ?:settings_subsections.*, ?:settings_descriptions.description FROM ?:settings_subsections {$descr} WHERE ?:settings_subsections.section_id = ?s ORDER BY ?:settings_subsections.position", 'subsection_id', $section_id);
    $descr = fn_settings_descr_query('option_id', 'O', CART_LANGUAGE, 'settings');
    $options = db_get_hash_multi_array("SELECT ?:settings.*, ?:settings_descriptions.description, ?:settings_descriptions.tooltip FROM ?:settings {$descr} WHERE ?:settings.section_id = ?s ORDER BY ?:settings.position", array('subsection_id'), $section_id);
    $options['main'] = $options[''];
    unset($options['']);
    $descr = fn_settings_descr_query('variant_id', 'V', CART_LANGUAGE, 'settings_variants');
    fn_get_schema('settings', 'variants', 'php', false, true);
    fn_get_schema('settings', 'actions', 'php', false, true);
    foreach ($options as $sid => $sct) {
        $ssid = $sid == 'main' ? '' : $sid;
        $elements = db_get_array("SELECT ?:settings_elements.*, ?:settings_descriptions.description FROM ?:settings_elements LEFT JOIN ?:settings_descriptions ON ?:settings_elements.element_id = ?:settings_descriptions.object_id AND ?:settings_descriptions.object_type = 'H' AND ?:settings_descriptions.lang_code = ?s WHERE ?:settings_elements.section_id = ?s AND ?:settings_elements.subsection_id = ?s ORDER BY ?:settings_elements.position", CART_LANGUAGE, $section_id, $ssid);
        foreach ($elements as $k => $v) {
            if (!empty($v['handler']) && $v['element_type'] == 'I') {
                $args = explode(',', $v['handler']);
                $func = array_shift($args);
                $elements[$k]['info'] = function_exists($func) ? call_user_func_array($func, $args) : 'Function not exists';
            }
        }
Esempio n. 21
0
 private static function _backupLogos()
 {
     $images['images_links'] = db_get_hash_array("SELECT * FROM ?:images_links WHERE object_type = 'logos'", 'image_id');
     if (!empty($images['images_links'])) {
         $images['images_data'] = db_get_hash_array("SELECT * FROM ?:images WHERE image_id IN (?a)", 'image_id', array_keys($images['images_links']));
         $images['images_descriptions'] = db_get_hash_multi_array("SELECT * FROM ?:common_descriptions WHERE object_id IN (?a)", array('lang_code', 'object_id'), array_keys($images['images_data']));
     }
     return $images;
 }
Esempio n. 22
0
if ($mode == 'assign_privileges' && !empty($_REQUEST['usergroup_id'])) {
    if (defined('RESTRICTED_ADMIN')) {
        $requested_mtype = db_get_field("SELECT type FROM ?:usergroups WHERE usergroup_id = ?i", $_REQUEST['usergroup_id']);
        if ($requested_mtype == 'A') {
            return array(CONTROLLER_STATUS_DENIED);
        }
    }
    $usergroup_name = db_get_field("SELECT usergroup FROM ?:usergroup_descriptions WHERE usergroup_id = ?i AND lang_code = ?s", $_REQUEST['usergroup_id'], DESCR_SL);
    fn_add_breadcrumb(fn_get_lang_var('usergroups'), "usergroups.manage");
    $usergroup_privileges = db_get_hash_single_array("SELECT privilege FROM ?:usergroup_privileges WHERE usergroup_id = ?i", array('privilege', 'privilege'), $_REQUEST['usergroup_id']);
    $view->assign('usergroup_privileges', $usergroup_privileges);
    $view->assign('usergroup_name', $usergroup_name);
    $view->assign('privileges', db_get_hash_multi_array("SELECT a.*, b.*, c.description as section FROM ?:privileges as a LEFT JOIN ?:privilege_descriptions as b ON b.privilege = a.privilege AND b.lang_code = ?s INNER JOIN ?:privilege_section_descriptions as c on c.section_id = b.section_id AND c.lang_code = ?s ORDER BY b.section_id, b.description", array('section_id'), CART_LANGUAGE, CART_LANGUAGE));
} elseif ($mode == 'privileges') {
    fn_add_breadcrumb(fn_get_lang_var('usergroups'), "usergroups.manage");
    $privileges = db_get_hash_multi_array("SELECT a.*, b.*, c.description as section FROM ?:privileges as a LEFT JOIN ?:privilege_descriptions as b ON b.privilege = a.privilege AND b.lang_code = ?s INNER JOIN ?:privilege_section_descriptions as c on c.section_id = b.section_id AND c.lang_code = ?s ORDER BY b.section_id, b.description", array('section_id'), DESCR_SL, DESCR_SL);
    $view->assign('privileges', $privileges);
} elseif ($mode == 'manage') {
    $where = defined('RESTRICTED_ADMIN') ? "a.type!='A' " : '1';
    $usergroups = db_get_array("SELECT a.usergroup_id, a.status, a.type, b.usergroup FROM ?:usergroups as a LEFT JOIN ?:usergroup_descriptions as b ON b.usergroup_id = a.usergroup_id AND b.lang_code = ?s WHERE {$where} ORDER BY usergroup", DESCR_SL);
    $view->assign('usergroups', $usergroups);
    Registry::set('navigation.tabs', array('general_0' => array('title' => fn_get_lang_var('general'), 'js' => true)));
} elseif ($mode == 'update') {
    $usergroup = db_get_row("SELECT a.usergroup_id, a.status, a.type, b.usergroup FROM ?:usergroups as a LEFT JOIN ?:usergroup_descriptions as b ON b.usergroup_id = a.usergroup_id AND b.lang_code = ?s WHERE a.usergroup_id = ?i", DESCR_SL, $_REQUEST['usergroup_id']);
    $view->assign('usergroup', $usergroup);
    Registry::set('navigation.tabs', array('general_' . $_REQUEST['usergroup_id'] => array('title' => fn_get_lang_var('general'), 'js' => true)));
} elseif ($mode == 'delete') {
    if (!empty($_REQUEST['usergroup_id'])) {
        fn_delete_usergroups((array) $_REQUEST['usergroup_id']);
    }
    return array(CONTROLLER_STATUS_REDIRECT, "usergroups.manage");
Esempio n. 23
0
 if ($mode == 'update') {
     if ($template_id = fn_update_ebay_template($_REQUEST['template_data'], $_REQUEST['template_id'])) {
         return array(CONTROLLER_STATUS_OK, 'ebay.update?template_id=' . $template_id);
     } else {
         fn_save_post_data('template_data');
         fn_delete_notification('changes_saved');
     }
     return array(CONTROLLER_STATUS_OK, 'ebay.add');
 }
 if ($mode == 'm_delete') {
     foreach ($_REQUEST['template_ids'] as $template_id) {
         fn_delete_ebay_template($template_id);
     }
 }
 if ($mode == 'export') {
     $products_data = db_get_hash_multi_array("SELECT product_id,company_id,ebay_template_id FROM ?:products WHERE product_id IN (?n)", array('company_id', 'product_id'), $_REQUEST['product_ids']);
     $template_ids = array();
     if (!empty($products_data)) {
         foreach ($products_data as $company_id => $products) {
             foreach ($products as $product_id => $product) {
                 if (!empty($product['ebay_template_id'])) {
                     $template_ids[$product['ebay_template_id']][] = $product_id;
                 } else {
                     $default_template_id = db_get_field("SELECT template_id FROM ?:ebay_templates WHERE use_as_default = 'Y' AND company_id = ?i", $company_id);
                     if (!empty($default_template_id)) {
                         $template_ids[$default_template_id][] = $product_id;
                     } else {
                         $company_name = fn_get_company_name($company_id);
                         fn_set_notification('E', __('error'), __('ebay_default_template_not_found', array('[company_name]' => $company_name)));
                     }
                 }
Esempio n. 24
0
function fn_get_profile_fields($location = 'C', $_auth = array(), $lang_code = CART_LANGUAGE, $params = array())
{
    $auth =& $_SESSION['auth'];
    $select = '';
    if (empty($_auth)) {
        $_auth = $auth;
    }
    if (!empty($params['get_custom'])) {
        $condition = "WHERE ?:profile_fields.is_default = 'N' ";
    } else {
        $condition = "WHERE 1 ";
    }
    if (!empty($params['get_profile_required'])) {
        $condition .= "AND ?:profile_fields.profile_required = 'Y' ";
    }
    if (!empty($params['get_checkout_required'])) {
        $condition .= "AND ?:profile_fields.checkout_required = 'Y' ";
    }
    fn_set_hook('change_location', $location, $select, $condition, $params);
    if ($location == 'A' || $location == 'V' || $location == 'C') {
        $select .= ", ?:profile_fields.profile_required as required";
        $condition .= " AND ?:profile_fields.profile_show = 'Y'";
    } elseif ($location == 'O' || $location == 'I') {
        $select .= ", ?:profile_fields.checkout_required as required";
        $condition .= " AND ?:profile_fields.checkout_show = 'Y'";
    }
    if (!empty($params['field_id'])) {
        $condition .= db_quote(' AND ?:profile_fields.field_id = ?i', $params['field_id']);
    }
    fn_set_hook('get_profile_fields', $location, $select, $condition);
    // Determine whether to retrieve or not email field
    $skip_email_field = false;
    if ($location != 'I') {
        if ($location == 'O' && Registry::get('settings.Checkout.disable_anonymous_checkout') == 'Y' && empty($_auth['user_id'])) {
            $skip_email_field = true;
        } elseif (strpos('APVC', $location) !== false) {
            $skip_email_field = true;
        }
    }
    if ($skip_email_field) {
        $condition .= " AND ?:profile_fields.field_type != 'E'";
    }
    $profile_fields = db_get_hash_multi_array("SELECT ?:profile_fields.*, ?:profile_field_descriptions.description {$select} FROM ?:profile_fields LEFT JOIN ?:profile_field_descriptions ON ?:profile_field_descriptions.object_id = ?:profile_fields.field_id AND ?:profile_field_descriptions.object_type = 'F' AND lang_code = ?s {$condition} ORDER BY ?:profile_fields.position", array('section', 'field_id'), $lang_code);
    $matches = array();
    // Collect matching IDs
    if (!empty($profile_fields['S'])) {
        foreach ($profile_fields['S'] as $v) {
            $matches[$v['matching_id']] = $v['field_id'];
        }
    }
    $profile_fields['E'][] = array('section' => 'E', 'field_type' => 'I', 'field_name' => 'email', 'description' => __('email'), 'required' => 'Y');
    foreach ($profile_fields as $section => $fields) {
        foreach ($fields as $k => $v) {
            if ($v['field_type'] == 'S' || $v['field_type'] == 'R') {
                $_id = $v['field_id'];
                if ($section == 'B' && empty($v['field_name'])) {
                    // If this field is enabled in billing section
                    if (!empty($matches[$v['field_id']])) {
                        $_id = $matches[$v['field_id']];
                        // Otherwise, get it from database
                    } else {
                        $_id = db_get_field("SELECT field_id FROM ?:profile_fields WHERE matching_id = ?i", $v['field_id']);
                    }
                }
                $profile_fields[$section][$k]['values'] = db_get_hash_single_array("SELECT ?:profile_field_values.value_id, ?:profile_field_descriptions.description FROM ?:profile_field_values LEFT JOIN ?:profile_field_descriptions ON ?:profile_field_descriptions.object_id = ?:profile_field_values.value_id AND ?:profile_field_descriptions.object_type = 'V' AND ?:profile_field_descriptions.lang_code = ?s WHERE ?:profile_field_values.field_id = ?i ORDER BY ?:profile_field_values.position", array('value_id', 'description'), $lang_code, $_id);
            }
        }
    }
    if (!empty($params['field_id'])) {
        $result = reset($profile_fields);
        if (!empty($result[$params['field_id']])) {
            return $result[$params['field_id']];
        } else {
            return array();
        }
    }
    $sections = array('C' => true, 'B' => true, 'S' => true, 'E' => true);
    $sections = array_intersect_key($sections, $profile_fields);
    $profile_fields = array_merge($sections, $profile_fields);
    return $profile_fields;
}
Esempio n. 25
0
/**
 * Gets all states
 *
 * @param bool $avail_only if set to true - gets only enabled states
 * @param string $lang_code language code
 * @return array multi key-value array with country code as key and array with state code and name as value
 */
function fn_get_all_states($avail_only = true, $lang_code = CART_LANGUAGE)
{
    $avail_cond = $avail_only == true ? " WHERE a.status = 'A' " : '';
    return db_get_hash_multi_array("SELECT a.country_code, a.code, b.state FROM ?:states as a LEFT JOIN ?:state_descriptions as b ON b.state_id = a.state_id AND b.lang_code = ?s {$avail_cond} ORDER BY a.country_code, b.state", array('country_code'), $lang_code);
}
Esempio n. 26
0
function fn_twg_get_searches($auth)
{
    $query = "SELECT view_id, object, name FROM ?:views WHERE object IN ('orders', 'products', 'users') AND user_id = ?i";
    $objects = db_get_hash_multi_array($query, array('object', 'view_id'), $auth['user_id']);
    // orders
    if (!isset($objects['orders'])) {
        $objects['orders'] = array();
    }
    array_unshift($objects['orders'], array('name' => fn_twg_get_lang_var('all')));
    // products
    if (!isset($objects['products'])) {
        $objects['products'] = array();
    }
    array_unshift($objects['products'], array('name' => fn_twg_get_lang_var('all')));
    array_push($objects['products'], array('name' => fn_twg_get_lang_var('twapp_low_stock'), 'view_id' => -1));
    // users
    if (!isset($objects['users'])) {
        $objects['users'] = array();
    }
    array_unshift($objects['users'], array('name' => fn_twg_get_lang_var('all')));
    return $objects;
}
Esempio n. 27
0
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';
    }
}
 $today_end = strtotime("23:59");
 $period_start = $today_start - intval($days_amount) * 24 * 60 * 60;
 $period_end = $today_end - intval($days_amount) * 24 * 60 * 60;
 $_products_list = array();
 if (!empty($recipient_data['anonim']) && $recipient_data['anonim'] == 'Y') {
     if ($recipient_data['timestamp'] < $period_start || $recipient_data['timestamp'] > $period_end) {
         continue;
     } else {
         foreach ($recipient_data['cart_products'] as $product) {
             $_products_list[$product['company_id']][] = $product;
         }
         $user_data = $recipient_data['user_data'];
     }
 } else {
     $cond .= db_quote(" AND timestamp >= ?i AND timestamp <= ?i", $period_start, $period_end);
     $user_products = db_get_hash_multi_array('SELECT * FROM ?:user_session_products WHERE user_id=?i AND user_type=?s AND type=?s ?p', array('company_id', 'item_id'), $recipient_data['user_id'], 'R', 'C', $cond);
     $user_data = db_get_row('SELECT * FROM ?:users WHERE user_id=?i', $recipient_data['user_id']);
     foreach ($user_products as $company_id => $_products) {
         foreach ($_products as $product) {
             $_products_list[$company_id][] = unserialize($product['extra']);
         }
     }
 }
 if (empty($_products_list)) {
     continue;
 }
 if (empty($user_data['email'])) {
     continue;
 }
 foreach ($_products_list as $company_id => $products) {
     $url_params = array();
Esempio n. 29
0
function fn_get_return_info($return_id)
{
    if (!empty($return_id)) {
        $return = db_get_row("SELECT * FROM ?:rma_returns WHERE return_id = ?i", $return_id);
        if (empty($return)) {
            return array();
        }
        $return['items'] = db_get_hash_multi_array("SELECT ?:rma_return_products.*, ?:products.product_id as original_product_id FROM ?:rma_return_products LEFT JOIN ?:products ON ?:rma_return_products.product_id = ?:products.product_id WHERE ?:rma_return_products.return_id = ?i", array('type', 'item_id'), $return_id);
        foreach ($return['items'] as $type => $value) {
            foreach ($value as $k => $v) {
                if (0 == floatval($v['price'])) {
                    $return['items'][$type][$k]['price'] = '';
                }
                if (empty($v['original_product_id'])) {
                    $return['items'][$type][$k]['deleted_product'] = true;
                }
                if (empty($v['product'])) {
                    $v['product'] = strtoupper(__('deleted_product'));
                }
                $return['items'][$type][$k]['product_options'] = !empty($return['items'][$type][$k]['product_options']) ? unserialize($return['items'][$type][$k]['product_options']) : array();
            }
        }
        return $return;
    }
    return false;
}
Esempio n. 30
0
 /**
  * Gets list of blocks
  * <i>$dynamic_object</i> must be array in this format
  * <pre>array (
  *   object_ids - dynamic object id
  *   object_type - dynamic object type from dynamic_objects scheme
  * )</pre>
  *
  * @param  array  $fields         array of table column names to be returned
  * @param  array  $grids_ids      Identifiers of grids containing the needed blocks
  * @param  array  $dynamic_object Dynamic object data
  * @param  string $join           Query join; it is treated as a JOIN clause
  * @param  string $condition      Query condition; it is treated as a WHERE clause
  * @param  string $lang_code      2 letter language code
  * @return array  Array of blocks as grid_id => array(block_id => block data)
  */
 public function getList($fields, $grids_ids, $dynamic_object = array(), $join = '', $condition = '', $lang_code = CART_LANGUAGE)
 {
     /**
      * Prepares params for SQL query before getting blocks
      * @param array $fields Array of table column names to be returned
      * @param array $grids_ids Identifiers of grids containing the needed blocks
      * @param array $dynamic_object Dynamic object data
      * @param string $join Query join; it is treated as a JOIN clause
      * @param string $condition Query condition; it is treated as a WHERE clause
      * @param string $lang_code 2 letter language code
      */
     fn_set_hook('get_blocks_pre', $fields, $grids_ids, $dynamic_object, $join, $condition, $lang_code);
     $_fields = array("?:bm_snapping.grid_id as grid_id", "?:bm_snapping.block_id as block_id", "IFNULL(dynamic_object_content.content, default_content.content) as content", "IFNULL(dynamic_object_content.object_id, default_content.object_id) AS object_id", "IFNULL(dynamic_object_content.object_type, default_content.object_type) AS object_type", "?:bm_block_statuses.object_ids as object_ids");
     $_fields = array_merge($_fields, $fields);
     $condition .= $this->getCompanyCondition('?:bm_blocks.company_id');
     $blocks = db_get_hash_multi_array("SELECT ?p " . "FROM ?:bm_snapping " . "LEFT JOIN ?:bm_blocks " . "ON ?:bm_blocks.block_id = ?:bm_snapping.block_id " . "LEFT JOIN ?:bm_block_statuses " . "ON ?:bm_snapping.snapping_id = ?:bm_block_statuses.snapping_id " . "AND ?:bm_block_statuses.object_type LIKE ?s " . "LEFT JOIN ?:bm_blocks_descriptions " . "ON ?:bm_blocks.block_id = ?:bm_blocks_descriptions.block_id ?p " . "LEFT JOIN ?:bm_blocks_content AS default_content " . "ON ?:bm_blocks.block_id = default_content.block_id " . "AND ?:bm_blocks_descriptions.lang_code = default_content.lang_code " . "AND default_content.snapping_id = 0 " . "AND default_content.object_id = 0 " . "AND default_content.object_type like '' " . "LEFT JOIN ?:bm_blocks_content AS dynamic_object_content " . "ON ?:bm_blocks.block_id = dynamic_object_content.block_id " . "AND ?:bm_blocks_descriptions.lang_code = dynamic_object_content.lang_code " . "AND dynamic_object_content.object_id = ?i " . "AND dynamic_object_content.object_type like ?s " . "WHERE ?:bm_snapping.grid_id IN (?n)  " . "AND ?:bm_blocks_descriptions.lang_code=?s ?p " . "ORDER BY ?:bm_snapping.order, ?:bm_snapping.block_id ", array('grid_id', 'block_id'), implode(',', $_fields), !empty($dynamic_object['object_type']) ? $dynamic_object['object_type'] : '', $join, !empty($dynamic_object['object_id']) ? $dynamic_object['object_id'] : 0, !empty($dynamic_object['object_type']) ? $dynamic_object['object_type'] : '', $grids_ids, $lang_code, $condition);
     foreach ($blocks as $grid_id => $blocks_list) {
         foreach ($blocks_list as $block_id => $block) {
             if (!empty($block['properties'])) {
                 $blocks[$grid_id][$block_id]['properties'] = unserialize($block['properties']);
             }
             if (!empty($block['content'])) {
                 $blocks[$grid_id][$block_id]['content'] = unserialize($block['content']);
             }
             if (!empty($block['object_ids'])) {
                 $blocks[$grid_id][$block_id]['items_array'] = explode(',', $block['object_ids']);
             } else {
                 $blocks[$grid_id][$block_id]['items_array'] = array();
             }
             $blocks[$grid_id][$block_id]['items_count'] = count($blocks[$grid_id][$block_id]['items_array']);
             if (!isset($blocks[$grid_id][$block_id]['object_id'], $blocks[$grid_id][$block_id]['object_type'])) {
                 $blocks[$grid_id][$block_id]['object_id'] = !empty($dynamic_object['object_id']) ? $dynamic_object['object_id'] : 0;
                 $blocks[$grid_id][$block_id]['object_type'] = !empty($dynamic_object['object_type']) ? $dynamic_object['object_type'] : '';
             }
         }
     }
     /**
      * Processes blocks list after getting it
      * @param array $blocks List of blocks data
      * @param array $grids_ids Identifiers of grids containing the needed blocks
      * @param array $dynamic_object Dynamic object data
      * @param string $join Query join; it is treated as a JOIN clause
      * @param string $condition Query condition; it is treated as a WHERE clause
      * @param string $lang_code 2 letter language code
      */
     fn_set_hook('get_blocks_post', $blocks, $grids_ids, $dynamic_object, $lang_code);
     return $blocks;
 }