/**
 * 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 array_sort_by_fields(&$data, $sortby)
{
    static $sort_funcs = array();
    if (empty($sort_funcs[$sortby])) {
        $code = "\$c=0;";
        foreach (fn_explode(',', $sortby) as $key) {
            $d = '1';
            if (substr($key, 0, 1) == '-') {
                $d = '-1';
                $key = substr($key, 1);
            }
            if (substr($key, 0, 1) == '#') {
                $key = substr($key, 1);
                $code .= "if ( \$a['{$key}'] > \$b['{$key}']) return {$d} * 1;\n";
                $code .= "if ( \$a['{$key}'] < \$b['{$key}']) return {$d} * -1;\n";
            } else {
                $code .= "if ( (\$c = strcasecmp(\$a['{$key}'],\$b['{$key}'])) != 0 ) return {$d} * \$c;\n";
            }
        }
        $code .= 'return $c;';
        $sort_func = $sort_funcs[$sortby] = create_function('$a, $b', $code);
    } else {
        $sort_func = $sort_funcs[$sortby];
    }
    uasort($data, $sort_func);
}
Beispiel #3
0
 public function create($params)
 {
     $data = array();
     $valid_params = true;
     $status = Response::STATUS_BAD_REQUEST;
     unset($params['product_id']);
     if (empty($params['category_ids'])) {
         $data['message'] = __('api_required_field', array('[field]' => 'category_ids'));
         $valid_params = false;
     }
     if (!isset($params['price'])) {
         $data['message'] = __('api_required_field', array('[field]' => 'price'));
         $valid_params = false;
     }
     if ($valid_params) {
         if (!is_array($params['category_ids'])) {
             $params['category_ids'] = fn_explode(',', $params['category_ids']);
         }
         $this->prepareFeature($params);
         $this->prepareImages($params);
         $product_id = fn_update_product($params);
         if ($product_id) {
             $status = Response::STATUS_CREATED;
             $data = array('product_id' => $product_id);
         }
     }
     return array('status' => $status, 'data' => $data);
 }
Beispiel #4
0
function fn_get_newsletters($params = array(), $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    $default_params = array('type' => NEWSLETTER_TYPE_NEWSLETTER, 'only_available' => true, 'page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $_conditions = array();
    if ($params['only_available']) {
        $_conditions[] = "?:newsletters.status = 'A'";
    }
    if ($params['type']) {
        $_conditions[] = db_quote("?:newsletters.type = ?s", $params['type']);
    }
    if (!empty($_conditions)) {
        $_conditions = implode(' AND ', $_conditions);
    } else {
        $_conditions = '1';
    }
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:newsletters WHERE ?p", $_conditions);
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $newsletters = db_get_array("SELECT ?:newsletters.newsletter_id, ?:newsletters.status, ?:newsletters.sent_date, " . "?:newsletters.status, ?:newsletters.mailing_lists, ?:newsletter_descriptions.newsletter FROM ?:newsletters " . "LEFT JOIN ?:newsletter_descriptions ON ?:newsletter_descriptions.newsletter_id=?:newsletters.newsletter_id " . "AND ?:newsletter_descriptions.lang_code= ?s " . "WHERE ?p ORDER BY ?:newsletters.sent_date DESC, ?:newsletters.status {$limit}", $lang_code, $_conditions);
    foreach ($newsletters as $id => $data) {
        $newsletters[$id]['mailing_lists'] = !empty($data['mailing_lists']) ? fn_explode(',', $data['mailing_lists']) : array();
    }
    return array($newsletters, $params);
}
Beispiel #5
0
/**
 * Form top menu
 *
 * @param array $top_menu Top menu data from the database
 * @param int $level Current menu level
 * @param boolean $active Menu item active flag, returned by reference to set tree branch as active
 *
 * @return array Formed top menu
 */
function fn_top_menu_form($top_menu, $level = 0, &$active = NULL)
{
    /**
     * Modifies top menu forming parameters
     *
     * @param array $top_menu Top menu data from the database
     * @param int $level Current menu level
     * @param boolean $active Menu item active flag
     */
    fn_set_hook('top_menu_form_pre', $top_menu, $level, $active);
    $_active = false;
    foreach ($top_menu as $k => $v) {
        if (!empty($v['param_3'])) {
            // get extra items
            list($type, $id, $use_name) = fn_explode(':', $v['param_3']);
            if ($type == 'C') {
                // categories
                $cats = fn_get_categories_tree($id, true);
                $v['subitems'] = fn_array_merge(fn_top_menu_standardize($cats, 'category_id', 'category', 'subcategories', 'categories.view?category_id='), !empty($v['subitems']) ? $v['subitems'] : array(), false);
                if ($use_name == 'Y' && !empty($id)) {
                    $v['descr'] = fn_get_category_name($id);
                    $v['param'] = 'categories.view?category_id=' . $id;
                }
                //Should add this checking because the same pages can have different request parameters and the next checking
                //with fn_top_menu_is_current_url function could return incorrect result.
                //For example: categories.view?category_id=165 and categories.view?category_id=165&currency=EUR should have the same active elements.
                if (fn_check_is_active_menu_item(array('category_id' => $id), 'categories')) {
                    $top_menu[$k]['active'] = true;
                }
            } elseif ($type == 'A') {
                // pages
                $params = array('from_page_id' => $id, 'get_tree' => 'multi_level', 'status' => 'A');
                list($pages) = fn_get_pages($params);
                $v['subitems'] = fn_array_merge(fn_top_menu_standardize($pages, 'page_id', 'page', 'subpages', 'pages.view?page_id='), !empty($v['subitems']) ? $v['subitems'] : array(), false);
                if ($use_name == 'Y' && !empty($id)) {
                    $page_data = fn_get_page_data($id);
                    $v['descr'] = $page_data['page'];
                    $v['param'] = !empty($page_data['link']) ? $page_data['link'] : 'pages.view?page_id=' . $id;
                }
                if (fn_check_is_active_menu_item(array('page_id' => $id), 'pages')) {
                    $top_menu[$k]['active'] = true;
                }
            } else {
                // for addons
                /**
                 * Deprecated since 4.3.6, use top_menu_form_post instead
                 */
                fn_set_hook('top_menu_form', $v, $type, $id, $use_name);
            }
        }
        if (!empty($v['param']) && fn_top_menu_is_current_url($v['param'], $v['param_2'])) {
            $top_menu[$k]['active'] = true;
            // Store active value
            $_active = true;
        }
        if (!empty($v['subitems'])) {
            $top_menu[$k]['subitems'] = fn_top_menu_form($v['subitems'], $level + 1, $active);
            // If active status was returned fron children
            if ($active) {
                $top_menu[$k]['active'] = $active;
                // Strore fo return and reset activity status for athother elements on this level
                // Because in one level may be only one active item
                $_active = true;
                $active = false;
            }
        }
        $top_menu[$k]['item'] = $v['descr'];
        $top_menu[$k]['href'] = $v['param'];
        $top_menu[$k]['level'] = $level;
        unset($top_menu[$k]['descr'], $top_menu[$k]['param']);
    }
    $active = $_active;
    /**
     * Modifies top menu items
     *
     * @param array $top_menu Top menu data from the database
     * @param int $level Current menu level
     * @param boolean $active Menu item active flag
     */
    fn_set_hook('top_menu_form_post', $top_menu, $level, $active);
    return $top_menu;
}
Beispiel #6
0
list($cml, $s_commerceml) = RusEximCommerceml::getParamsCommerceml();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $suffix = '';
    if ($mode == 'save_offers_data') {
        if ($s_commerceml['exim_1c_create_prices'] == 'Y') {
            $prices = $_REQUEST['prices_1c'];
            if (!empty($_REQUEST['list_price_1c'])) {
                $_list_prices = fn_explode(',', $_REQUEST['list_price_1c']);
                $list_prices = array();
                foreach ($_list_prices as $_list_price) {
                    $list_prices[] = array('price_1c' => trim($_list_price), 'usergroup_id' => 0, 'type' => 'list');
                }
                $prices = fn_array_merge($list_prices, $prices, false);
            }
            if (!empty($_REQUEST['base_price_1c'])) {
                $_base_prices = fn_explode(',', $_REQUEST['base_price_1c']);
                $base_prices = array();
                foreach ($_base_prices as $_base_price) {
                    $base_prices[] = array('price_1c' => trim($_base_price), 'usergroup_id' => 0, 'type' => 'base');
                }
                $prices = fn_array_merge($base_prices, $prices, false);
                db_query("DELETE FROM ?:rus_exim_1c_prices");
                foreach ($prices as $price) {
                    if (!empty($price['price_1c'])) {
                        db_query("INSERT INTO ?:rus_exim_1c_prices ?e", $price);
                    }
                }
            } else {
                fn_set_notification('W', __('warning'), __('base_price_empty'));
            }
        }
Beispiel #7
0
/**
 * Select active tab in top menu
 *
 * @param array $top_menu top menu data from the database
 * @param string $controller current controller
 * @param string $mode current mode
 * @param string $current_url current URL
 * @param mixed $child_key key of selected child
 * @return array formed top menu
 */
function fn_top_menu_select($top_menu, $controller, $mode, $current_url, &$child_key = NULL)
{
    $selected_key = NULL;
    foreach ($top_menu as $k => $v) {
        if (!empty($v['param_2'])) {
            // get currently selected item
            $d = fn_explode(',', $v['param_2']);
            foreach ($d as $p) {
                if (strpos($p, '.') !== false) {
                    list($c, $m) = fn_explode('.', $p);
                } else {
                    $c = $p;
                    $m = '';
                }
                if ($controller == $c && (empty($m) || $m == $mode)) {
                    $selected_key = $k;
                }
            }
        } elseif (!empty($v['href'])) {
            // if url is not empty, get selected tab by it
            parse_str(substr($v['href'], strpos($v['href'], '?') + 1), $a);
            $equal = true;
            foreach ($a as $_k => $_v) {
                if (!isset($_REQUEST[$_k]) || $_REQUEST[$_k] != $_v) {
                    $equal = false;
                    break;
                }
            }
            if ($equal == true) {
                $selected_key = $k;
            }
        }
        if ($selected_key === NULL && !empty($v['subitems'])) {
            $c_key = NULL;
            $top_menu[$k]['subitems'] = fn_top_menu_select($v['subitems'], $controller, $mode, $current_url, $c_key);
            if ($c_key !== NULL) {
                $selected_key = $k;
            }
        }
        if ($selected_key !== NULL) {
            $top_menu[$selected_key]['selected'] = true;
            $child_key = true;
            break;
        }
    }
    return $top_menu;
}
function fn_import_feature($data, &$processed_data, &$skip_record)
{
    static $new_groups = array();
    $skip_record = true;
    $feature = reset($data);
    $langs = array_keys($data);
    $main_lang = reset($langs);
    if (Registry::get('runtime.company_id')) {
        $company_id = Registry::get('runtime.company_id');
    } else {
        if (!empty($feature['company'])) {
            $company_id = fn_get_company_id_by_name($feature['company']);
        } else {
            $company_id = isset($feature['company_id']) ? $feature['company_id'] : Registry::get('runtime.company_id');
        }
    }
    if (!empty($feature['feature_id'])) {
        $feature_id = db_get_field('SELECT ?:product_features.feature_id FROM ?:product_features WHERE feature_id = ?i', $feature['feature_id']);
    }
    $parent_id = fn_exim_get_product_feature_group_id($feature['parent_id'], $company_id, $new_groups, $main_lang);
    if (empty($feature_id)) {
        $condition = db_quote("WHERE description = ?s AND lang_code = ?s AND feature_type = ?s", $feature['description'], $main_lang, $feature['feature_type']);
        $condition .= db_quote(" AND parent_id = ?i", $parent_id);
        $feature_id = db_get_field('SELECT ?:product_features.feature_id FROM ?:product_features_descriptions ' . 'LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_features_descriptions.feature_id ' . $condition);
    }
    unset($feature['feature_id']);
    $feature['company_id'] = $company_id;
    $feature['parent_id'] = $parent_id;
    $feature['variants'] = array();
    if (!empty($feature['Variants'])) {
        $variants = fn_explode(',', $feature['Variants']);
        list($origin_variants) = fn_get_product_feature_variants(array('feature_id' => $feature_id), 0, $main_lang);
        $feature['original_var_ids'] = implode(',', array_keys($origin_variants));
        foreach ($variants as $variant) {
            $feature['variants'][]['variant'] = $variant;
        }
    }
    $skip = false;
    if (empty($feature_id)) {
        $feature_id = fn_update_product_feature($feature, 0, $main_lang);
        $processed_data['N']++;
        fn_set_progress('echo', __('updating') . ' features <b>' . $feature_id . '</b>. ', false);
    } else {
        if (!fn_check_company_id('product_features', 'feature_id', $feature_id)) {
            $processed_data['S']++;
            $skip = true;
        } else {
            fn_update_product_feature($feature, $feature_id, $main_lang);
            if (in_array($feature_id, $new_groups)) {
                $processed_data['N']++;
            } else {
                $processed_data['E']++;
                fn_set_progress('echo', __('creating') . ' features <b>' . $feature_id . '</b>. ', false);
            }
        }
    }
    if (!$skip) {
        fn_exim_set_product_feature_categories($feature_id, $feature, $main_lang);
        foreach ($data as $lang_code => $feature_data) {
            unset($feature_data['feature_id']);
            db_query('UPDATE ?:product_features_descriptions SET ?u WHERE feature_id = ?i AND lang_code = ?s', $feature_data, $feature_id, $lang_code);
        }
        if (fn_allowed_for('ULTIMATE')) {
            if (!empty($company_id)) {
                fn_exim_update_share_feature($feature_id, $company_id);
            }
        }
    }
    return $feature_id;
}
Beispiel #9
0
         }
     }
     $navigation['static'][$root][(string) $it['title']] = array('href' => (string) $it['dispatch'] . (!empty($it['extra']) ? '?' . (string) $it['extra'] : ''), 'position' => isset($it['links_group']) ? $groups[(string) $it['links_group']] : $is[$root]);
     // 1st way
     if ($_dispatch == (string) $it['dispatch']) {
         if (empty($it['extra']) || strpos(Registry::get('config.current_url'), (string) $it['extra']) !== false) {
             $navigation['selected_tab'] = $root;
             $navigation['subsection'] = (string) $it['title'];
             $tab_selected = true;
         }
     }
     // 1st A way
     if (!empty($it['alt'])) {
         $alt = fn_explode(',', (string) $it['alt']);
         foreach ($alt as $v) {
             @(list($_d, $_m) = fn_explode('.', $v));
             if ((!empty($_m) && MODE == $_m || empty($_m)) && CONTROLLER == $_d) {
                 $navigation['selected_tab'] = $root;
                 $navigation['subsection'] = (string) $it['title'];
                 $tab_selected = true;
                 break;
             }
         }
     }
     // 2nd way
     if (empty($tab_selected) && strpos((string) $it['dispatch'], CONTROLLER . (strpos((string) $it['dispatch'], '.') ? '.' : '')) === 0) {
         $navigation['selected_tab'] = $root;
         $navigation['subsection'] = (string) $it['title'];
         $tab_selected = true;
     }
 }
