function onAction() { global $application; $request = $application->getInstance('Request'); $pm_sm_uid = $request->getValueByKey('pm_sm_uid'); if ($pm_sm_uid !== NULL) { $pm_settings = modApiFunc("Checkout", "getSelectedModules", "payment"); $sm_settings = modApiFunc("Checkout", "getSelectedModules", "shipping"); $pm_sm_settings = array_merge_recursive($pm_settings, $sm_settings); $module_settings = $pm_sm_settings[$pm_sm_uid]; $rule = $request->getValueByKey('pm_sm_accepted_currencies_rule'); if ($rule !== NULL) { foreach ($module_settings['currency_acceptance_rules'] as $id => $info) { $info =& $module_settings['currency_acceptance_rules'][$id]; if ($info['rule_name'] == $rule) { $info['rule_selected'] = DB_TRUE; } else { $info['rule_selected'] = DB_FALSE; } unset($info); } switch ($rule) { case ACTIVE_AND_SELECTED_BY_CUSTOMER: break; case ACTIVE_AND_ACCEPTED_BY_PM_SM_AND_SELECTED_BY_CUSTOMER: $accepted_currencies = $request->getValueByKey('accepted_currencies_checkboxes'); if ($accepted_currencies === NULL) { $accepted_currencies = array(); } // foreach ($module_settings['accepted_currencies'] as $id => $info) { $info =& $module_settings['accepted_currencies'][$id]; if (array_key_exists($info['currency_code'], $accepted_currencies)) { $info['currency_status'] = ACCEPTED; } else { $info['currency_status'] = NOT_ACCEPTED; } unset($info); } break; case THE_ONLY_ACCEPTED: $the_only_acceptable_code = $request->getValueByKey('accepted_currencies_radio'); // foreach ($module_settings['accepted_currencies'] as $id => $info) { $info =& $module_settings['accepted_currencies'][$id]; if ($info['currency_code'] == $the_only_acceptable_code) { $info['currency_status'] = THE_ONE_ONLY_ACCEPTED; } else { $info['currency_status'] = NOT_ACCEPTED; } unset($info); } break; case MAIN_STORE_CURRENCY: break; } modApiStaticFunc("Checkout", "update_pm_sm_currency_settings", $pm_sm_uid, $module_settings); } } }
function onAction() { global $application; $request = $application->getInstance('Request'); $SessionPost = array(); if (modApiFunc('Session', 'is_Set', 'SessionPost')) { _fatal(array("CODE" => "CORE_050"), __CLASS__, __FUNCTION__); } $SessionPost = $_POST; $nErrors = 0; $topic_id = $request->getValueByKey('topic'); $topic_name = $request->getValueByKey('topic_name'); $topic_status = $request->getValueByKey('topic_status'); $topic_access = $request->getValueByKey('topic_access'); $topic_auto = $request->getValueByKey('topic_auto'); if ($topic_id == '') { $SessionPost['ViewState']['ErrorsArray'][] = 'ALERT_EDIT_INTERNAL_ERROR'; $SessionPost['ViewState']['hasCloseScript'] = 'false'; } elseif ($topic_name == '') { $SessionPost['ViewState']['ErrorsArray'][] = 'ALERT_FILL_TOPIC_NAME'; $SessionPost['ViewState']['ErrorFields'][] = 'topic_name'; $SessionPost['ViewState']['hasCloseScript'] = 'false'; } else { modApiStaticFunc('Subscriptions', 'updateTopic', $topic_id, $topic_name, $topic_status, $topic_access, $topic_auto); } modApiFunc('Session', 'set', 'SessionPost', $SessionPost); $request = new Request(); $request->setView(CURRENT_REQUEST_URL); $application->redirect($request); }
function onAction() { global $application; $request = $application->getInstance('Request'); $topic = $request->getValueByKey('topic'); $SessionPost = array(); /* if(modApiFunc('Session', 'is_Set', 'SessionPost')) { _fatal(array( "CODE" => "CORE_050"), __CLASS__, __FUNCTION__); } */ $SessionPost = $_POST; $nErrors = 0; $selected_topics = $request->getValueByKey('topic_id'); if (!is_array($selected_topics) || empty($selected_topics)) { $SessionPost['ViewState']['ErrorsArray'][] = 'ALERT_SELECT_TOPICS_TO_UNSUBSCRIBE'; $nErrors++; } $emails = $request->getValueByKey('emails_unsubscribe'); $emails = preg_split('/[\\s,;]+/', $emails); $valid_emails = array(); $invalid_emails = array(); foreach ($emails as $email) { if (modApiFunc("Users", "isValidEmail", $email)) { $valid_emails[] = $email; } else { $invalid_emails[] = $email; } } if (empty($valid_emails)) { $SessionPost['ViewState']['ErrorsArray'][] = 'ALERT_FILL_EMAILS_TO_UNSUBSCRIBE'; $SessionPost['ViewState']['ErrorFields'][] = 'emails_unsubscribe'; $nErrors++; } if ($nErrors == 0) { modApiStaticFunc('Subscriptions', 'unsubscribeEmails', array_keys($selected_topics), $valid_emails); } if (!empty($valid_emails) && !empty($invalid_emails)) { $SessionPost['ViewState']['ErrorsArray'][] = 'ALERT_SOME_EMAILS_INVALID'; $SessionPost['ViewState']['ErrorFields'][] = 'emails_unsubscribe'; $SessionPost['emails_unsubscribe'] = implode("\n", $invalid_emails); $nErrors++; } if ($nErrors > 0) { $SessionPost['ViewState']['OpenSubform'] = 'unsubscribe'; } modApiFunc('Session', 'set', 'SessionPost', $SessionPost); $request = new Request(); $request->setView(CURRENT_REQUEST_URL); if (!empty($topic)) { $request->setKey('topic', $topic); } $application->redirect($request); }
/** * @ */ function onAction() { global $application; $this->updateGA(); $this->updateClixGalore(); //Set modules active $request = $application->getInstance('Request'); $ActiveModules = $request->getValueByKey('ModuleActive'); $InstalledModules = modApiStaticFunc("TransactionTracking", "getInstalledModules"); foreach ($InstalledModules as $uid => $info) { $new_status = isset($ActiveModules[$uid]) ? DB_TRUE : DB_FALSE; TransactionTracking::updateModuleStatus($uid, $new_status); } modApiFunc('Session', 'set', 'ResultMessage', 'MSG_TRANSACTION_TRACKING_SETTINGS_UPDATED'); }
function onAction() { global $application; $request = $application->getInstance('Request'); $SessionPost = array(); if (modApiFunc('Session', 'is_Set', 'SessionPost')) { _fatal(array("CODE" => "CORE_050"), __CLASS__, __FUNCTION__); } $SessionPost = $_POST; $nErrors = 0; $sort_orders = $request->getValueByKey('sort_order'); if (!empty($sort_orders) && is_array($sort_orders)) { foreach ($sort_orders as $topic_id => $sort_order) { modApiStaticFunc('Subscriptions', 'updateOrder', $topic_id, $sort_order); } } }
function output($part = 'footer') { global $application; #Define whether to output the view or not if (isset($this->NoView) && $this->NoView) { $application->outputTagErrors(true, "TransactionTracking", "Errors"); return ""; } /* Output composition */ $output = ''; $InstalledModules = modApiStaticFunc("TransactionTracking", "getInstalledModules"); foreach ($InstalledModules as $method_uid => $info) { if ($info['status_active'] == DB_TRUE) { $output .= $this->outputMethodHtmlCode($method_uid, $part) . "\n"; } } return $output; }
function initQuery($params) { $anon_name = $params['anon_name']; $tables = modApiStaticFunc("Customer_Account", "getTables"); $c = $tables['ca_customers']['columns']; $this->addSelectField($c['customer_account']); $this->WhereValue($c['customer_account'], DB_LIKE, "'" . $anon_name . "%'"); }
function deleteCustomers($customers_ids) { if (!is_array($customers_ids) or empty($customers_ids)) { return false; } global $application; $ca_tables = $this->getTables(); $co_tables = modApiStaticFunc('Checkout', 'getTables'); $query = new DB_Select(); $query->addSelectTable('orders'); $query->addSelectField($co_tables['orders']['columns']['id'], 'order_id'); $query->Where($co_tables['orders']['columns']['person_id'], DB_IN, "(" . implode(", ", $customers_ids) . ")"); $res = $application->db->getDB_Result($query); $orders_ids = array(); for ($i = 0; $i < count($res); $i++) { $orders_ids[] = $res[$i]['order_id']; } if (!empty($orders_ids)) { modApiFunc('Checkout', 'DeleteOrders', $orders_ids); } $accounts = array(); $query = new DB_Select(); $query->addSelectField($ca_tables['ca_customers']['columns']['customer_account'], 'customer_account'); $query->addSelectTable('ca_customers'); $query->Where($ca_tables['ca_customers']['columns']['customer_id'], DB_IN, "(" . implode(", ", $customers_ids) . ")"); $res = $application->db->getDB_Result($query); for ($i = 0; $i < count($res); $i++) { $accounts[] = $res[$i]['customer_account']; } if (!empty($accounts)) { $query = new DB_Delete('ca_activation_keys'); $query->Where($ca_tables['ca_activation_keys']['columns']['customer_account'], DB_IN, "('" . implode("','", $accounts) . "')"); $application->db->PrepareSQL($query); $application->db->DB_Exec(); } $query = new DB_Delete('ca_person_info_data'); $query->Where($ca_tables['ca_person_info_data']['columns']['customer_id'], DB_IN, "(" . implode(", ", $customers_ids) . ")"); $application->db->PrepareSQL($query); $application->db->DB_Exec(); $query = new DB_Delete('ca_customers'); $query->Where($ca_tables['ca_customers']['columns']['customer_id'], DB_IN, "(" . implode(", ", $customers_ids) . ")"); $application->db->PrepareSQL($query); $application->db->DB_Exec(); return true; }
function initQuery($params) { $tables = modApiStaticFunc($params['ApiClassName'], "getTables"); $columns = $tables['sm_dsr_rates']['columns']; $this->addSelectField($columns['dst_country'], 'dst_country'); $this->addSelectField($columns['dst_state'], 'dst_state'); $this->addSelectField($columns['bcharge_abs'], 'bcharge_abs'); $this->addSelectField($columns['bcharge_perc'], 'bcharge_perc'); $this->addSelectField($columns['acharge_pi_abs'], 'acharge_pi_abs'); $this->addSelectField($columns['acharge_pi_perc'], 'acharge_pi_perc'); $this->addSelectField($columns['acharge_pwu_abs'], 'acharge_pwu_abs'); $this->addSelectField($columns['acharge_pwu_perc'], 'acharge_pwu_perc'); $this->WhereValue($columns['method_id'], DB_EQ, $params['method_id']); $this->WhereAND(); $this->addWhereOpenSection(); $this->WhereValue($columns['dst_country'], DB_EQ, $params['shipping_info_country_id']); $this->WhereOR(); $this->WhereValue($columns['dst_country'], DB_EQ, ALL_OTHER_COUNTRIES_COUNTRY_ID); $this->addWhereCloseSection(); $this->WhereAND(); $this->addWhereOpenSection(); $this->WhereValue($columns['dst_state'], DB_EQ, $params['shipping_info_state_id']); $this->WhereOR(); $this->WhereValue($columns['dst_state'], DB_EQ, ALL_OTHER_STATES_STATE_ID); $this->WhereOR(); $this->WhereValue($columns['dst_state'], DB_EQ, STATE_UNDEFINED_STATE_ID); $this->addWhereCloseSection(); $this->WhereAND(); $this->WhereValue($columns['wrange_from'], DB_LTE, $params['pak_weight']); $this->WhereAND(); $this->WhereValue($columns['wrange_to'], DB_GTE, $params['pak_weight']); }
function add_https_settings($layout_array, $layout_file_path) { // SiteHTTPSURL [Site] // https 1.8.2 if (isset($layout_array['Site'])) { $new_vals = array(); foreach ($layout_array['Site'] as $key => $value) { if (_ml_strcasecmp($key, 'SiteHTTPSURL') != 0) { $new_vals[$key] = $value; } } $layout_array['Site'] = $new_vals; } // HTTPS = YES/NO // https 1.8.2 foreach ($layout_array as $layout_section_name => $vals) { $new_vals = array(); foreach ($vals as $key => $value) { if (_ml_strcasecmp($key, 'HTTPS') != 0) { $new_vals[$key] = $value; } } $layout_array[$layout_section_name] = $new_vals; } // SITE_HTTPS_URL if (isset($layout_array['Site']) && isset($layout_array['Site']['SiteURL'])) { $SiteHTTPSURL = modApiStaticFunc("Configuration", "getCZSiteHTTPSURL", $layout_array['Site']['SiteURL']); if ($SiteHTTPSURL !== NULL) { $layout_array['Site']['SiteHTTPSURL'] = $SiteHTTPSURL; } } // HTTPS $cz_https_settings = modApiStaticFunc("Configuration", "getLayoutSettings"); //Search for current layout path entry $target_layout_file_path = NULL; foreach ($cz_https_settings as $fpath => $info) { if (file_path_cmp($fpath, $layout_file_path) === 0) { $target_layout_file_path = $fpath; break; } } if ($target_layout_file_path !== NULL) { $map = modApiStaticFunc("Configuration", "getLayoutSettingNameByCZLayoutSectionNameMap"); foreach ($map as $layout_section_name => $settings_section_name) { if (isset($layout_array[$layout_section_name])) { $layout_array[$layout_section_name]['HTTPS'] = modApiStaticFunc("Configuration", "getCZHTTPS", $layout_section_name, $cz_https_settings[$target_layout_file_path]); } } } return $layout_array; }
public static function getPanelSettingsJSON() { global $application; $panel_settings = unserialize(modApiFunc('Configuration', 'getValue', STOREFRONT_SKIN_PANEL_SETTINGS)); if (!$panel_settings) { $panel_settings = array(); } $panel_settings['active_theme'] = (string) modApiStaticFunc('Look_Feel', 'getActiveTheme'); $panel_settings['edited_theme'] = modApiStaticFunc('Look_Feel', 'getEditedTheme'); $panel_settings['skin_default_theme_title'] = getXMsg('LF', 'LF_SKIN_DEFAULTS_TITLE'); $panel_settings['themes_folder'] = $application->getAppIni('PATH_THEME_THEMES'); $panel_settings['labels'] = array('set_active_fail_wtd' => getXMsg('LF', 'LF_STATUS_SET_ACTIVE_FAIL_WTD'), 'alert_not_saved_theme' => getXMsg('LF', 'ALERT_NOT_SAVED_THEME'), 'alert_not_saved_theme_nav' => getXMsg('LF', 'ALERT_NOT_SAVED_THEME_NAV')); loadCoreFile('JSON.php'); $json = new Services_JSON(); return $json->encode($panel_settings); }
function initQuery($params) { $tables = modApiStaticFunc($params['ApiClassName'], "getTables"); $s = $tables[$params['settings_table_name']]['columns']; $this->addSelectTable($params['settings_table_name']); $this->addSelectField('*'); }
xMsg('LF', 'LF_GO_URL_TITLE'); ?> </h3> <div class="button_go"></div><div class="url"><input type="text" /></div> </div> </div> </div> </div> <div id="rulesDebug"></div> <script language="JavaScript"> $(function() { window.setTimeout(function() { $('body').SkinsPanel(<?php echo modApiStaticFunc('Look_Feel', 'getPanelSettingsJSON'); ?> ); }, 100); }); </script> <?php echo $application->combineAdminJS(array('js/main.js', 'js/jquery.ui.widget.js', 'js/jquery.ui.button.js', 'js/jquery.ui.accordion.js', 'colorpicker/js/colorpicker.js', 'js/css_editor_panel.js', 'js/css_editor_rule.js', 'js/css_editor_property.js')); ?> </body> </HTML>
function getPermissionsWarning($skin_info) { global $application; $skin_path = $application->appIni['PATH_THEMES'] . $skin_info['skin'] . '/'; $warnings = array(); $themes_dir = $skin_path . 'themes'; if (!is_dir($themes_dir)) { $warnings[] = $this->renderWarning(getXMsg('LF', 'WRN_NO_THEMES_DIR', $themes_dir)); } elseif (!is_writable($themes_dir)) { $warnings[] = $this->renderWarning(getXMsg('LF', 'WRN_THEMES_DIR_NOT_WRITABLE', $themes_dir)); } $images_dir = $skin_path . 'images/upload'; if (!is_dir($images_dir)) { if (!mkdir($images_dir, 0755)) { $warnings[] = $this->renderWarning(getXMsg('LF', 'WRN_NO_IMAGES_DIR', $images_dir)); } } elseif (!is_writable($images_dir)) { $warnings[] = $this->renderWarning(getXMsg('LF', 'WRN_IMAGES_DIR_NOT_WRITABLE', $images_dir)); } $themes_warnings = array(); $themes = modApiStaticFunc('Look_Feel', 'getThemeList'); foreach ($themes as $theme) { if (!$theme['editable']) { $themes_warnings[] = $this->renderWarning($theme['path']); } } if ($themes_warnings) { $warnings[] = $this->mTmplFiller->fill('look_feel/skin_list/', 'warning_list_themes.tpl.html', array('Warnings' => implode('', $themes_warnings))); } if (false && Look_Feel::getEditorRules() == '') { $warnings[] = $this->renderWarning(getXMsg('LF', 'WRN_CSS_RULES_NOT_DEFINED', $images_dir)); } elseif (sizeof($themes_warnings) < sizeof($themes) || is_writable($themes_dir)) { $this->enable_editing = true; } return $warnings ? $this->mTmplFiller->fill('look_feel/skin_list/', 'warning_list.tpl.html', array('Warnings' => implode('', $warnings))) : ''; }
case 'add_theme': $result = modApiStaticFunc('Look_Feel', 'addNewTheme', $r->getValueByKey('name')); $json = new Services_JSON(); echo $json->encode($result); exit; case 'set_active_theme': modApiStaticFunc('Look_Feel', 'setActiveTheme', $r->getValueByKey('name')); modApiFunc('Configuration', 'resetCache'); $active = modApiFunc('Look_Feel', 'getActiveTheme'); echo $active == $r->getValueByKey('name') ? 'ok' : 'fail(' . $r->getValueByKey('name') . ':' . $active . ')'; exit; case 'set_edited_theme': modApiStaticFunc('Look_Feel', 'setEditedTheme', $r->getValueByKey('name')); exit; case 'remove_theme': $result = modApiStaticFunc('Look_Feel', 'removeTheme', $r->getValueByKey('name')); $json = new Services_JSON(); echo $json->encode($result); exit; case 'save_theme': $name = $r->getValueByKey('name'); $css = $r->getValueByKey('css'); $result = modApiStaticFunc('Look_Feel', 'saveThemeCss', $name, $css); $json = new Services_JSON(); echo $json->encode($result); exit; case 'set_panel_setting': modApiStaticFunc('Look_Feel', 'setPanelSetting', $r->getValueByKey('name'), $r->getValueByKey('value')); echo 'done'; exit; }
function __loadOrdersSummary() { if (!$this->search_completed or empty($this->orders_ids)) { return; } // : // , // main_store_currency . // main_store_currency, // . // main_store_currency. global $application; $co_tables = modApiStaticFunc('Checkout', 'getTables'); $orders_table = $co_tables['orders']['columns']; $order_prices_table = $co_tables['order_prices']['columns']; $query = new DB_Select(); $query->addSelectTable('orders'); $query->addSelectField($order_prices_table['order_total'], 'order_total'); $query->addSelectField($orders_table['payment_status_id'], 'payment_status_id'); $query->addSelectField($order_prices_table['currency_code'], 'currency_code'); $query->WhereValue($order_prices_table['currency_type'], DB_EQ, CURRENCY_TYPE_MAIN_STORE_CURRENCY); $query->WhereAnd(); $query->Where($orders_table['id'], DB_IN, "('" . implode("','", $this->orders_ids) . "')"); $query->addLeftJoin('order_prices', $orders_table['id'], DB_EQ, $order_prices_table['order_id']); $rows = $application->db->getDB_Result($query); $amount = 0.0; $fully_paid_amount = 0.0; $main_store_currency = modApiFunc("Localization", "getCurrencyCodeById", modApiFunc("Localization", "getMainStoreCurrency")); foreach ($rows as $order_info) { $order_main_currency = $order_info['currency_code']; $order_total = $order_info['order_total']; if ($order_main_currency != $main_store_currency) { $order_total = modApiFunc('Currency_Converter', 'convert', $order_total, $order_main_currency, $main_store_currency); } $amount += $order_total; if ($order_info['payment_status_id'] == ORDER_PAYMENT_STATUS_FULLY_PAID) { $fully_paid_amount += $order_total; } } $query = new DB_Select(); $query->addSelectTable('orders'); $query->addSelectField($query->fMax($orders_table['date']), 'max_date'); $query->addSelectField($query->fMin($orders_table['date']), 'min_date'); $query->Where($orders_table['id'], DB_IN, "('" . implode("','", $this->orders_ids) . "')"); $res = $application->db->getDB_Result($query); $this->orders_summary = array('amount' => $amount, 'max_date' => $res[0]['max_date'], 'min_date' => $res[0]['min_date'], 'fully_paid_amount' => $fully_paid_amount); }
/** * Sets up "is_selected" in false, and also "is_active" in false in all * modules, except the passed in ones. It sets "is_selected" in true in all * passed modules,that exist in the database. It adds the modules, that don't * exist in the table. So that it should be specified in the inputted data * which data should be added as "active", and which of them shouldn't. * * Parameters have a complicated structure, because words Selected and Active * for modules depend: if a module is not Selected, it can't be Active. * And also because the status Selected/non-Selected is usually changed for * several modules at once. Administrator choses, which modules should be * Selected, which of them are non-Selected and then presses the button: * save the changes. */ function setSelectedModules($modules, $modulesType, $b_settings_table_is_empty = false) { global $application; //The list of modules,which should become selected. $selected_modules_ids = array(); foreach ($modules as $module_id => $module_settings) { $selected_modules_ids[] = "'" . $module_id . "'"; } $tables = Checkout::getTables(); $columns = $tables['checkout_pm_sm_settings']['columns']; $YES = "1"; $NO = "2"; //Sets up "is_selected" in false, and also "is_active" in false in all modules, except the passed in ones. if (count($selected_modules_ids) != 0) { $query = new DB_Update('checkout_pm_sm_settings'); $query->addUpdateExpression($columns['status_selected_value_id'], $NO); $query->addUpdateExpression($columns['status_active_value_id'], $NO); $query->WhereField($columns['module_id'], DB_NIN, "(" . implode(",", $selected_modules_ids) . ")"); $query->WhereAnd(); $query->WhereValue($columns['module_group'], DB_EQ, $modulesType); $application->db->getDB_Result($query); } //Set "is_selected" in true, and also sort_order in all passed modules that exist in the database. //It adds the modules, that don't exist in the table. So that it should be specified in the inputted data //which data should be added as "active", and which of them shouldn't. //First get the list of modules, entered to the database: //_print($selected_modules_ids);die("full stop"); if ($b_settings_table_is_empty === true) { $modules_already_in_db = array(); } else { $modules_already_in_db = $this->getSelectedModules($modulesType); } foreach ($modules as $module_id => $module_settings) { if (!array_key_exists($module_id, $modules_already_in_db)) { //The module doesn't exist in the database. //Add module settings to the database. // Checkout::getPaymentModuleInfo() , // , isActive() // , checkout_pm_sm_settings. $mm_info = Checkout::getInstalledModulesListData($modulesType, NULL, true); $m_name = ""; foreach ($mm_info as $key => $info) { if ($info->UUID == $module_settings['module_id']) { $m_name = $info->name; break; } } $db_insert = new DB_Insert('checkout_pm_sm_settings'); $db_insert->addInsertValue($module_settings['module_id'], $columns['module_id']); $db_insert->addInsertValue($m_name, $columns['module_class_name']); $db_insert->addInsertValue($module_settings['module_group'], $columns['module_group']); $db_insert->addInsertValue($NO, $columns['status_active_value_id']); $db_insert->addInsertValue($module_settings['b_is_selected'] === true ? $YES : $NO, $columns['status_selected_value_id']); $db_insert->addInsertValue($module_settings['sort_order'], $columns['sort_order']); $application->db->PrepareSQL($db_insert); //_print($modules);_print($module_settings);_print($application->db->QueryString);die; $application->db->DB_Exec(); Checkout::update_pm_sm_currency_settings($module_settings['module_id'], modApiStaticFunc($m_name, "getInitialCurrencySettings")); } else { //The module exists in the database. Update sort_order and is_selected. $query = new DB_Update('checkout_pm_sm_settings'); $query->addUpdateExpression($columns['status_selected_value_id'], $YES); $query->addUpdateExpression($columns['sort_order'], $module_settings['sort_order']); $query->WhereValue($columns['module_id'], DB_EQ, $module_id); $application->db->getDB_Result($query); } } }
/** * @param int $category_id - ID * @param array $period = ('begin' => timestamp, 'end' => timestamp) - * * @param int $limit - ( * , STAT_NO_LIMIT) * @param int $what_category = STAT_CATEGORY_THIS_ONLY || * STAT_CATEGORY_RECURSIVE - * * @param int $what_products = STAT_PRODUCTS_ALL || * STAT_PRODUCTS_EXISTS_ONLY - , * */ function getProductsSellingStat($category_id, $period, $limit = STAT_NO_LIMIT, $what_category = STAT_CATEGORY_THIS_ONLY, $what_products = STAT_PRODUCTS_EXISTS_ONLY) { global $application; $tables = $this->getTables(); $ps_table = $tables['stat_products_sold']['columns']; $categories_ids = array(); if ($what_category == STAT_CATEGORY_RECURSIVE) { $categories = modApiFunc('Catalog', 'getSubcategoriesFullListWithParent', $category_id, false, false); foreach ($categories as $cat_info) { $categories_ids[] = $cat_info['id']; } } else { $categories_ids[] = $category_id; } $query = new DB_Select(); $query->addSelectField($ps_table['product_id'], 'product_id'); $query->addSelectField($query->fSum($ps_table['quantity']), 'sum_quantity'); $query->addSelectTable('stat_products_sold'); $query->WhereValue($ps_table['categories_ids'], DB_REGEXP, '[[.vertical-line.]]' . implode('|', $categories_ids) . '[[.vertical-line.]]'); $query->WhereAND(); $query->Where($ps_table['time'], DB_GTE, $period['begin']); $query->WhereAND(); $query->Where($ps_table['time'], DB_LTE, $period['end']); if ($what_products == STAT_PRODUCTS_EXISTS_ONLY) { $catalog_tables = modApiStaticFunc('Catalog', 'getTables'); $query->addSelectTable('products'); $query->WhereAND(); $query->WhereField($ps_table['product_id'], DB_EQ, $catalog_tables['products']['columns']['id']); } $query->SelectGroup('product_id'); $query->SelectOrder('sum_quantity', 'DESC'); if ($limit != STAT_NO_LIMIT) { $query->SelectLimit(0, $limit); } return $application->db->getDB_Result($query); }