public static function apiUpdateOrder($order, $response) { if (!defined('ORDER_MANAGEMENT')) { define('ORDER_MANAGEMENT', true); } if (!empty($order['status'])) { $statuses = fn_get_statuses(STATUSES_ORDER, false, true); if (!isset($statuses[$order['status']])) { $response->addError('ERROR_OBJECT_UPDATE', str_replace('[object]', 'orders', __('twgadmin_wrong_api_object_data'))); } else { fn_change_order_status($order['order_id'], $order['status']); } } $cart = array(); fn_clear_cart($cart, true); $customer_auth = fn_fill_auth(array(), array(), false, 'C'); fn_form_cart($order['order_id'], $cart, $customer_auth); $cart['order_id'] = $order['order_id']; // update only profile data $profile_data = fn_check_table_fields($order, 'user_profiles'); $cart['user_data'] = fn_array_merge($cart['user_data'], $profile_data); $cart['user_data'] = fn_array_merge($cart['user_data'], $order); fn_calculate_cart_content($cart, $customer_auth, 'A', true, 'I'); if (!empty($order['details'])) { db_query('UPDATE ?:orders SET details = ?s WHERE order_id = ?i', $order['details'], $order['order_id']); } if (!empty($order['notes'])) { $cart['notes'] = $order['notes']; } fn_update_payment_surcharge($cart, $customer_auth); list($order_id, $process_payment) = fn_place_order($cart, $customer_auth, 'save'); return array($order_id, $process_payment); }
static function clear($changed_tables) { $tags = array(); foreach ($changed_tables as $table => $flag) { if (!empty(self::$_cache_handlers[$table])) { $tags = fn_array_merge($tags, array_keys(self::$_cache_handlers[$table]), false); } } self::$db->query("DELETE FROM cache WHERE tags IN ('" . implode("', '", $tags) . "')"); self::$db->query("REPLACE INTO cache (name, data) VALUES ('cache_handlers', '" . sqlite_escape_string(serialize(self::$_cache_handlers)) . "')"); return true; }
static function clear($changed_tables) { $tags = array(); foreach ($changed_tables as $table => $flag) { if (!empty(self::$_cache_handlers[$table])) { $tags = fn_array_merge($tags, array_keys(self::$_cache_handlers[$table]), false); } } db_query("DELETE FROM ?:cache WHERE tags IN (?a)", $tags); db_query("REPLACE INTO ?:cache ?e", array('name' => 'cache_handlers', 'data' => serialize(self::$_cache_handlers))); return true; }
function fn_google_anaylitics_send($account, $order_info, $refuse = false) { $url = 'http://www.google-analytics.com/collect'; $sign = $refuse == true ? '-' : ''; //Common data which should be sent with any request $required_data = array('v' => '1', 'tid' => $account, 'cid' => md5($order_info['email']), 'ti' => $order_info['order_id'], 'cu' => $order_info['secondary_currency']); $transaction = array('t' => 'transaction', 'tr' => $sign . $order_info['total'], 'ts' => $sign . $order_info['shipping_cost'], 'tt' => $sign . $order_info['tax_subtotal']); $result = Http::get($url, fn_array_merge($required_data, $transaction)); foreach ($order_info['products'] as $item) { $item = array('t' => 'item', 'in' => $item['product'], 'ip' => fn_format_price($item['subtotal'] / $item['amount']), 'iq' => $sign . $item['amount'], 'ic' => $item['product_code'], 'iv' => fn_ga_get_main_category($item['product_id'], $order_info['lang_code'])); $result = Http::get($url, fn_array_merge($required_data, $item)); } }
static function clear($changed_tables) { $tags = array(); foreach ($changed_tables as $table => $flag) { if (!empty(self::$_cache_handlers[$table])) { $tags = fn_array_merge($tags, array_keys(self::$_cache_handlers[$table]), false); } } foreach ($tags as $tag) { fn_rm(DIR_CACHE . $tag, true); } fn_put_contents(DIR_CACHE . self::$_handlers_name, serialize(self::$_cache_handlers)); return true; }
private function _prepareAnywhere() { $company_suburb = Registry::get('settings.Company.company_suburb'); $code = $this->_shipping_info['service_params']['temando_method']; $origination = $this->_shipping_info['package_info']['origination']; $location = $this->_shipping_info['package_info']['location']; if ($code != 'Door to Door') { $x = array('originState' => $origination['state'], 'originCity' => $origination['city'], 'destinationState' => $location['state'], 'destinationCity' => $location['city']); } else { $x = array('originSuburb' => !empty($company_suburb) ? $company_suburb : $origination['city'], 'destinationSuburb' => $location['suburb']); } $where = array('itemNature' => 'Domestic', 'itemMethod' => $code, 'originCountry' => 'AU', 'originCode' => $origination['zipcode'], 'destinationCountry' => 'AU', 'destinationCode' => $location['zipcode'], 'destinationIs' => 'Residence', 'originIs' => 'Business'); return fn_array_merge($where, $x); }
/** * Gets storage object instance * * @param string $type type of storage * @param array $options options * @return Storage storage object instance */ public static function instance($type, $options = array()) { $options = empty($options) ? Registry::get('runtime.storage') : $options; $storage = $options['storage']; if (empty($storage)) { throw new DeveloperException('Storage: undefined storage backend'); } if (!Registry::get('config.storage.' . $type)) { throw new DeveloperException('Storage: undefined storage type - ' . $type); } if (empty(self::$_instance[$storage])) { $class = '\\Tygh\\Backend\\Storage\\' . ucfirst($storage); self::$_instance[$storage] = new $class(); } self::$_instance[$storage]->options = fn_array_merge($options, Registry::get('config.storage.' . $type)); self::$_instance[$storage]->type = $type; return self::$_instance[$storage]; }
/** * Loads received language variables into language cache * * @param array $var_names Language variable that to be loaded * @param string $lang_code 2-letter language code * * @return boolean True if any of received language variables were added into cache; false otherwise */ public static function preloadLangVars($var_names, $lang_code = CART_LANGUAGE) { Registry::registerCache('lang_cache', array('language_values', 'ult_language_values'), Registry::cacheLevel('dispatch'), true); $values = Registry::get('lang_cache.' . $lang_code); if (empty($values)) { $values = array(); } $var_names = array_diff($var_names, array_keys($values)); if ($var_names) { foreach ($var_names as $index => $var_name) { $var_names[$index] = strtolower($var_name); if (isset($values[$var_name])) { unset($var_names[$index]); } } if (empty($var_names)) { return true; } $fields = array('lang.name' => true, 'lang.value' => true); $tables = array('?:language_values lang'); $left_join = array(); $condition = array(db_quote('lang.lang_code = ?s', $lang_code), db_quote('lang.name IN (?a)', $var_names)); $params = array(); fn_set_hook('get_lang_var', $fields, $tables, $left_join, $condition, $params); $joins = !empty($left_join) ? ' LEFT JOIN ' . implode(', ', $left_join) : ''; $new_values = db_get_hash_single_array('SELECT ' . implode(', ', array_keys($fields)) . ' FROM ' . implode(', ', $tables) . $joins . ' WHERE ' . implode(' AND ', $condition), array('name', 'value')); foreach ($var_names as $var_name) { if (!isset($new_values[$var_name])) { $new_values[$var_name] = '_' . $var_name; } } $values = fn_array_merge($values, $new_values); Registry::set('lang_cache.' . $lang_code, $values); return true; } return false; }
function fn_update_image_pairs($icons, $detailed, $pairs_data, $object_id = 0, $object_type = 'product_lists', $object_ids = array(), $update_alt_desc = true, $lang_code = CART_LANGUAGE) { $pair_ids = array(); if (!empty($pairs_data)) { foreach ($pairs_data as $k => $p_data) { $data = array(); $pair_id = !empty($p_data['pair_id']) ? $p_data['pair_id'] : 0; $o_id = !empty($object_id) ? $object_id : (!empty($p_data['object_id']) ? $p_data['object_id'] : 0); if ($o_id == 0 && !empty($object_ids[$k])) { $o_id = $object_ids[$k]; } elseif (!empty($object_ids) && empty($object_ids[$k])) { continue; } // Check if main pair is exists if (empty($pair_id) && !empty($p_data['type']) && $p_data['type'] == 'M') { $pair_data = db_get_row("SELECT pair_id, image_id, detailed_id FROM ?:images_links WHERE object_id = ?i AND object_type = ?s AND type = ?s", $o_id, $object_type, $p_data['type']); $pair_id = !empty($pair_data['pair_id']) ? $pair_data['pair_id'] : 0; } else { $pair_data = db_get_row("SELECT image_id, detailed_id FROM ?:images_links WHERE pair_id = ?i", $pair_id); if (empty($pair_data)) { $pair_id = 0; } } // Update detailed image if (!empty($detailed[$k]) && !empty($detailed[$k]['size'])) { if (fn_get_image_size($detailed[$k]['path'])) { $data['detailed_id'] = fn_update_image($detailed[$k], !empty($pair_data['detailed_id']) ? $pair_data['detailed_id'] : 0, 'detailed'); } } // Update icon if (!empty($icons[$k]) && !empty($icons[$k]['size'])) { if (fn_get_image_size($icons[$k]['path'])) { $data['image_id'] = fn_update_image($icons[$k], !empty($pair_data['image_id']) ? $pair_data['image_id'] : 0, $object_type); } } // Update alt descriptions if ((empty($data) && !empty($pair_id) || !empty($data)) && $update_alt_desc == true) { $image_ids = array(); if (!empty($pair_id)) { $image_ids = db_get_row("SELECT image_id, detailed_id FROM ?:images_links WHERE pair_id = ?i", $pair_id); } $image_ids = fn_array_merge($image_ids, $data); $fields = array('detailed', 'image'); foreach ($fields as $field) { if (!empty($image_ids[$field . '_id']) && isset($p_data[$field . '_alt'])) { if (!is_array($p_data[$field . '_alt'])) { $_data = array('description' => empty($p_data[$field . '_alt']) ? '' : trim($p_data[$field . '_alt']), 'object_holder' => 'images'); // check, if this is new record, create new descriptions for all languages $is_exists = db_get_field('SELECT object_id FROM ?:common_descriptions WHERE object_id = ?i AND lang_code = ?s AND object_holder = ?s', $image_ids[$field . '_id'], $lang_code, 'images'); if (!$is_exists) { fn_create_description('common_descriptions', 'object_id', $image_ids[$field . '_id'], $_data); } else { db_query('UPDATE ?:common_descriptions SET ?u WHERE object_id = ?i AND lang_code = ?s AND object_holder = ?s', $_data, $image_ids[$field . '_id'], $lang_code, 'images'); } } else { foreach ($p_data[$field . '_alt'] as $lc => $_v) { $_data = array('object_id' => $image_ids[$field . '_id'], 'description' => empty($_v) ? '' : trim($_v), 'lang_code' => $lc, 'object_holder' => 'images'); db_query("REPLACE INTO ?:common_descriptions ?e", $_data); } } } } } if (empty($data)) { continue; } // Pair is exists $data['position'] = !empty($p_data['position']) ? $p_data['position'] : 0; // set data position if (!empty($pair_id)) { db_query("UPDATE ?:images_links SET ?u WHERE pair_id = ?i", $data, $pair_id); } else { $data['type'] = $p_data['type']; // set link type $data['object_id'] = $o_id; // assign pair to object $data['object_type'] = $object_type; $pair_id = db_query("INSERT INTO ?:images_links ?e", $data); } $pairs_data[$k]['pair_id'] = $pair_id; $pair_ids[] = $pair_id; } } fn_set_hook('update_image_pairs', $pair_ids, $icons, $detailed, $pairs_data, $object_id, $object_type, $object_ids, $update_alt_desc, $lang_code); return $pair_ids; }
if (!empty($registers)) { foreach ($registers as $register_id => $register) { $spsr_invoices = db_get_array("SELECT * FROM ?:rus_spsr_invoices WHERE order_id = ?i AND register_id = ?i ", $order_info['order_id'], $register['register_id']); if (!empty($spsr_invoices)) { $_invoices = array(); foreach ($spsr_invoices as $invoice) { $_invoices[] = $invoice['invoice_number']; if (!empty($invoice['invoice_number'])) { $spsr_invoice_info[$invoice['invoice_number']] = $invoice; } unset($spsr_shipments[$invoice['shipment_id']]); } $spsr_couriers = RusSpsr::WAGetActiveOrders(); Tygh::$app['view']->assign('spsr_couriers', $spsr_couriers); $invoice_info = RusSpsr::WAGetInvoiceInfo($_invoices); $spsr_invoice_info = fn_array_merge($invoice_info, $spsr_invoice_info); if (!empty($invoice_info)) { $spsr_register = 1; } } if ($register['status'] == 'S') { $register_status = 'Y'; } } Tygh::$app['view']->assign('spsr_invoice_info', $spsr_invoice_info); } Tygh::$app['view']->assign('spsr_register_status', $register_status); Tygh::$app['view']->assign('spsr_register', $spsr_register); foreach ($spsr_shipments as $shipment) { $shipping_data = fn_get_shipping_info($shipment['shipping_id'], DESCR_SL); $shipping_data['rate'] = $order_info['shipping_cost'];
/** * Returns array of setting item data from xml node * @param $xml_node * @return array */ protected function _getSettingItem($xml_node) { $addon_id = (string) $this->_xml->id; $default_language = $this->getDefaultLanguage(); foreach (fn_get_translation_languages() as $lang_code => $_v) { $items[$lang_code] = $this->getPoValues($lang_code, 'SettingsOptions'); } if (isset($xml_node['id'])) { $_types = $this->_getTypes(); $translations = $this->_getTranslations($xml_node, 'SettingsOptions', $addon_id); $tooltip_translations = $this->_getTranslations($xml_node, 'SettingsTooltips', $addon_id, 'tooltip'); $setting = array('edition_type' => $this->_getEditionType($xml_node), 'id' => (string) $xml_node['id'], 'name' => isset($items[$default_language][(string) $xml_node['id']]) ? $items[$default_language][(string) $xml_node['id']] : (string) $xml_node->name, 'type' => isset($_types[(string) $xml_node->type]) ? $_types[(string) $xml_node->type] : '', 'translations' => fn_array_merge($translations, $tooltip_translations), 'default_value' => isset($xml_node->default_value) ? (string) $xml_node->default_value : '', 'variants' => $this->_getVariants($xml_node), 'handler' => isset($xml_node->handler) ? (string) $xml_node->handler : '', 'parent_id' => isset($xml_node['parent_id']) ? (string) $xml_node['parent_id'] : ''); return $setting; } else { return array(); } }
/** * Init backend * * @param array $config global configuration params * @param array $params additional params passed from Session class * * @return bool true if backend was init correctly, false otherwise */ public function __construct($config, $params = array()) { parent::__construct($config, $params); $this->config = fn_array_merge(array('redis_server' => $config['session_redis_server'], 'saas_uid' => !empty($config['saas_uid']) ? $config['saas_uid'] : null), $this->config); return $this->connect(); }
if (!defined('BOOTSTRAP')) { die('Access denied'); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { // // Creation gift certificate // if ($mode == 'create_gift_certificate') { $change_return_status = $_REQUEST['change_return_status']; if (!empty($_REQUEST['accepted'])) { $total = 0; $return_info = fn_get_return_info($change_return_status['return_id']); foreach ((array) $_REQUEST['accepted'] as $item_id => $v) { if (isset($v['chosen']) && $v['chosen'] == 'Y') { $total += $v['amount'] * $return_info['items'][RETURN_PRODUCT_ACCEPTED][$item_id]['price']; } } if ($total > 0) { $certificate = fn_create_return_gift_certificate($return_info['order_id'], fn_format_price($total)); $return_info['extra'] = unserialize($return_info['extra']); if (!isset($return_info['extra']['gift_certificates'])) { $return_info['extra']['gift_certificates'] = array(); } $return_info['extra']['gift_certificates'] = fn_array_merge($return_info['extra']['gift_certificates'], $certificate); $_data = array('extra' => serialize($return_info['extra'])); db_query("UPDATE ?:rma_returns SET ?u WHERE return_id = ?i", $_data, $change_return_status['return_id']); } } return array(CONTROLLER_STATUS_REDIRECT, 'rma.details?return_id=' . $change_return_status['return_id']); } }
/** * Parses request URL to use in request * @param string $method request method * @param string $url request URL * @param mixed $data request data * @return array parsed URL and URL-encoded data */ private static function _prepareData($method, $url, $data) { $components = parse_url($url); $upass = ''; if (!empty($components['user'])) { $upass = $components['user'] . (!empty($components['pass']) ? ':' . $components['pass'] : '') . '@'; } if (empty($components['path'])) { $components['path'] = '/'; } $port = empty($components['port']) ? '' : ':' . $components['port']; $url = $components['scheme'] . '://' . $upass . $components['host'] . $port . $components['path']; if (!empty($components['query'])) { if ($method == self::GET) { parse_str($components['query'], $args); if (!empty($data) && !is_array($data) && !empty($args)) { throw new DeveloperException('Http: incompatible data type passed'); } $data = fn_array_merge($args, $data); } else { $url .= '?' . $components['query']; } } return array($url, is_array($data) ? http_build_query($data) : $data); }
/** * Gets all available patterns for the section * * @param string $section section to get patterns for * @param string $get_for get import or export patterns * @return array */ function fn_get_patterns($section, $get_for) { // Get core patterns $files = fn_get_dir_contents(Registry::get('config.dir.schemas') . 'exim', false, true, '.php'); foreach (Registry::get('addons') as $addon_name => $addon_data) { if ($addon_data['status'] != 'A') { continue; } $schema_dir = Registry::get('config.dir.addons') . $addon_name . '/schemas/exim'; if (is_dir($schema_dir)) { $_files = fn_get_dir_contents($schema_dir, false, true, '.php'); foreach ($_files as $key => $filename) { if (strpos($filename, '.post.php') !== false) { unset($_files[$key]); } } if (!empty($_files)) { $files = fn_array_merge($files, $_files, false); } } } $patterns = array(); $sections = array(); foreach ($files as $schema_file) { if (strpos($schema_file, '.functions.') !== false) { // skip functions schema definition continue; } $pattern_id = str_replace('.php', '', $schema_file); $pattern = fn_get_pattern_definition($pattern_id, $get_for); if (empty($pattern) || !fn_check_pattern_permissions($pattern, $get_for, $_SESSION['auth']['user_id'])) { continue; } $sections[$pattern['section']] = array('title' => __($pattern['section']), 'href' => 'exim.' . Registry::get('runtime.mode') . '?section=' . $pattern['section']); if ($pattern['section'] == $section) { $patterns[$pattern_id] = $pattern; } } if (Registry::get('runtime.company_id')) { $schema = fn_get_permissions_schema('vendor'); // Check if the selected section is available if (isset($schema[$get_for]['sections'][$section]['permission']) && !$schema[$get_for]['sections'][$section]['permission']) { return array('', ''); } if (!empty($schema[$get_for]['sections'])) { foreach ($schema[$get_for]['sections'] as $section_id => $data) { if (isset($data['permission']) && !$data['permission']) { unset($sections[$section_id]); } } } if (!empty($schema[$get_for]['patterns'])) { foreach ($schema[$get_for]['patterns'] as $pattern_id => $data) { if (isset($data['permission']) && !$data['permission']) { unset($patterns[$pattern_id]); } } } } ksort($sections, SORT_STRING); uasort($patterns, 'fn_sort_patterns'); return array($sections, $patterns); }
function fn_create_return_gift_certificate($order_id, $amount) { $min = Registry::get('addons.gift_certificates.min_amount') * 1; $max = Registry::get('addons.gift_certificates.max_amount') * 1; $order_info = fn_get_order_info($order_id); $templates = fn_get_gift_certificate_templates(); $_data = array('send_via' => 'E', 'recipient' => "{$order_info['firstname']} {$order_info['lastname']}", 'sender' => Registry::get('settings.Company.company_name'), 'amount' => $amount, 'email' => $order_info['email'], 'address' => $order_info['s_address'], 'address_2' => $order_info['s_address_2'], 'city' => $order_info['s_city'], 'country' => $order_info['s_country'], 'state' => $order_info['s_state'], 'zipcode' => $order_info['s_zipcode'], 'phone' => $order_info['phone'], 'template' => key($templates)); if (fn_allowed_for('ULTIMATE')) { $_data['company_id'] = Registry::ifGet('runtime.company_id', $order_info['company_id']); } do { $code = fn_generate_gift_certificate_code(); } while (true == fn_check_gift_certificate_code($code)); if ($amount < $min || $amount > $max) { fn_set_notification('E', __('error'), __('gift_cert_error_amount', array('[min]' => $min, '[max]' => $max))); $result = array(); } else { $_data = fn_array_merge($_data, array('gift_cert_code' => $code, 'timestamp' => TIME)); $gift_cert_id = db_query('INSERT INTO ?:gift_certificates ?e', $_data); $result = array($gift_cert_id => array('code' => $code, 'amount' => $amount)); } return $result; }
/** * Reads directory * @param string $path path to directory * @param string $base_path path to root directory * @return array list of directories/files */ function fn_te_read_dir($path, $base_path) { $items = array(); clearstatcache(); $path = rtrim($path, '/'); if ($dh = @opendir($path)) { $dirs = array(); $files = array(); while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..' || fn_te_filter_path($path . '/' . $file)) { continue; } if (is_dir($path . '/' . $file)) { $dirs[$file] = array('name' => $file, 'type' => 'D', 'full_path' => fn_te_form_path(str_replace($base_path, '', $path . '/' . $file)), 'path' => fn_te_form_path(str_replace($base_path, '', $path . '/'))); } if (is_file($path . '/' . $file)) { $files[$file] = array('name' => $file, 'type' => 'F', 'ext' => fn_get_file_ext($file), 'full_path' => fn_te_form_path(str_replace($base_path, '', $path . '/' . $file)), 'path' => fn_te_form_path(str_replace($base_path, '', $path . '/'))); } } closedir($dh); ksort($dirs, SORT_STRING); ksort($files, SORT_STRING); $items = fn_array_merge($dirs, $files, false); } return $items; }
/** * 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; }
} fn_recalculate_exceptions($_REQUEST['product_id']); $suffix = ".exceptions?product_id={$_REQUEST['product_id']}"; } if ($mode == 'm_delete_exceptions') { foreach ($_REQUEST['exception_ids'] as $id) { fn_delete_exception($id); } $suffix = ".exceptions?product_id={$_REQUEST['product_id']}"; } } if ($mode == 'add_combinations') { if (is_array($_REQUEST['add_inventory'])) { foreach ($_REQUEST['add_inventory'] as $k => $v) { $_data = array('product_id' => $_REQUEST['product_id'], 'combination' => $_REQUEST['add_options_combination'][$k], 'amount' => isset($_REQUEST['add_inventory'][$k]['amount']) ? $_REQUEST['add_inventory'][$k]['amount'] : 0); $_data = fn_array_merge($v, $_data); fn_update_option_combination($_data); } } $suffix = ".inventory?product_id={$_REQUEST['product_id']}"; } if ($mode == 'update_combinations') { if (!empty($_REQUEST['inventory'])) { foreach ($_REQUEST['inventory'] as $k => $v) { fn_update_option_combination($v, $k); } } $suffix = ".inventory?product_id={$_REQUEST['product_id']}"; } if ($mode == 'm_delete_combinations') { foreach ($_REQUEST['combination_hashes'] as $v) {
/** * Installes addon * * @param string $addon Addon to install * @param bool $show_notification Display notification if set to true * @param bool $install_demo If defined as true, addon's demo data will be installed * @return bool True if addons installed successfully, false otherwise */ function fn_install_addon($addon, $show_notification = true, $install_demo = false) { $status = db_get_field("SELECT status FROM ?:addons WHERE addon = ?s", $addon); // Return true if addon is installed if (!empty($status)) { return true; } $addon_scheme = SchemesManager::getScheme($addon); if (empty($addon_scheme)) { // Required add-on was not found in store. return false; } // Unmanaged addons can be installed via console only if ($addon_scheme->getUnmanaged() && !defined('CONSOLE')) { return false; } if ($addon_scheme != false) { // Register custom classes Registry::get('class_loader')->add('', Registry::get('config.dir.addons') . $addon); if ($addon_scheme->isPromo()) { $texts = fn_get_addon_permissions_text(); fn_set_notification('E', __('error'), $texts['text']); return false; } $_data = array('addon' => $addon_scheme->getId(), 'priority' => $addon_scheme->getPriority(), 'dependencies' => implode(',', $addon_scheme->getDependencies()), 'conflicts' => implode(',', $addon_scheme->getConflicts()), 'requirements' => $addon_scheme->getRequirements(), 'version' => $addon_scheme->getVersion(), 'separate' => $addon_scheme->getSettingsLayout() == 'separate' ? 1 : 0, 'has_icon' => $addon_scheme->hasIcon(), 'unmanaged' => $addon_scheme->getUnmanaged(), 'status' => 'D'); // Check system requirements (needed versions, installed extensions, etc.) if (!$addon_scheme->checkRequirements($_data['requirements'])) { return false; } $dependencies = SchemesManager::getInstallDependencies($_data['addon']); if (!empty($dependencies)) { fn_set_notification('W', __('warning'), __('text_addon_install_dependencies', array('[addon]' => implode(',', $dependencies)))); return false; } if ($addon_scheme->callCustomFunctions('before_install') == false) { fn_uninstall_addon($addon, false); return false; } // Add add-on to registry Registry::set('addons.' . $addon, array('status' => 'D', 'priority' => $_data['priority'])); // Execute optional queries if ($addon_scheme->processQueries('install', Registry::get('config.dir.addons') . $addon) == false) { fn_uninstall_addon($addon, false); return false; } if (fn_update_addon_settings($addon_scheme) == false) { fn_uninstall_addon($addon, false); return false; } db_query("REPLACE INTO ?:addons ?e", $_data); foreach ($addon_scheme->getAddonTranslations() as $translation) { db_query("REPLACE INTO ?:addon_descriptions ?e", array('lang_code' => $translation['lang_code'], 'addon' => $addon_scheme->getId(), 'name' => $translation['value'], 'description' => $translation['description'])); } if ($original = $addon_scheme->getOriginals()) { db_query("REPLACE INTO ?:original_values ?e", array('msgctxt' => 'Addon:' . $addon, 'msgid' => $original['name'])); db_query("REPLACE INTO ?:original_values ?e", array('msgctxt' => 'AddonDescription:' . $addon, 'msgid' => $original['description'])); } // Install templates fn_install_addon_templates($addon_scheme->getId()); // Put this addon settings to the registry $settings = Settings::instance()->getValues($addon_scheme->getId(), Settings::ADDON_SECTION, false); if (!empty($settings)) { Registry::set('settings.' . $addon, $settings); $addon_data = Registry::get('addons.' . $addon); Registry::set('addons.' . $addon, fn_array_merge($addon_data, $settings)); } // Add optional language variables $language_variables = $addon_scheme->getLanguageValues(false); if (!empty($language_variables)) { db_query('REPLACE INTO ?:language_values ?m', $language_variables); } // Get only original values $language_variables = $addon_scheme->getLanguageValues(true); if (!empty($language_variables)) { db_query('REPLACE INTO ?:original_values ?m', $language_variables); } if (fn_allowed_for('ULTIMATE')) { foreach (fn_get_all_companies_ids() as $company) { ProductTabs::instance($company)->createAddonTabs($addon_scheme->getId(), $addon_scheme->getTabOrder()); } } else { ProductTabs::instance()->createAddonTabs($addon_scheme->getId(), $addon_scheme->getTabOrder()); } // Execute custom functions if ($addon_scheme->callCustomFunctions('install') == false) { fn_uninstall_addon($addon, false); return false; } if ($show_notification == true) { fn_set_notification('N', __('notice'), __('text_addon_installed', array('[addon]' => $addon_scheme->getName()))); } // If we need to activate addon after install, call "update status" procedure if ($addon_scheme->getStatus() != 'D') { fn_update_addon_status($addon, $addon_scheme->getStatus(), false); } if (file_exists(Registry::get('config.dir.addons') . $addon . '/layouts.xml')) { if (fn_allowed_for('ULTIMATE')) { foreach (fn_get_all_companies_ids() as $company) { $layouts = Layout::instance($company)->getList(); foreach ($layouts as $layout_id => $layout) { Exim::instance($company, $layout_id)->importFromFile(Registry::get('config.dir.addons') . $addon . '/layouts.xml'); } } } else { $layouts = Layout::instance()->getList(); foreach ($layouts as $layout_id => $layout) { Exim::instance(0, $layout_id)->importFromFile(Registry::get('config.dir.addons') . $addon . '/layouts.xml'); } } } // Clean cache fn_clear_cache(); if ($install_demo) { $addon_scheme->processQueries('demo', Registry::get('config.dir.addons') . $addon); if ($addon_scheme->callCustomFunctions('demo') == false) { fn_uninstall_addon($addon, false); return false; } } return true; } else { // Addon was not installed because scheme is not exists. return false; } }
return array(CONTROLLER_STATUS_DENIED); } $order_info = fn_get_order_info($_REQUEST['order_id']); if (!empty($order_info['is_parent_order']) && $order_info['is_parent_order'] == 'Y') { $order_info['child_ids'] = implode(',', db_get_fields("SELECT order_id FROM ?:orders WHERE parent_order_id = ?i", $_REQUEST['order_id'])); } if (!empty($order_info)) { Tygh::$app['view']->assign('order_info', $order_info); } } fn_add_breadcrumb(__('landing_header')); } elseif ($mode == 'process_payment') { if (fn_allow_place_order($cart, $auth) == true) { $order_info = $cart; $order_info['products'] = $cart['products']; $order_info = fn_array_merge($order_info, $cart['user_data']); $order_info['order_id'] = $order_id = TIME . "_" . (!empty($auth['user_id']) ? $auth['user_id'] : 0); unset($order_info['user_data']); list($is_processor_script, $processor_data) = fn_check_processor_script($order_info['payment_id']); if ($is_processor_script) { set_time_limit(300); fn_define('IFRAME_MODE', true); include Registry::get('config.dir.payments') . $processor_data['processor_script']; fn_finish_payment($order_id, $pp_response, array()); fn_order_placement_routines('route', $order_id); } } } if (fn_cart_is_empty($cart) && !isset($force_redirection) && !in_array($mode, array('clear', 'delete', 'cart', 'update', 'apply_coupon', 'shipping_estimation', 'update_shipping', 'complete'))) { fn_set_notification('W', __('cart_is_empty'), __('cannot_proccess_checkout', 'K', 'cannot_proccess_checkout')); return array(CONTROLLER_STATUS_REDIRECT, 'checkout.cart');
$company_data = !empty($company_id) ? fn_get_company_data($company_id) : array(); if ($mode == 'update' && empty($company_data)) { return array(CONTROLLER_STATUS_NO_PAGE); } if (fn_allowed_for('MULTIVENDOR')) { if (!empty($company_id)) { $company_data['logos'] = fn_get_logos($company_id); } Tygh::$app['view']->assign('logo_types', fn_get_logo_types(true)); } $restored_company_data = fn_restore_post_data('company_data'); if (!empty($restored_company_data) && $mode == 'add') { if (!empty($restored_company_data['shippings'])) { $restored_company_data['shippings'] = implode(',', $restored_company_data['shippings']); } $company_data = fn_array_merge($company_data, $restored_company_data); } if (fn_allowed_for('ULTIMATE')) { if ($mode == 'update') { $available_themes = fn_get_available_themes(fn_get_theme_path('[theme]', 'C', $company_id)); $theme_name = fn_get_theme_path('[theme]', 'C', $company_id); $layout = Layout::instance($company_id)->getDefault($theme_name); $style = Styles::factory($theme_name)->get($layout['style_id']); Tygh::$app['view']->assign('current_style', $style); Tygh::$app['view']->assign('theme_info', $available_themes['current']); } $countries_list = fn_get_simple_countries(); if (!empty($company_data['countries_list'])) { if (!is_array($company_data['countries_list'])) { $company_countries = explode(',', $company_data['countries_list']); } else {
/** * Get directory contents * * @param string $dir directory path * @param bool $get_dirs get sub directories * @param bool $get_files * @param mixed $extension allowed file extensions * @param string $prefix file/dir path prefix * @return array $contents directory contents */ function fn_get_dir_contents($dir, $get_dirs = true, $get_files = false, $extension = '', $prefix = '', $recursive = false, $exclude = array()) { $contents = array(); if (is_dir($dir)) { if ($dh = opendir($dir)) { // $extention - can be string or array. Transform to array. $extension = is_array($extension) ? $extension : array($extension); while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..' || in_array($file, $exclude)) { continue; } if ($recursive == true && is_dir($dir . '/' . $file)) { $contents = fn_array_merge($contents, fn_get_dir_contents($dir . '/' . $file, $get_dirs, $get_files, $extension, $prefix . $file . '/', $recursive, $exclude), false); } if (is_dir($dir . '/' . $file) && $get_dirs == true || is_file($dir . '/' . $file) && $get_files == true) { if ($get_files == true && !fn_is_empty($extension)) { // Check all extentions for file foreach ($extension as $_ext) { if (substr($file, -strlen($_ext)) == $_ext) { $contents[] = $prefix . $file; break; } } } else { $contents[] = $prefix . $file; } } } closedir($dh); } } asort($contents, SORT_STRING); return $contents; }
function fn_wishlist_get_gift_certificate_info(&$_certificate, &$certificate, &$type) { if ($type == 'W' && is_numeric($certificate)) { $_certificate = fn_array_merge($_SESSION['wishlist']['gift_certificates'][$certificate], array('gift_cert_wishlist_id' => $certificate)); } }
// if (!defined('AREA')) { die('Access denied'); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Define trusted variables that shouldn't be stripped fn_trusted_vars('gift_cert_data'); if ($mode == 'add') { if (!empty($_REQUEST['gift_cert_data'])) { do { $code = fn_generate_gift_certificate_code(); } while (true == fn_check_gift_certificate_code($code)); $gift_cert_data = $_REQUEST['gift_cert_data']; fn_correct_gift_certificate($gift_cert_data); $_data = fn_check_table_fields($gift_cert_data, 'gift_certificates'); $_data = fn_array_merge($_data, array('gift_cert_code' => $code, 'timestamp' => TIME)); if (!empty($_data['products'])) { $_data['products'] = serialize($_data['products']); } $gift_cert_id = db_query("INSERT INTO ?:gift_certificates ?e", $_data); $gift_cert_data = fn_get_gift_certificate_info($gift_cert_id); fn_gift_certificate_notification($gift_cert_data, fn_get_notification_rules($_REQUEST)); $suffix = ".update?gift_cert_id={$gift_cert_id}"; } } if ($mode == 'update') { if (!empty($_REQUEST['gift_cert_data'])) { $gift_cert_data = $_REQUEST['gift_cert_data']; fn_correct_gift_certificate($gift_cert_data); if (!isset($gift_cert_data['products'])) { $gift_cert_data['products'] = array();
function fn_reward_points_change_order_status(&$status_to, &$status_from, &$order_info, &$force_notification, &$order_statuses, &$place_order) { static $log_id; if (isset($order_info['deleted_order'])) { if (!empty($log_id)) { $log_item = array('action' => CHANGE_DUE_ORDER_DELETE); db_query("UPDATE ?:reward_point_changes SET ?u WHERE change_id = ?i", $log_item, $log_id); } return true; } $points_info = isset($order_info['points_info']) ? $order_info['points_info'] : array(); if (!empty($points_info)) { $reason = array('order_id' => $order_info['order_id'], 'to' => $status_to, 'from' => $status_from); $action = empty($place_order) ? CHANGE_DUE_ORDER : CHANGE_DUE_ORDER_PLACE; if ($order_statuses[$status_to]['params']['inventory'] == 'I' && $order_statuses[$status_from]['params']['inventory'] == 'D') { if (!empty($points_info['in_use']['points'])) { // increase points in use $log_id = fn_change_user_points($points_info['in_use']['points'], $order_info['user_id'], serialize(fn_array_merge($reason, array('text' => 'text_increase_points_in_use'))), $action); } if ($points_info['is_gain'] == 'Y' && !empty($points_info['reward'])) { // decrease earned points $log_id = fn_change_user_points(-$points_info['reward'], $order_info['user_id'], serialize($reason), $action); db_query("DELETE FROM ?:order_data WHERE order_id = ?i AND type = ?s", $order_info['order_id'], ORDER_DATA_POINTS_GAIN); } } if ($order_statuses[$status_to]['params']['inventory'] == 'D' && $order_statuses[$status_from]['params']['inventory'] == 'I') { if (!empty($points_info['in_use']['points'])) { // decrease points in use if ($points_info['in_use']['points'] > fn_get_user_additional_data(POINTS, $order_info['user_id'])) { fn_set_notification('W', __('warning'), __('text_order_status_has_not_been_changed')); $status_to = $status_from; } else { $log_id = fn_change_user_points(-$points_info['in_use']['points'], $order_info['user_id'], serialize(fn_array_merge($reason, array('text' => 'text_decrease_points_in_use'))), $action); } } } if ($status_to == 'C' && $points_info['is_gain'] == 'N' && !empty($points_info['reward'])) { // increase rewarded points $log_id = fn_change_user_points($points_info['reward'], $order_info['user_id'], serialize($reason), $action); $order_data = array('order_id' => $order_info['order_id'], 'type' => ORDER_DATA_POINTS_GAIN, 'data' => 'Y'); db_query("REPLACE INTO ?:order_data ?e", $order_data); } } }
function fn_update_gift_certificate($gift_cert_data, $gift_cert_id = 0, $params = array()) { fn_correct_gift_certificate($gift_cert_data); $gift_cert_data['products'] = !empty($gift_cert_data['products']) ? serialize($gift_cert_data['products']) : ''; if (empty($gift_cert_id)) { do { $code = fn_generate_gift_certificate_code(); } while (true == fn_check_gift_certificate_code($code)); $gift_cert_data = fn_array_merge($gift_cert_data, array('gift_cert_code' => $code, 'timestamp' => TIME)); if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) { $gift_cert_data['company_id'] = Registry::get('runtime.company_id'); } $gift_cert_id = db_query("INSERT INTO ?:gift_certificates ?e", $gift_cert_data); } else { // Change certfificate status fn_change_gift_certificate_status($gift_cert_id, $gift_cert_data['status'], '', fn_get_notification_rules(array(), false)); //if difference then add line in log $debit_info = db_get_row("SELECT debit AS amount, debit_products AS products FROM ?:gift_certificates_log WHERE gift_cert_id = ?i ORDER BY timestamp DESC", $gift_cert_id); if (empty($debit_info)) { $debit_info = db_get_row("SELECT amount, products FROM ?:gift_certificates WHERE gift_cert_id = ?i", $gift_cert_id); } $is_diff = $gift_cert_data['amount'] - $debit_info['amount'] != 0 || md5($gift_cert_data['products']) != md5($debit_info['products']); if ($is_diff == true) { $_info = array('amount' => $gift_cert_data['amount'], 'products' => $gift_cert_data['products']); fn_add_gift_certificate_log_record($gift_cert_id, $debit_info, $_info); } //Update certificate data $_data = $gift_cert_data; db_query("UPDATE ?:gift_certificates SET ?u WHERE gift_cert_id = ?i", $gift_cert_data, $gift_cert_id); } $gc_data = fn_get_gift_certificate_info($gift_cert_id); fn_gift_certificate_notification($gc_data, fn_get_notification_rules($params)); return $gift_cert_id; }
/** * Serialize promotion conditions for search * * @param array $conditions conditions * @param boolean $plain flag - return as string (true) or array (false) * @return mixed serialized data */ function fn_promotion_serialize($conditions, $plain = true) { $result = array(); foreach ($conditions as $c) { if (!empty($c['conditions'])) { $result = fn_array_merge($result, fn_promotion_serialize($c['conditions']), false); } elseif (isset($c['value'])) { if ($c['condition'] == 'auto_coupons' || $c['condition'] == 'coupon_code') { $vals = explode(',', $c['value']); foreach ($vals as $v) { $result[] = $c['condition'] . '=' . $v; } } else { if (is_array($c['value'])) { $c['value'] = implode(',', array_keys($c['value'])); } $result[] = $c['condition'] . '=' . $c['value']; } } } return $plain == true ? implode(';', $result) : $result; }
/** * Init search view params * * @param string $object object to init view for * @param array $params request parameters * @return array filtered params */ public function update($object, $params) { if (!empty($params['skip_view'])) { return $params; } $this->_checkUpdateActions($object, $params); if (!empty($params['view_id'])) { $data = $this->getViewParams($params['view_id']); if (!empty($data)) { $result['view_id'] = $params['view_id']; $result = fn_array_merge($params, $data); if (!empty($params['sort_by'])) { $result['sort_by'] = $params['sort_by']; } if (!empty($params['sort_order'])) { $result['sort_order'] = $params['sort_order']; } db_query("UPDATE ?:views SET active = IF(view_id = ?i, 'Y', 'N') WHERE user_id = ?i AND object = ?s", $params['view_id'], $this->_auth['user_id'], $object); return $result; } } return $params; }
public function GetCategoryFeatures($category_id, $features_list = array()) { $credentials = $this->credentials; $features = ''; if (!empty($features_list)) { $features = '<FeatureID>' . implode('</FeatureID><FeatureID>', $features_list) . '</FeatureID>'; } $xml = <<<EOT <?xml version="1.0" encoding="utf-8"?> <GetCategoryFeaturesRequest xmlns="urn:ebay:apis:eBLBaseComponents"> {$credentials} <CategoryID>{$category_id}</CategoryID> {$features} <DetailLevel>ReturnAll</DetailLevel> <ViewAllNodes>true</ViewAllNodes> </GetCategoryFeaturesRequest> EOT; list($trans_id, $result) = $this->_request($xml, 'GetCategoryFeatures'); $features = array(); if ($result->Ack == 'Success' && ($result->Category || $result->SiteDefaults)) { if ($result->SiteDefaults) { $features = (array) $result->SiteDefaults; $features['ListingDurationIds'] = $this->_convertListingDuration($result->SiteDefaults); } if ($result->Category) { $features = fn_array_merge($features, (array) $result->Category); $features['ListingDurationIds'] = $this->_convertListingDuration($result->SiteDefaults); } $features['listing_duration'] = array(); foreach ($result->FeatureDefinitions->ListingDurations[0] as $key => $value) { foreach ($value->attributes() as $a => $b) { if ((string) $a == 'durationSetID' && (int) $b == $features['ListingDurationIds']['FixedPriceItem']) { foreach ($value->Duration as $v) { $features['listing_duration'][] = (string) $v; } } } } } return array($trans_id, $features); }