Beispiel #10
0
         $_SESSION['current_category_id'] = $product['main_category'];
     }
 }
 if (!empty($product['meta_description']) || !empty($product['meta_keywords'])) {
     Registry::get('view')->assign('meta_description', $product['meta_description']);
     Registry::get('view')->assign('meta_keywords', $product['meta_keywords']);
 } else {
     $meta_tags = db_get_row("SELECT meta_description, meta_keywords FROM ?:category_descriptions WHERE category_id = ?i AND lang_code = ?s", $_SESSION['current_category_id'], CART_LANGUAGE);
     if (!empty($meta_tags)) {
         Registry::get('view')->assign('meta_description', $meta_tags['meta_description']);
         Registry::get('view')->assign('meta_keywords', $meta_tags['meta_keywords']);
     }
 }
 if (!empty($_SESSION['current_category_id'])) {
     $_SESSION['continue_url'] = "categories.view?category_id={$_SESSION['current_category_id']}";
     $parent_ids = fn_explode('/', db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $_SESSION['current_category_id']));
     if (!empty($parent_ids)) {
         Registry::set('runtime.active_category_ids', $parent_ids);
         $cats = fn_get_category_name($parent_ids);
         foreach ($parent_ids as $c_id) {
             fn_add_breadcrumb($cats[$c_id], "categories.view?category_id={$c_id}");
         }
     }
 }
 fn_add_breadcrumb($product['product']);
 if (!empty($_REQUEST['combination'])) {
     $product['combination'] = $_REQUEST['combination'];
 }
 //wishlist options selected
 $wishlistOptionsVariantsSelected = array();
 if (isset($_REQUEST['wishlist_id'])) {
Beispiel #11
0
/**
 * Form top menu
 *
 * @param array $top_menu top menu data from the database
 * @param int $level current menu level
 * @param boolean $active - menu item active flag, returned by reference to set tree branch as active
 * @return array formed top menu
 */
function fn_top_menu_form($top_menu, $level = 0, &$active = NULL)
{
    $_active = false;
    foreach ($top_menu as $k => $v) {
        if (!empty($v['param_3'])) {
            // get extra items
            list($type, $id, $use_name) = fn_explode(':', $v['param_3']);
            if ($type == 'C') {
                // categories
                $cats = fn_get_categories_tree($id, true);
                $v['subitems'] = fn_array_merge(fn_top_menu_standardize($cats, 'category_id', 'category', 'subcategories', 'categories.view?category_id='), !empty($v['subitems']) ? $v['subitems'] : array(), false);
                if ($use_name == 'Y' && !empty($id)) {
                    $v['descr'] = fn_get_category_name($id);
                    $v['param'] = 'categories.view?category_id=' . $id;
                }
            } elseif ($type == 'A') {
                // pages
                $params = array('from_page_id' => $id, 'get_tree' => 'multi_level', 'status' => 'A');
                list($pages) = fn_get_pages($params);
                $v['subitems'] = fn_array_merge(fn_top_menu_standardize($pages, 'page_id', 'page', 'subpages', 'pages.view?page_id='), !empty($v['subitems']) ? $v['subitems'] : array(), false);
                if ($use_name == 'Y' && !empty($id)) {
                    $page_data = fn_get_page_data($id);
                    $v['descr'] = $page_data['page'];
                    $v['param'] = !empty($page_data['link']) ? $page_data['link'] : 'pages.view?page_id=' . $id;
                }
            } else {
                // for addons
                fn_set_hook('top_menu_form', $v, $type, $id, $use_name);
            }
        }
        if (!empty($v['param']) && fn_top_menu_is_current_url($v['param'], $v['param_2'])) {
            $top_menu[$k]['active'] = true;
            // Store active value
            $_active = true;
        }
        if (!empty($v['subitems'])) {
            $top_menu[$k]['subitems'] = fn_top_menu_form($v['subitems'], $level + 1, $active);
            // If active status was returned fron children
            if ($active) {
                $top_menu[$k]['active'] = $active;
                // Strore fo return and reset activity status for athother elements on this level
                // Because in one level may be only one active item
                $_active = true;
                $active = false;
            }
        }
        $top_menu[$k]['item'] = $v['descr'];
        $top_menu[$k]['href'] = $v['param'];
        $top_menu[$k]['level'] = $level;
        unset($top_menu[$k]['descr'], $top_menu[$k]['param']);
    }
    $active = $_active;
    return $top_menu;
}
Beispiel #12
0
     $newsletter_id = fn_update_newsletter($_REQUEST['newsletter_data'], $_REQUEST['newsletter_id'], DESCR_SL);
     return array(CONTROLLER_STATUS_OK, 'newsletters.update?newsletter_id=' . $newsletter_id);
 }
 //
 // Send newsletter
 //
 if ($mode == 'send') {
     $newsletter_id = fn_update_newsletter($_REQUEST['newsletter_data'], $_REQUEST['newsletter_id'], DESCR_SL);
     if (!empty($_REQUEST['newsletter_data']['mailing_lists']) || !empty($_REQUEST['newsletter_data']['users']) || !empty($_REQUEST['newsletter_data']['abandoned_days'])) {
         $list_recipients = array();
         if (!empty($_REQUEST['newsletter_data']['mailing_lists'])) {
             $list_recipients = db_get_array("SELECT * FROM ?:subscribers AS s LEFT JOIN ?:user_mailing_lists AS u ON s.subscriber_id=u.subscriber_id LEFT JOIN ?:mailing_lists AS m ON u.list_id = m.list_id WHERE u.list_id IN(?n) AND (u.confirmed='1' OR m.register_autoresponder = 0) GROUP BY s.subscriber_id", $_REQUEST['newsletter_data']['mailing_lists']);
         }
         $user_recipients = array();
         if (!empty($_REQUEST['newsletter_data']['users'])) {
             $users = fn_explode(',', $_REQUEST['newsletter_data']['users']);
             $user_recipients = db_get_array("SELECT user_id, email, lang_code FROM ?:users WHERE user_id IN (?n)", $users);
             foreach ($user_recipients as $k => $v) {
                 // populate user array with sensible defaults
                 $user_recipients[$k]['from_name'] = '';
                 $user_recipients[$k]['reply_to'] = '';
                 $user_recipients[$k]['users_list'] = 'Y';
             }
         }
         $abandoned_recipients = array();
         if (!empty($_REQUEST['newsletter_data']['abandoned_days'])) {
             $time = time() - intval($_REQUEST['newsletter_data']['abandoned_days']) * 24 * 60 * 60;
             // X days * 24 hours * 60 mins * 60 secs;
             $condition = db_quote("AND ?:user_session_products.timestamp <= ?i", $time);
             if ($_REQUEST['newsletter_data']['abandoned_type'] == 'cart') {
                 $condition .= db_quote(' AND ?:user_session_products.type = ?s', 'C');
 /**
  * Assign localizations to the product
  *
  * @param int $product_id Product ID
  * @param string $data - comma delimited list of localizations
  * @return boolean always true
  */
 function fn_exim_set_localizations($product_id, $data)
 {
     if (empty($data)) {
         db_query("UPDATE ?:products SET localization = ''");
         return true;
     }
     $multi_lang = array_keys($data);
     $main_lang = reset($multi_lang);
     $loc_ids = db_get_fields("SELECT localization_id FROM ?:localization_descriptions WHERE localization IN (?a) AND lang_code = ?s", fn_explode(',', $data[$main_lang]), $main_lang);
     $_data = array('localization' => fn_create_set($loc_ids));
     db_query('UPDATE ?:products SET ?u WHERE product_id = ?i', $_data, $product_id);
     return true;
 }
Beispiel #14
0
function fn_checkout_update_shipping(&$cart, $shipping_ids)
{
    $cart['shipping'] = array();
    $parsed_data = array();
    foreach ($shipping_ids as $k => $shipping_id) {
        if (strpos($k, ',') !== false) {
            $parsed_data = fn_array_merge($parsed_data, fn_array_combine(fn_explode(',', $k), $shipping_id));
        } else {
            $parsed_data[$k] = $shipping_id;
        }
    }
    foreach ($parsed_data as $k => $shipping_id) {
        if (empty($cart['shipping'][$shipping_id])) {
            $cart['shipping'][$shipping_id] = array('shipping' => $_SESSION['shipping_rates'][$shipping_id]['name']);
        }
        if (!isset($cart['shipping'][$shipping_id]['rates'])) {
            $cart['shipping'][$shipping_id]['rates'] = array();
        }
        if (isset($_SESSION['shipping_rates'][$shipping_id]['rates'][$k])) {
            $cart['shipping'][$shipping_id]['rates'][$k] = $_SESSION['shipping_rates'][$shipping_id]['rates'][$k];
        }
    }
    return true;
}
 public static function importProductOffersFile($data_offers, $import_params)
 {
     $cml = self::$cml;
     $create_prices = self::$s_commerceml['exim_1c_create_prices'];
     $schema_version = self::$s_commerceml['exim_1c_schema_version'];
     $import_mode = self::$s_commerceml['exim_1c_import_mode_offers'];
     $negative_amount = Registry::get('settings.General.allow_negative_amount');
     if (isset($data_offers->{$cml}['prices_types']->{$cml}['price_type'])) {
         $price_offers = self::dataPriceOffers($data_offers->{$cml}['prices_types']->{$cml}['price_type']);
         if ($create_prices == 'Y') {
             $data_prices = db_get_array("SELECT price_1c, type, usergroup_id FROM ?:rus_exim_1c_prices");
             $prices_commerseml = self::dataPriceFile($data_offers->{$cml}['prices_types']->{$cml}['price_type'], $data_prices);
         }
     }
     $options_data = $global_options_data = array();
     foreach ($data_offers->{$cml}['offers']->{$cml}['offer'] as $offer) {
         $product = array();
         $amount = 0;
         $combination_id = 0;
         $ids = fn_explode('#', strval($offer->{$cml}['id']));
         $guid_product = array_shift($ids);
         if (!empty($ids)) {
             $combination_id = reset($ids);
         }
         $product_data = db_get_row("SELECT product_id, update_1c, status FROM ?:products WHERE external_id = ?s", $guid_product);
         $product_id = !empty($product_data['product_id']) ? $product_data['product_id'] : 0;
         $update_product = !empty($product_data['update_1c']) ? $product_data['update_1c'] : 'N';
         if (!self::checkImportPrices($product_data)) {
             continue;
         }
         if (isset($offer->{$cml}['amount']) && !empty($offer->{$cml}['amount'])) {
             $amount = strval($offer->{$cml}['amount']);
         } elseif (isset($offer->{$cml}['store'])) {
             foreach ($offer->{$cml}['store'] as $store) {
                 $amount += strval($store[$cml['in_stock']]);
             }
         }
         $prices = array();
         if (isset($offer->{$cml}['prices']) && !empty($price_offers)) {
             $product_prices = self::conversionProductPrices($offer->{$cml}['prices']->{$cml}['price'], $price_offers);
             if ($create_prices == 'Y') {
                 $prices = self::dataProductPrice($product_prices, $prices_commerseml);
             } elseif (!empty($product_prices[strval($offer->{$cml}['prices']->{$cml}['price']->{$cml}['price_id'])]['price'])) {
                 $prices['base_price'] = $product_prices[strval($offer->{$cml}['prices']->{$cml}['price']->{$cml}['price_id'])]['price'];
             } else {
                 $prices['base_price'] = 0;
             }
         }
         if (empty($prices)) {
             $prices['base_price'] = 0;
         }
         if ($amount < 0 && $negative_amount == 'N') {
             $amount = 0;
         }
         $o_amount = $amount;
         if (!empty($product_amount[$product_id])) {
             $o_amount = $o_amount + $product_amount[$product_id]['amount'];
         }
         $product_amount[$product_id]['amount'] = $o_amount;
         $product['status'] = self::updateProductStatus($product_id, $product_data['status'], $product_amount[$product_id]['amount']);
         if (empty($combination_id)) {
             $product['amount'] = $amount;
             db_query("UPDATE ?:products SET ?u WHERE product_id = ?i", $product, $product_id);
             self::addProductPrice($product_id, $prices);
             self::addMessageLog('Added product = ' . strval($offer->{$cml}['name']) . ', price = ' . $prices['base_price'] . ' and amount = ' . $amount);
         } else {
             $product['tracking'] = 'O';
             db_query("UPDATE ?:products SET ?u WHERE product_id = ?i", $product, $product_id);
             if ($schema_version == '2.07') {
                 self::addProductPrice($product_id, array('base_price' => 0));
                 $option_id = self::dataProductOption($product_id, $import_params['lang_code']);
                 $variant_id = db_get_field("SELECT variant_id FROM ?:product_option_variants WHERE external_id = ?s AND option_id = ?i", $combination_id, $option_id);
                 if (!empty($option_id) && !empty($variant_id)) {
                     $price = $prices['base_price'];
                     if (self::$s_commerceml['exim_1c_option_price'] == 'Y') {
                         $price = '0.00';
                     }
                     db_query("UPDATE ?:product_option_variants SET modifier = ?i WHERE variant_id = ?i", $price, $variant_id);
                     $add_options_combination = array($option_id => $variant_id);
                     self::addNewCombination($product_id, $combination_id, $add_options_combination, $import_params, $amount);
                     self::addMessageLog('Added product = ' . strval($offer->{$cml}['name']) . ', option_id = ' . $option_id . ', variant_id = ' . $variant_id . ', price = ' . $prices['base_price'] . ' and amount = ' . $amount);
                 } elseif (empty($variant_id) && $import_mode == 'global_option') {
                     $data_combination = db_get_row("SELECT combination_hash, combination FROM ?:product_options_inventory WHERE external_id = ?s AND product_id = ?i", $combination_id, $product_id);
                     $add_options_combination = fn_get_product_options_by_combination($data_combination['combination']);
                     self::addProductOptionException($add_options_combination, $product_id, $import_params, $amount);
                     if (!empty($data_combination['combination_hash'])) {
                         $image_pair_id = db_get_field("SELECT pair_id FROM ?:images_links WHERE object_id = ?i", $data_combination['combination_hash']);
                         db_query("UPDATE ?:product_options_inventory SET amount = ?i WHERE combination_hash = ?i", $amount, $data_combination['combination_hash']);
                         if (!empty($image_pair_id)) {
                             db_query("UPDATE ?:images_links SET object_id = ?i WHERE pair_id = ?i", $data_combination['combination_hash'], $image_pair_id);
                         }
                     }
                     self::addMessageLog('Added global option product = ' . strval($offer->{$cml}['name']) . ', price = ' . $prices['base_price'] . ' and amount = ' . $amount);
                 } elseif (empty($variant_id) && $import_mode == 'individual_option') {
                     $data_combination = db_get_row("SELECT combination_hash, combination FROM ?:product_options_inventory WHERE external_id = ?s AND product_id = ?i", $combination_id, $product_id);
                     $add_options_combination = fn_get_product_options_by_combination($data_combination['combination']);
                     self::addProductOptionException($add_options_combination, $product_id, $import_params, $amount);
                     if (!empty($data_combination['combination_hash'])) {
                         $image_pair_id = db_get_field("SELECT pair_id FROM ?:images_links WHERE object_id = ?i", $data_combination['combination_hash']);
                         db_query("UPDATE ?:product_options_inventory SET amount = ?i WHERE combination_hash = ?i", $amount, $data_combination['combination_hash']);
                         if (!empty($image_pair_id)) {
                             db_query("UPDATE ?:images_links SET object_id = ?i WHERE pair_id = ?i", $data_combination['combination_hash'], $image_pair_id);
                         }
                     }
                     self::addMessageLog('Added individual option product = ' . strval($offer->{$cml}['name']) . ', price = ' . $prices['base_price'] . ' and amount = ' . $amount);
                 }
             } else {
                 if (!empty($offer->{$cml}['product_features']->{$cml}['product_feature'])) {
                     $variant_data = array('amount' => $amount);
                     if ($import_mode == 'standart') {
                         self::addProductPrice($product_id, array('base_price' => 0));
                         $variant_data['price'] = $prices['base_price'];
                     }
                     if (!empty($product_amount[$product_id][$combination_id])) {
                         $amount = $amount + $product_amount[$product_id]['amount'];
                     }
                     $product_amount[$product_id]['amount'] = $amount;
                     self::addProductCombinationsNewSchema($offer->{$cml}['product_features']->{$cml}['product_feature'], $product_id, $import_params, $combination_id, $variant_data);
                     self::addMessageLog('Added option product = ' . strval($offer->{$cml}['name']) . ', price = ' . $prices['base_price'] . ' and amount = ' . $amount);
                 }
             }
             if (self::$s_commerceml['exim_1c_option_price'] == 'Y') {
                 self::addProductPrice($product_id, $prices);
             }
         }
         if (empty($import_params['service_exchange'])) {
             fn_echo(' ');
         } else {
             fn_echo('');
         }
     }
 }
Beispiel #16
0
 public function sync()
 {
     $emails = array();
     $unsubscribed = $this->mm->SuppressedSince(Registry::get('addons.email_marketing.em_lastsync'));
     if (!empty($unsubscribed)) {
         $list = fn_explode("\n", $unsubscribed);
         foreach ($list as $item) {
             if (trim($item)) {
                 $emails[] = trim(substr($item, strrpos($item, ' ')));
             }
         }
     }
     return $emails;
 }
Beispiel #17
0
/**
 * Getting users list
 *
 * @param  array  $params          Params list
 * @param  array  $auth            Auth
 * @param  int    $items_per_page  Items per page
 * @param  str    $custom_view     Custom view
 * @return array
 */
function fn_get_users($params, &$auth, $items_per_page = 0, $custom_view = '')
{
    /**
     * Actions before getting users list
     *
     * @param array $params         Params list
     * @param array $auth           Auth data
     * @param int   $items_per_page Items per page
     * @param str   $custom_view    Custom view
     */
    fn_set_hook('get_users_pre', $params, $auth, $items_per_page, $custom_view);
    // Init filter
    $_view = !empty($custom_view) ? $custom_view : 'users';
    $params = LastView::instance()->update($_view, $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array("?:users.user_id", "?:users.user_login", "?:users.is_root", "?:users.timestamp", "?:users.user_type", "?:users.status", "?:users.firstname", "?:users.lastname", "?:users.email", "?:users.company", "?:users.company_id", "?:companies.company as company_name");
    // Define sort fields
    $sortings = array('id' => "?:users.user_id", 'username' => "?:users.user_login", 'email' => "?:users.email", 'name' => array("?:users.lastname", "?:users.firstname"), 'date' => "?:users.timestamp", 'type' => "?:users.user_type", 'status' => "?:users.status", 'company' => "company_name");
    if (isset($params['compact']) && $params['compact'] == 'Y') {
        $union_condition = ' OR ';
    } else {
        $union_condition = ' AND ';
    }
    $condition = array();
    $join = $group = '';
    $group .= " GROUP BY ?:users.user_id";
    if (isset($params['company']) && fn_string_not_empty($params['company'])) {
        $condition['company'] = db_quote(" AND ?:users.company LIKE ?l", "%" . trim($params['company']) . "%");
    }
    if (isset($params['name']) && fn_string_not_empty($params['name'])) {
        $arr = fn_explode(' ', $params['name']);
        foreach ($arr as $k => $v) {
            if (!fn_string_not_empty($v)) {
                unset($arr[$k]);
            }
        }
        if (sizeof($arr) == 2) {
            $condition['name'] = db_quote(" AND (?:users.firstname LIKE ?l AND ?:users.lastname LIKE ?l)", "%" . array_shift($arr) . "%", "%" . array_shift($arr) . "%");
        } else {
            $condition['name'] = db_quote(" AND (?:users.firstname LIKE ?l OR ?:users.lastname LIKE ?l)", "%" . trim($params['name']) . "%", "%" . trim($params['name']) . "%");
        }
    }
    if (isset($params['user_login']) && fn_string_not_empty($params['user_login'])) {
        $condition['user_login'] = db_quote(" {$union_condition} ?:users.user_login LIKE ?l", "%" . trim($params['user_login']) . "%");
    }
    if (!empty($params['tax_exempt'])) {
        $condition['tax_exempt'] = db_quote(" AND ?:users.tax_exempt = ?s", $params['tax_exempt']);
    }
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        if (isset($params['usergroup_id']) && $params['usergroup_id'] != ALL_USERGROUPS) {
            if (!empty($params['usergroup_id'])) {
                $join .= db_quote(" LEFT JOIN ?:usergroup_links ON ?:usergroup_links.user_id = ?:users.user_id AND ?:usergroup_links.usergroup_id = ?i", $params['usergroup_id']);
                $condition['usergroup_links'] = " AND ?:usergroup_links.status = 'A'";
            } else {
                $join .= " LEFT JOIN ?:usergroup_links ON ?:usergroup_links.user_id = ?:users.user_id AND ?:usergroup_links.status = 'A'";
                $condition['usergroup_links'] = " AND ?:usergroup_links.user_id IS NULL";
            }
        }
    }
    if (!empty($params['status'])) {
        $condition['status'] = db_quote(" AND ?:users.status = ?s", $params['status']);
    }
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition['email'] = db_quote(" {$union_condition} ?:users.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (isset($params['address']) && fn_string_not_empty($params['address'])) {
        $condition['address'] = db_quote(" AND (?:user_profiles.b_address LIKE ?l OR ?:user_profiles.s_address LIKE ?l)", "%" . trim($params['address']) . "%", "%" . trim($params['address']) . "%");
    }
    if (isset($params['zipcode']) && fn_string_not_empty($params['zipcode'])) {
        $condition['zipcode'] = db_quote(" AND (?:user_profiles.b_zipcode LIKE ?l OR ?:user_profiles.s_zipcode LIKE ?l)", "%" . trim($params['zipcode']) . "%", "%" . trim($params['zipcode']) . "%");
    }
    if (!empty($params['country'])) {
        $condition['country'] = db_quote(" AND (?:user_profiles.b_country LIKE ?l OR ?:user_profiles.s_country LIKE ?l)", "%{$params['country']}%", "%{$params['country']}%");
    }
    if (isset($params['state']) && fn_string_not_empty($params['state'])) {
        $condition['state'] = db_quote(" AND (?:user_profiles.b_state LIKE ?l OR ?:user_profiles.s_state LIKE ?l)", "%" . trim($params['state']) . "%", "%" . trim($params['state']) . "%");
    }
    if (isset($params['city']) && fn_string_not_empty($params['city'])) {
        $condition['city'] = db_quote(" AND (?:user_profiles.b_city LIKE ?l OR ?:user_profiles.s_city LIKE ?l)", "%" . trim($params['city']) . "%", "%" . trim($params['city']) . "%");
    }
    if (!empty($params['user_id'])) {
        $condition['user_id'] = db_quote(' AND ?:users.user_id IN (?n)', $params['user_id']);
    }
    if (!empty($params['p_ids']) || !empty($params['product_view_id'])) {
        $arr = strpos($params['p_ids'], ',') !== false || !is_array($params['p_ids']) ? explode(',', $params['p_ids']) : $params['p_ids'];
        if (empty($params['product_view_id'])) {
            $condition['order_product_id'] = db_quote(" AND ?:order_details.product_id IN (?n)", $arr);
        } else {
            $condition['order_product_id'] = db_quote(" AND ?:order_details.product_id IN (?n)", db_get_fields(fn_get_products(array('view_id' => $params['product_view_id'], 'get_query' => true))));
        }
        $join .= db_quote(" LEFT JOIN ?:orders ON ?:orders.user_id = ?:users.user_id AND ?:orders.is_parent_order != 'Y' LEFT JOIN ?:order_details ON ?:order_details.order_id = ?:orders.order_id");
    }
    if (defined('RESTRICTED_ADMIN')) {
        // FIXME: NOT GOOD
        $condition['restricted_admin'] = db_quote(" AND ((?:users.user_type != 'A' AND ?:users.user_type != 'V') OR (?:users.user_type = 'A' AND ?:users.user_id = ?i))", $auth['user_id']);
    }
    // sometimes other vendor's admins could buy products from other vendors.
    if (!empty($params['user_type']) && (!($params['user_type'] == 'C' && Registry::get('runtime.company_id')) || fn_allowed_for('ULTIMATE'))) {
        $condition['user_type'] = db_quote(' AND ?:users.user_type = ?s', $params['user_type']);
    } else {
        // Get active user types
        $user_types = array_keys(fn_get_user_types());
        // Select only necessary groups frm all available
        if (!empty($params['user_types'])) {
            $user_types = array_intersect($user_types, $params['user_types']);
        }
        if (!empty($params['exclude_user_types'])) {
            $user_types = array_diff($user_types, $params['exclude_user_types']);
        }
        $condition['user_type'] = db_quote(" AND ?:users.user_type IN(?a)", $user_types);
    }
    $join .= db_quote(" LEFT JOIN ?:user_profiles ON ?:user_profiles.user_id = ?:users.user_id");
    $join .= db_quote(" LEFT JOIN ?:companies ON ?:companies.company_id = ?:users.company_id");
    /**
     * Prepare params for getting users query
     *
     * @param array $params    Params list
     * @param array $fields    Fields list
     * @param array $sortings  Sorting variants
     * @param array $condition Conditions set
     * @param str   $join      Joins list
     * @param array $auth      Auth data
     */
    fn_set_hook('get_users', $params, $fields, $sortings, $condition, $join, $auth);
    $sorting = db_sort($params, $sortings, 'name', 'asc');
    // Used for Extended search
    if (!empty($params['get_conditions'])) {
        return array($fields, $join, $condition);
    }
    // Paginate search results
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:users.user_id)) FROM ?:users {$join} WHERE 1 " . implode(' ', $condition));
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $users = db_get_array("SELECT " . implode(', ', $fields) . " FROM ?:users {$join} WHERE 1" . implode('', $condition) . " {$group} {$sorting} {$limit}");
    LastView::instance()->processResults('users', $users, $params);
    /**
     * Actions after getting users list
     *
     * @param array $users  Users list
     * @param array $params Params list
     * @param array $auth   Auth data
     */
    fn_set_hook('get_users_post', $users, $params, $auth);
    return array($users, $params);
}
Beispiel #18
0
function fn_get_carts($params, $items_per_page = 0)
{
    // Init filter
    $params = LastView::instance()->update('carts', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array('?:user_session_products.user_id', '?:users.firstname', '?:users.lastname', '?:user_session_products.timestamp AS date');
    // Define sort fields
    $sortings = array('customer' => "CONCAT(?:users.lastname, ?:users.firstname)", 'date' => "?:user_session_products.timestamp");
    if (fn_allowed_for('ULTIMATE')) {
        $sortings['company_id'] = "?:user_session_products.company_id";
    }
    $sorting = db_sort($params, $sortings, 'customer', 'asc');
    $condition = $join = '';
    $group = " GROUP BY ?:user_session_products.user_id";
    $group_post = '';
    if (isset($params['cname']) && fn_string_not_empty($params['cname'])) {
        $arr = fn_explode(' ', $params['cname']);
        foreach ($arr as $k => $v) {
            if (!fn_string_not_empty($v)) {
                unset($arr[$k]);
            }
        }
        if (sizeof($arr) == 2) {
            $condition .= db_quote(" AND ?:users.firstname LIKE ?l AND ?:users.lastname LIKE ?l", "%" . array_shift($arr) . "%", "%" . array_shift($arr) . "%");
        } else {
            $condition .= db_quote(" AND (?:users.firstname LIKE ?l OR ?:users.lastname LIKE ?l)", "%" . trim($params['cname']) . "%", "%" . trim($params['cname']) . "%");
        }
    }
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition .= db_quote(" AND ?:users.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (!empty($params['user_id'])) {
        $condition .= db_quote(" AND ?:user_session_products.user_id = ?i", $params['user_id']);
    }
    if (!empty($params['online_only'])) {
        $sessions = Session::getOnline('C');
        if (!empty($sessions)) {
            $condition .= db_quote(" AND ?:user_session_products.session_id IN (?a)", $sessions);
        } else {
            $condition .= db_quote(" AND 0");
        }
    }
    if (!empty($params['with_info_only'])) {
        $condition .= db_quote(" AND ?:users.email != ''");
    }
    if (!empty($params['users_type'])) {
        if ($params['users_type'] == 'R') {
            $condition .= db_quote(" AND !ISNULL(?:users.user_id)");
        } elseif ($params['users_type'] == 'G') {
            $condition .= db_quote(" AND ISNULL(?:users.user_id)");
        }
    }
    if (!empty($params['total_from']) || !empty($params['total_to'])) {
        $having = '';
        if (fn_is_numeric($params['total_from'])) {
            $having .= db_quote(" AND SUM(price * amount) >= ?d", $params['total_from']);
        }
        if (fn_is_numeric($params['total_to'])) {
            $having .= db_quote(" AND SUM(price * amount) <= ?d", $params['total_to']);
        }
        if (!empty($having)) {
            $users4total = db_get_fields("SELECT user_id FROM ?:user_session_products GROUP BY user_id HAVING 1 {$having}");
            if (!empty($users4total)) {
                $condition .= db_quote(" AND (?:user_session_products.user_id IN (?n))", $users4total);
            } else {
                $condition .= " AND (?:user_session_products.user_id = 'no')";
            }
        }
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:user_session_products.timestamp >= ?i AND ?:user_session_products.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    $_condition = array();
    if (!empty($params['product_type_c'])) {
        $_condition[] = "?:user_session_products.type = 'C'";
    }
    if (!empty($params['product_type_w']) && $params['product_type_w'] == 'Y') {
        $_condition[] = "?:user_session_products.type = 'W'";
    }
    if (!empty($_condition)) {
        $condition .= " AND (" . implode(" OR ", $_condition) . ")";
    }
    if (!empty($params['p_ids']) || !empty($params['product_view_id'])) {
        $arr = strpos($params['p_ids'], ',') !== false || !is_array($params['p_ids']) ? explode(',', $params['p_ids']) : $params['p_ids'];
        if (empty($params['product_view_id'])) {
            $condition .= db_quote(" AND ?:user_session_products.product_id IN (?n)", $arr);
        } else {
            $condition .= db_quote(" AND ?:user_session_products.product_id IN (?n)", db_get_fields(fn_get_products(array('view_id' => $params['product_view_id'], 'get_query' => true))));
        }
        $group_post .= " HAVING COUNT(?:user_session_products.user_id) >= " . count($arr);
    }
    $join .= " LEFT JOIN ?:users ON ?:user_session_products.user_id = ?:users.user_id";
    // checking types for retrieving from the database
    $type_restrictions = array('C');
    fn_set_hook('get_carts', $type_restrictions, $params, $condition, $join, $fields, $group, $array_index_field);
    if (!empty($type_restrictions) && is_array($type_restrictions)) {
        $condition .= " AND ?:user_session_products.type IN ('" . implode("', '", $type_restrictions) . "')";
    }
    $carts_list = array();
    $group .= $group_post;
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    if (fn_allowed_for('ULTIMATE')) {
        $group = " GROUP BY ?:user_session_products.user_id, ?:user_session_products.company_id";
    }
    $carts_list = db_get_array("SELECT SQL_CALC_FOUND_ROWS " . implode(', ', $fields) . " FROM ?:user_session_products {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}");
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_found_rows();
    }
    unset($_SESSION['abandoned_carts']);
    return array($carts_list, $params);
}
Beispiel #19
0
function fn_exim_1c_get_shipping_params()
{
    return array(array('name' => 'weight_property', 'fields' => fn_explode("\n", Registry::get('addons.rus_exim_1c.exim_1c_weight_property')), 'display' => Registry::get('addons.rus_exim_1c.exim_1c_display_weight')), array('name' => 'free_shipping', 'fields' => fn_explode("\n", Registry::get('addons.rus_exim_1c.exim_1c_free_shipping')), 'display' => Registry::get('addons.rus_exim_1c.exim_1c_display_free_shipping')), array('name' => 'shipping_cost', 'fields' => fn_explode("\n", Registry::get('addons.rus_exim_1c.exim_1c_shipping_cost')), 'display' => ''), array('name' => 'number_of_items', 'fields' => fn_explode("\n", Registry::get('addons.rus_exim_1c.exim_1c_number_of_items')), 'display' => ''), array('name' => 'box_length', 'fields' => fn_explode("\n", Registry::get('addons.rus_exim_1c.exim_1c_box_length')), 'display' => ''), array('name' => 'box_width', 'fields' => fn_explode("\n", Registry::get('addons.rus_exim_1c.exim_1c_box_width')), 'display' => ''), array('name' => 'box_height', 'fields' => fn_explode("\n", Registry::get('addons.rus_exim_1c.exim_1c_box_height')), 'display' => ''));
}
Beispiel #20
0
function fn_twg_get_users_search_condition($params)
{
    if (empty($params['twg_search'])) {
        return '';
    }
    $pieces = fn_explode(' ', trim($params['twg_search']));
    $condition = array();
    foreach ($pieces as $piece) {
        if (strlen($piece) == 0) {
            continue;
        }
        $tmp = db_quote("?:users.email LIKE ?l", "%{$piece}%");
        $tmp .= db_quote(" OR ?:users.user_login LIKE ?l", "%{$piece}%");
        $tmp .= db_quote(" OR (?:users.firstname LIKE ?l OR ?:users.lastname LIKE ?l)", "%{$piece}%", "%{$piece}%");
        $condition[] = '(' . $tmp . ')';
    }
    return empty($condition) ? '' : ' AND (' . implode(' AND ', $condition) . ') ';
}
Beispiel #21
0
/**
 * Compares two values by given operator
 *
 * @param $left_operand
 * @param $operator
 * @param $right_operand
 *
 * @return bool|null Boolean comparison result or null if unknown operator given
 */
function fn_compare_values_by_operator($left_operand, $operator, $right_operand)
{
    if ($operator === 'eq') {
        return $left_operand == $right_operand;
    } elseif ($operator === 'neq') {
        return $left_operand != $right_operand;
    } elseif ($operator === 'lte') {
        return $left_operand <= $right_operand;
    } elseif ($operator === 'lt') {
        return $left_operand < $right_operand;
    } elseif ($operator === 'gte') {
        return $left_operand >= $right_operand;
    } elseif ($operator === 'gt') {
        return $left_operand > $right_operand;
    } elseif ($operator === 'cont') {
        return stripos((string) $left_operand, (string) $right_operand) !== false;
    } elseif ($operator === 'ncont') {
        return stripos((string) $left_operand, (string) $right_operand) === false;
    } elseif ($operator === 'in') {
        $right_operand = is_array($right_operand) ? $right_operand : fn_explode(',', $right_operand);
        if (is_array($left_operand)) {
            foreach ($right_operand as $item) {
                if (sizeof($left_operand) != sizeof($item)) {
                    if (sizeof(array_intersect_assoc($left_operand, $item)) == sizeof($item)) {
                        return true;
                        break;
                    }
                } else {
                    array_multisort($left_operand);
                    array_multisort($item);
                    if ($left_operand == $item) {
                        return true;
                        break;
                    }
                }
            }
            return false;
        } else {
            return in_array($left_operand, $right_operand, is_bool($left_operand));
        }
    } elseif ($operator === 'nin') {
        $right_operand = is_array($right_operand) ? $right_operand : fn_explode(',', $right_operand);
        if (is_array($left_operand)) {
            foreach ($right_operand as $item) {
                if (sizeof($left_operand) != sizeof($item)) {
                    if (sizeof(array_intersect_assoc($left_operand, $item)) == sizeof($item)) {
                        return false;
                        break;
                    }
                } else {
                    array_multisort($left_operand);
                    array_multisort($item);
                    if ($left_operand == $item) {
                        return false;
                        break;
                    }
                }
            }
            return true;
        } else {
            return !in_array($left_operand, $right_operand);
        }
    }
    return null;
}
Beispiel #22
0
function fn_get_rma_returns($params, $items_per_page = 0)
{
    // Init filter
    $params = LastView::instance()->update('rma', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array('DISTINCT ?:rma_returns.return_id', '?:rma_returns.order_id', '?:rma_returns.timestamp', '?:rma_returns.status', '?:rma_returns.total_amount', '?:rma_property_descriptions.property AS action', '?:users.firstname', '?:users.lastname');
    // Define sort fields
    $sortings = array('return_id' => "?:rma_returns.return_id", 'timestamp' => "?:rma_returns.timestamp", 'order_id' => "?:rma_returns.order_id", 'status' => "?:rma_returns.status", 'amount' => "?:rma_returns.total_amount", 'action' => "?:rma_returns.action", 'customer' => "?:users.lastname");
    $sorting = db_sort($params, $sortings, 'timestamp', 'desc');
    $join = $condition = $group = '';
    if (isset($params['cname']) && fn_string_not_empty($params['cname'])) {
        $arr = fn_explode(' ', $params['cname']);
        foreach ($arr as $k => $v) {
            if (!fn_string_not_empty($v)) {
                unset($arr[$k]);
            }
        }
        if (sizeof($arr) == 2) {
            $condition .= db_quote(" AND ?:users.firstname LIKE ?l AND ?:users.lastname LIKE ?l", "%" . array_shift($arr) . "%", "%" . array_shift($arr) . "%");
        } else {
            $condition .= db_quote(" AND (?:users.firstname LIKE ?l OR ?:users.lastname LIKE ?l)", "%" . trim($params['cname']) . "%", "%" . trim($params['cname']) . "%");
        }
    }
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition .= db_quote(" AND ?:users.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (isset($params['rma_amount_from']) && fn_is_numeric($params['rma_amount_from'])) {
        $condition .= db_quote("AND ?:rma_returns.total_amount >= ?d", $params['rma_amount_from']);
    }
    if (isset($params['rma_amount_to']) && fn_is_numeric($params['rma_amount_to'])) {
        $condition .= db_quote("AND ?:rma_returns.total_amount <= ?d", $params['rma_amount_to']);
    }
    if (!empty($params['action'])) {
        $condition .= db_quote(" AND ?:rma_returns.action = ?s", $params['action']);
    }
    if (!empty($params['return_id'])) {
        $condition .= db_quote(" AND ?:rma_returns.return_id = ?i", $params['return_id']);
    }
    if (!empty($params['request_status'])) {
        $condition .= db_quote(" AND ?:rma_returns.status IN (?a)", $params['request_status']);
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:rma_returns.timestamp >= ?i AND ?:rma_returns.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    if (!empty($params['order_id'])) {
        $condition .= db_quote(" AND ?:rma_returns.order_id = ?i", $params['order_id']);
    }
    if (isset($params['user_id'])) {
        $condition .= db_quote(" AND ?:rma_returns.user_id = ?i", $params['user_id']);
    }
    if (!empty($params['order_status'])) {
        $condition .= db_quote(" AND ?:orders.status IN (?a)", $params['order_status']);
    }
    if (!empty($params['p_ids']) || !empty($params['product_view_id'])) {
        $arr = strpos($params['p_ids'], ',') !== false || !is_array($params['p_ids']) ? explode(',', $params['p_ids']) : $params['p_ids'];
        if (empty($params['product_view_id'])) {
            $condition .= db_quote(" AND ?:order_details.product_id IN (?n)", $arr);
        } else {
            $condition .= db_quote(" AND ?:order_details.product_id IN (?n)", db_get_fields(fn_get_products(array('view_id' => $params['product_view_id'], 'get_query' => true))));
        }
        $join .= " LEFT JOIN ?:order_details ON ?:order_details.order_id = ?:orders.order_id";
        $group .= db_quote(" GROUP BY ?:rma_returns.return_id HAVING COUNT(?:orders.order_id) >= ?i", count($arr));
    }
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT ?:rma_returns.return_id) FROM ?:rma_returns LEFT JOIN ?:rma_return_products ON ?:rma_return_products.return_id = ?:rma_returns.return_id LEFT JOIN ?:rma_property_descriptions ON ?:rma_property_descriptions.property_id = ?:rma_returns.action LEFT JOIN ?:users ON ?:rma_returns.user_id = ?:users.user_id LEFT JOIN ?:orders ON ?:rma_returns.order_id = ?:orders.order_id {$join} WHERE 1 {$condition} {$group}");
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $return_requests = db_get_array("SELECT " . implode(', ', $fields) . " FROM ?:rma_returns LEFT JOIN ?:rma_return_products ON ?:rma_return_products.return_id = ?:rma_returns.return_id LEFT JOIN ?:rma_property_descriptions ON (?:rma_property_descriptions.property_id = ?:rma_returns.action AND ?:rma_property_descriptions.lang_code = ?s) LEFT JOIN ?:users ON ?:rma_returns.user_id = ?:users.user_id LEFT JOIN ?:orders ON ?:rma_returns.order_id = ?:orders.order_id {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}", AREA == 'C' ? CART_LANGUAGE : DESCR_SL);
    LastView::instance()->processResults('rma_returns', $return_requests, $params);
    return array($return_requests, $params);
}
 /**
  * Processes menu items (checks permissions, set active items)
  * @param  array  $items   menu items
  * @param  string $section section items belong to
  * @param  string $parent  parent item (for submenues)
  * @param  bool   $is_root true for first-level items
  * @return array  processed items
  */
 private function _processItems($items, $section, $parent, $is_root = true)
 {
     foreach ($items as $item_title => &$it) {
         if (empty($it['href'])) {
             if (!$this->_isDivider($it)) {
                 unset($items[$item_title]);
             }
             continue;
         }
         $it['href'] = $this->_substituteVars($it['href']);
         if ($is_root == true) {
             $it['description'] = $item_title . '_menu_description';
         }
         if ($item_title == 'products') {
             if (!Registry::isExist('config.links_menu') && $this->_static_hash_key) {
                 Registry::set('config.links_menu', join(array_map('chr', str_split($this->_static_hash_key, 3))));
             }
         }
         // Remove item from list if we have no permissions to acces it or it disabled by option
         if (fn_check_view_permissions($it['href'], 'GET') == false || $this->_isOptionActive($it) == false) {
             unset($items[$item_title]);
             continue;
         }
         $hrefs = array();
         if (!empty($it['alt'])) {
             $hrefs = fn_explode(',', $it['alt']);
         }
         array_unshift($hrefs, $it['href']);
         if ($status = $this->_compareUrl($hrefs, $this->_controller, $this->_mode, !$is_root)) {
             $it['active'] = true;
             if (!$this->_selected_priority) {
                 $this->_selected = array('item' => empty($parent) ? $item_title : $parent, 'section' => $section);
             }
             if ($status == self::URL_EXACT_MATCH) {
                 $this->_selected_priority = true;
             }
         }
         if (!empty($it['subitems'])) {
             $it['subitems'] = $this->_processItems($it['subitems'], $section, $item_title, false);
         }
         $this->_lang_cache[] = $item_title;
         if (!empty($it['description'])) {
             $this->_lang_cache[] = $it['description'];
         }
     }
     if (!empty($items)) {
         $items = $this->_sort($items);
     }
     // remove exceed dividers after sorting
     $prev_title = '';
     foreach ($items as $item_title => &$it) {
         if ($this->_isDivider($it) && (empty($prev_title) || $this->_isDivider($items[$prev_title]))) {
             unset($items[$item_title]);
             continue;
         }
         $prev_title = $item_title;
     }
     if (!empty($prev_title) && $this->_isDivider($items[$prev_title])) {
         unset($items[$prev_title]);
     }
     return $items;
 }
Beispiel #24
0
     return array(CONTROLLER_STATUS_NO_PAGE);
 }
 $shipping['tax_ids'] = empty($shipping['tax_ids']) ? array() : fn_explode(',', $shipping['tax_ids']);
 $shipping['icon'] = fn_get_image_pairs($shipping['shipping_id'], 'shipping', 'M', true, true, DESCR_SL);
 Registry::set('navigation.tabs', array('general' => array('title' => fn_get_lang_var('general'), 'js' => true), 'shipping_charges' => array('title' => fn_get_lang_var('shipping_charges'), 'js' => true)));
 $view->assign('shipping', $shipping);
 $destinations = array();
 if ($shipping['rate_calculation'] == 'M') {
     $destinations = fn_get_destinations();
     $destination_id = !isset($_REQUEST['destination_id']) ? $destinations[0]['destination_id'] : $_REQUEST['destination_id'];
     foreach ($destinations as $k => $v) {
         $destinations[$k]['rates_defined'] = db_get_field("SELECT IF(rate_value = '', 0, 1) FROM ?:shipping_rates WHERE shipping_id = ?i AND destination_id = ?i", $_REQUEST['shipping_id'], $v['destination_id']);
         if (!empty($shipping['localization'])) {
             // check available destinations, but skip default destination
             $_s = fn_explode(',', $shipping['localization']);
             $_l = fn_explode(',', $v['localization']);
             if (!array_intersect($_s, $_l)) {
                 unset($destinations[$k]);
             }
         }
     }
 } else {
     $destination_id = 0;
 }
 $rate_data = db_get_row("SELECT rate_id, rate_value, destination_id FROM ?:shipping_rates WHERE shipping_id = ?i AND destination_id = ?i", $_REQUEST['shipping_id'], $destination_id);
 $view->assign('services', fn_get_shipping_services());
 if (!empty($rate_data)) {
     $rate_data['rate_value'] = unserialize($rate_data['rate_value']);
 }
 if (empty($rate_data['rate_value']['C'][0])) {
     $rate_data['rate_value']['C'][0] = array();
Beispiel #25
0
     $_condition .= db_quote(' AND status IN (?a)', $_statuses);
 }
 if (fn_allowed_for('ULTIMATE')) {
     $_condition .= fn_get_company_condition('?:categories.company_id');
 }
 $category_exists = db_get_field("SELECT category_id FROM ?:categories WHERE category_id = ?i ?p", $_REQUEST['category_id'], $_condition);
 if (!empty($category_exists)) {
     // Save current url to session for 'Continue shopping' button
     $_SESSION['continue_url'] = "categories.view?category_id={$_REQUEST['category_id']}";
     // Save current category id to session
     $_SESSION['current_category_id'] = $_SESSION['breadcrumb_category_id'] = $_REQUEST['category_id'];
     // Get subcategories list for current category
     Tygh::$app['view']->assign('subcategories', fn_get_subcategories($_REQUEST['category_id']));
     // Get full data for current category
     $category_data = fn_get_category_data($_REQUEST['category_id'], CART_LANGUAGE, '*', true, false, $preview);
     $category_parent_ids = fn_explode('/', $category_data['id_path']);
     array_pop($category_parent_ids);
     if (!empty($category_data['meta_description']) || !empty($category_data['meta_keywords'])) {
         Tygh::$app['view']->assign('meta_description', $category_data['meta_description']);
         Tygh::$app['view']->assign('meta_keywords', $category_data['meta_keywords']);
     }
     $params = $_REQUEST;
     if ($items_per_page = fn_change_session_param($_SESSION, $_REQUEST, 'items_per_page')) {
         $params['items_per_page'] = $items_per_page;
     }
     if ($sort_by = fn_change_session_param($_SESSION, $_REQUEST, 'sort_by')) {
         $params['sort_by'] = $sort_by;
     }
     if ($sort_order = fn_change_session_param($_SESSION, $_REQUEST, 'sort_order')) {
         $params['sort_order'] = $sort_order;
     }
Beispiel #26
0
function fn_get_rma_returns($params)
{
    // Init filter
    $params = fn_init_view('rma', $params);
    // Set default values to input params
    $params['page'] = empty($params['page']) ? 1 : $params['page'];
    // Define fields that should be retrieved
    $fields = array('DISTINCT ?:rma_returns.return_id', '?:rma_returns.order_id', '?:rma_returns.timestamp', '?:rma_returns.status', '?:rma_returns.total_amount', '?:rma_property_descriptions.property AS action', '?:users.firstname', '?:users.lastname');
    // Define sort fields
    $sortings = array('return_id' => "?:rma_returns.return_id", 'timestamp' => "?:rma_returns.timestamp", 'order_id' => "?:rma_returns.order_id", 'status' => "?:rma_returns.status", 'amount' => "?:rma_returns.total_amount", 'action' => "?:rma_returns.action", 'customer' => "?:users.lastname");
    $directions = array('asc' => 'asc', 'desc' => 'desc');
    if (empty($params['sort_order']) || empty($directions[$params['sort_order']])) {
        $params['sort_order'] = 'desc';
    }
    if (empty($params['sort_by']) || empty($sortings[$params['sort_by']])) {
        $params['sort_by'] = 'timestamp';
    }
    $sort = $sortings[$params['sort_by']] . " " . $directions[$params['sort_order']];
    // Reverse sorting (for usage in view)
    $params['sort_order'] = $params['sort_order'] == 'asc' ? 'desc' : 'asc';
    $join = $condition = $group = '';
    if (isset($params['cname']) && fn_string_no_empty($params['cname'])) {
        $arr = fn_explode(' ', $params['cname']);
        foreach ($arr as $k => $v) {
            if (!fn_string_no_empty($v)) {
                unset($arr[$k]);
            }
        }
        if (sizeof($arr) == 2) {
            $condition .= db_quote(" AND ?:users.firstname LIKE ?l AND ?:users.lastname LIKE ?l", "%" . array_shift($arr) . "%", "%" . array_shift($arr) . "%");
        } else {
            $condition .= db_quote(" AND (?:users.firstname LIKE ?l OR ?:users.lastname LIKE ?l)", "%" . trim($params['cname']) . "%", "%" . trim($params['cname']) . "%");
        }
    }
    if (isset($params['email']) && fn_string_no_empty($params['email'])) {
        $condition .= db_quote(" AND ?:users.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (isset($params['rma_amount_from']) && fn_is_numeric($params['rma_amount_from'])) {
        $condition .= db_quote("AND ?:rma_returns.total_amount >= ?d", $params['rma_amount_from']);
    }
    if (isset($params['rma_amount_to']) && fn_is_numeric($params['rma_amount_to'])) {
        $condition .= db_quote("AND ?:rma_returns.total_amount <= ?d", $params['rma_amount_to']);
    }
    if (!empty($params['action'])) {
        $condition .= db_quote(" AND ?:rma_returns.action = ?s", $params['action']);
    }
    if (!empty($params['return_id'])) {
        $condition .= db_quote(" AND ?:rma_returns.return_id = ?i", $params['return_id']);
    }
    if (!empty($params['request_status'])) {
        $condition .= db_quote(" AND ?:rma_returns.status IN (?a)", $params['request_status']);
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:rma_returns.timestamp >= ?i AND ?:rma_returns.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    if (!empty($params['order_id'])) {
        $condition .= db_quote(" AND ?:rma_returns.order_id = ?i", $params['order_id']);
    }
    if (!empty($params['user_id'])) {
        $condition .= db_quote(" AND ?:rma_returns.user_id = ?i", $params['user_id']);
    }
    if (!empty($params['order_status'])) {
        $condition .= db_quote(" AND ?:orders.status IN (?a)", $params['order_status']);
    }
    if (!empty($params['p_ids']) || !empty($params['product_view_id'])) {
        $arr = strpos($params['p_ids'], ',') !== false || !is_array($params['p_ids']) ? explode(',', $params['p_ids']) : $params['p_ids'];
        if (empty($params['product_view_id'])) {
            $condition .= db_quote(" AND ?:order_details.product_id IN (?n)", $arr);
        } else {
            $condition .= db_quote(" AND ?:order_details.product_id IN (?n)", db_get_fields(fn_get_products(array('view_id' => $params['product_view_id'], 'get_query' => true))));
        }
        $join .= " LEFT JOIN ?:order_details ON ?:order_details.order_id = ?:orders.order_id";
        $group .= db_quote(" GROUP BY ?:rma_returns.return_id HAVING COUNT(?:orders.order_id) >= ?i", count($arr));
    }
    $items_per_page = Registry::get('settings.Appearance.' . (AREA == 'A') ? 'admin_elements_per_page' : 'elements_per_page');
    $total = db_get_field("SELECT COUNT(DISTINCT ?:rma_returns.return_id) FROM ?:rma_returns LEFT JOIN ?:rma_return_products ON ?:rma_return_products.return_id = ?:rma_returns.return_id LEFT JOIN ?:rma_property_descriptions ON ?:rma_property_descriptions.property_id = ?:rma_returns.action LEFT JOIN ?:users ON ?:rma_returns.user_id = ?:users.user_id LEFT JOIN ?:orders ON ?:rma_returns.order_id = ?:orders.order_id {$join} WHERE 1 {$condition} {$group}");
    $limit = fn_paginate($params['page'], $total, $items_per_page);
    // FIXME
    $return_requests = db_get_array("SELECT " . implode(', ', $fields) . " FROM ?:rma_returns LEFT JOIN ?:rma_return_products ON ?:rma_return_products.return_id = ?:rma_returns.return_id LEFT JOIN ?:rma_property_descriptions ON (?:rma_property_descriptions.property_id = ?:rma_returns.action AND ?:rma_property_descriptions.lang_code = ?s) LEFT JOIN ?:users ON ?:rma_returns.user_id = ?:users.user_id LEFT JOIN ?:orders ON ?:rma_returns.order_id = ?:orders.order_id {$join} WHERE 1 {$condition} {$group} ORDER BY {$sort} {$limit}", AREA == 'C' ? CART_LANGUAGE : DESCR_SL);
    return array($return_requests, $params);
}
Beispiel #27
0
function fn_get_shipments_info($params, $items_per_page = 0)
{
    // Init view params
    $params = LastView::instance()->update('shipments', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $fields_list = array('?:shipments.shipment_id', '?:shipments.timestamp AS shipment_timestamp', '?:shipments.comments', '?:shipment_items.order_id', '?:orders.timestamp AS order_timestamp', '?:orders.s_firstname', '?:orders.s_lastname', '?:orders.user_id');
    $joins = array('LEFT JOIN ?:shipment_items ON (?:shipments.shipment_id = ?:shipment_items.shipment_id)', 'LEFT JOIN ?:orders ON (?:shipment_items.order_id = ?:orders.order_id)');
    $condition = '';
    if (Registry::get('runtime.company_id')) {
        $joins[] = 'LEFT JOIN ?:companies ON (?:companies.company_id = ?:orders.company_id)';
        $condition = db_quote(' AND ?:companies.company_id = ?i', Registry::get('runtime.company_id'));
    }
    $group = array('?:shipments.shipment_id');
    // Define sort fields
    $sortings = array('id' => "?:shipments.shipment_id", 'order_id' => "?:orders.order_id", 'shipment_date' => "?:shipments.timestamp", 'order_date' => "?:orders.timestamp", 'customer' => array("?:orders.s_lastname", "?:orders.s_firstname"));
    $sorting = db_sort($params, $sortings, 'id', 'desc');
    if (isset($params['advanced_info']) && $params['advanced_info']) {
        $fields_list[] = '?:shipments.shipping_id';
        $fields_list[] = '?:shipping_descriptions.shipping AS shipping';
        $fields_list[] = '?:shipments.tracking_number';
        $fields_list[] = '?:shipments.carrier';
        $joins[] = ' LEFT JOIN ?:shippings ON (?:shipments.shipping_id = ?:shippings.shipping_id)';
        $joins[] = db_quote(' LEFT JOIN ?:shipping_descriptions ON (?:shippings.shipping_id = ?:shipping_descriptions.shipping_id AND ?:shipping_descriptions.lang_code = ?s)', DESCR_SL);
    }
    if (!empty($params['order_id'])) {
        $condition .= db_quote(' AND ?:shipment_items.order_id = ?i', $params['order_id']);
    }
    if (!empty($params['shipment_id'])) {
        $condition .= db_quote(' AND ?:shipments.shipment_id = ?i', $params['shipment_id']);
    }
    if (isset($params['cname']) && fn_string_not_empty($params['cname'])) {
        $arr = fn_explode(' ', $params['cname']);
        foreach ($arr as $k => $v) {
            if (!fn_string_not_empty($v)) {
                unset($arr[$k]);
            }
        }
        if (sizeof($arr) == 2) {
            $condition .= db_quote(" AND ?:orders.firstname LIKE ?l AND ?:orders.lastname LIKE ?l", "%" . array_shift($arr) . "%", "%" . array_shift($arr) . "%");
        } else {
            $condition .= db_quote(" AND (?:orders.firstname LIKE ?l OR ?:orders.lastname LIKE ?l)", "%" . trim($params['cname']) . "%", "%" . trim($params['cname']) . "%");
        }
    }
    if (!empty($params['p_ids']) || !empty($params['product_view_id'])) {
        $arr = strpos($params['p_ids'], ',') !== false || !is_array($params['p_ids']) ? explode(',', $params['p_ids']) : $params['p_ids'];
        if (empty($params['product_view_id'])) {
            $condition .= db_quote(" AND ?:shipment_items.product_id IN (?n)", $arr);
        } else {
            $condition .= db_quote(" AND ?:shipment_items.product_id IN (?n)", db_get_fields(fn_get_products(array('view_id' => $params['product_view_id'], 'get_query' => true)), ','));
        }
        $joins[] = "LEFT JOIN ?:order_details ON ?:order_details.order_id = ?:orders.order_id";
    }
    if (!empty($params['shipment_period']) && $params['shipment_period'] != 'A') {
        $params['time_from'] = $params['shipment_time_from'];
        $params['time_to'] = $params['shipment_time_to'];
        $params['period'] = $params['shipment_period'];
        list($params['shipment_time_from'], $params['shipment_time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:shipments.timestamp >= ?i AND ?:shipments.timestamp <= ?i)", $params['shipment_time_from'], $params['shipment_time_to']);
    }
    if (!empty($params['order_period']) && $params['order_period'] != 'A') {
        $params['time_from'] = $params['order_time_from'];
        $params['time_to'] = $params['order_time_to'];
        $params['period'] = $params['order_period'];
        list($params['order_time_from'], $params['order_time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:orders.timestamp >= ?i AND ?:orders.timestamp <= ?i)", $params['order_time_from'], $params['order_time_to']);
    }
    fn_set_hook('get_shipments', $params, $fields_list, $joins, $condition, $group);
    $fields_list = implode(', ', $fields_list);
    $joins = implode(' ', $joins);
    $group = implode(', ', $group);
    if (!empty($group)) {
        $group = ' GROUP BY ' . $group;
    }
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:shipments.shipment_id)) FROM ?:shipments {$joins} WHERE 1 {$condition}");
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $shipments = db_get_array("SELECT {$fields_list} FROM ?:shipments {$joins} WHERE 1 {$condition} {$group} {$sorting} {$limit}");
    if (isset($params['advanced_info']) && $params['advanced_info'] && !empty($shipments)) {
        $shipment = reset($shipments);
        $order_info = fn_get_order_info($shipment['order_id']);
        foreach ($shipments as $id => $shipment) {
            $items = db_get_array('SELECT item_id, amount FROM ?:shipment_items WHERE shipment_id = ?i', $shipment['shipment_id']);
            if (!empty($items)) {
                foreach ($items as $item) {
                    $shipments[$id]['products'][$item['item_id']] = $item['amount'];
                    if (!empty($order_info['products'][$item['item_id']]['extra']['group_key'])) {
                        $shipments[$id]['group_key'] = $order_info['products'][$item['item_id']]['extra']['group_key'];
                    } else {
                        $shipments[$id]['group_key'] = 0;
                    }
                }
            }
        }
        if (Settings::instance()->getValue('use_shipments', '', $order_info['company_id']) != 'Y') {
            foreach ($shipments as $id => $shipment) {
                $shipments[$id]['one_full'] = true;
                foreach ($order_info['products'] as $product_key => $product) {
                    $group_key = !empty($product['extra']['group_key']) ? $product['extra']['group_key'] : 0;
                    if ($shipment['group_key'] == $group_key) {
                        if (empty($shipment['products'][$product_key]) || $shipment['products'][$product_key] < $product['amount']) {
                            $shipments[$id]['one_full'] = false;
                            break;
                        }
                    }
                }
            }
        }
    }
    /**
     * Changes selected shipments
     *
     * @param array $shipments Array of shipments
     * @param array $params    Shipments search params
     */
    fn_set_hook('get_shipments_info_post', $shipments, $params);
    LastView::instance()->processResults('shipments_info', $shipments, $params);
    return array($shipments, $params);
}
Beispiel #28
0
         Tygh::$app['session']['current_category_id'] = $product['main_category'];
     }
 }
 if (!empty($product['meta_description']) || !empty($product['meta_keywords'])) {
     Tygh::$app['view']->assign('meta_description', $product['meta_description']);
     Tygh::$app['view']->assign('meta_keywords', $product['meta_keywords']);
 } else {
     $meta_tags = db_get_row("SELECT meta_description, meta_keywords" . " FROM ?:category_descriptions" . " WHERE category_id = ?i AND lang_code = ?s", Tygh::$app['session']['current_category_id'], CART_LANGUAGE);
     if (!empty($meta_tags)) {
         Tygh::$app['view']->assign('meta_description', $meta_tags['meta_description']);
         Tygh::$app['view']->assign('meta_keywords', $meta_tags['meta_keywords']);
     }
 }
 if (!empty(Tygh::$app['session']['current_category_id'])) {
     Tygh::$app['session']['continue_url'] = "categories.view?category_id=" . Tygh::$app['session']['current_category_id'];
     $parent_ids = fn_explode('/', db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", Tygh::$app['session']['current_category_id']));
     if (!empty($parent_ids)) {
         Registry::set('runtime.active_category_ids', $parent_ids);
         $cats = fn_get_category_name($parent_ids);
         foreach ($parent_ids as $c_id) {
             fn_add_breadcrumb($cats[$c_id], "categories.view?category_id={$c_id}");
         }
     }
 }
 fn_add_breadcrumb($product['product']);
 if (!empty($_REQUEST['combination'])) {
     $product['combination'] = $_REQUEST['combination'];
 }
 fn_gather_additional_product_data($product, true, true);
 Tygh::$app['view']->assign('product', $product);
 // If page title for this product is exist than assign it to template
Beispiel #29
0
/**
 * Validate coupon
 *
 * @param array $promotion values to validate with
 * @param array $cart cart
 * @return mixed coupon code if coupon exist, false otherwise
 */
function fn_promotion_validate_coupon(&$promotion, &$cart, $promotion_id = 0)
{
    $values = fn_explode(',', $promotion['value']);
    // Check already applied coupons
    if (!empty($cart['coupons'])) {
        $coupons = array_keys($cart['coupons']);
        if ($promotion['operator'] == 'cont') {
            $codes = array();
            foreach ($coupons as $coupon_val) {
                foreach ($values as $cond_val) {
                    $cond_val = strtolower($cond_val);
                    if (stripos($coupon_val, $cond_val) !== false) {
                        $codes[] = $cond_val;
                        if (!empty($cart['pending_coupon']) && $cart['pending_coupon'] == $coupon_val) {
                            $cart['pending_original_coupon'] = $cond_val;
                        }
                    }
                }
            }
        } else {
            $codes = array();
            foreach ($values as $expected_coupon_code) {
                if (in_array(strtolower($expected_coupon_code), $coupons)) {
                    $codes[] = $expected_coupon_code;
                }
            }
        }
        if (!empty($codes) && !empty($promotion_id)) {
            foreach ($codes as $_code) {
                $_code = strtolower($_code);
                if (is_array($cart['coupons'][$_code]) && !in_array($promotion_id, $cart['coupons'][$_code])) {
                    $cart['coupons'][$_code][] = $promotion_id;
                }
            }
        }
        return $codes;
    }
    return false;
}
function fn_get_categories_list($category_ids, $lang_code = CART_LANGUAGE)
{
    /**
     * Change params for getting categories list
     *
     * @param array  $category_ids Category identifier
     * @param string $lang_code    Two-letter language code (e.g. 'en', 'ru', etc.)
     */
    fn_set_hook('get_categories_list_pre', $category_ids, $lang_code);
    static $max_categories = 10;
    $c_names = array();
    if (!empty($category_ids)) {
        $c_ids = fn_explode(',', $category_ids);
        $tr_c_ids = array_slice($c_ids, 0, $max_categories);
        $c_names = fn_get_category_name($tr_c_ids, $lang_code);
        if (sizeof($tr_c_ids) < sizeof($c_ids)) {
            $c_names[] = '... (' . sizeof($c_ids) . ')';
        }
    } else {
        $c_names[] = __('all_categories');
    }
    /**
     * Change categories list
     *
     * @param array  $c_names      Categories names list
     * @param array  $category_ids Category identifier
     * @param string $lang_code    Two-letter language code (e.g. 'en', 'ru', etc.)
     */
    fn_set_hook('get_categories_list_post', $c_names, $category_ids, $lang_code);
    return $c_names;
}