function fn_update_paypal_settings($settings) { if (isset($settings['pp_statuses'])) { $settings['pp_statuses'] = serialize($settings['pp_statuses']); } foreach ($settings as $setting_name => $setting_value) { Settings::instance()->updateValue($setting_name, $setting_value); } //Get company_ids for which we should update logos. If root admin click 'update for all', get all company_ids if (isset($settings['pp_logo_update_all_vendors']) && $settings['pp_logo_update_all_vendors'] == 'Y') { $company_ids = db_get_fields('SELECT company_id FROM ?:companies'); $company_id = array_shift($company_ids); } elseif (!Registry::get('runtime.simple_ultimate')) { $company_id = Registry::get('runtime.company_id'); } else { $company_id = 1; } //Use company_id as pair_id fn_attach_image_pairs('paypal_logo', 'paypal_logo', $company_id); if (isset($company_ids)) { foreach ($company_ids as $logo_id) { fn_clone_image_pairs($logo_id, $company_id, 'paypal_logo'); } } }
function fn_advanced_menu_update_category_pre(&$category_data, $category_id, $lang_code) { if (isset($category_data['advanced_menu'])) { $category_data['advanced_menu'] = serialize($category_data['advanced_menu']); } if (!empty($category_id)) { fn_attach_image_pairs('menu_image', 'menu', $category_id, $lang_code); } }
public function update($id, $params) { $data = array(); $status = Response::STATUS_BAD_REQUEST; unset($params['category_id']); $lang_code = $this->safeGet($params, 'lang_code', DEFAULT_LANGUAGE); $category_id = fn_update_category($params, $id, $lang_code); $this->prepareImages($params, $id); $updated = fn_attach_image_pairs('category_main', 'category', $id, DESCR_SL); if ($category_id || $updated) { if ($updated && fn_notification_exists('extra', '404')) { fn_delete_notification('404'); } $status = Response::STATUS_OK; $data = array('category_id' => $id); } return array('status' => $status, 'data' => $data); }
/** * Updates product option * * @param array $option_data option data array * @param int $option_id option ID (empty if we're adding the option) * @param string $lang_code language code to add/update option for * @return int ID of the added/updated option */ function fn_update_product_option($option_data, $option_id = 0, $lang_code = DESCR_SL) { /** * Changes parameters before update option data * * @param array $option_data Option data * @param int $option_id Option identifier * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) */ fn_set_hook('update_product_option_pre', $option_data, $option_id, $lang_code); // Add option if (empty($option_id)) { if (empty($option_data['product_id'])) { $option_data['product_id'] = 0; } $option_data['option_id'] = $option_id = db_query('INSERT INTO ?:product_options ?e', $option_data); foreach (fn_get_translation_languages() as $option_data['lang_code'] => $_v) { db_query("INSERT INTO ?:product_options_descriptions ?e", $option_data); } $create = true; // Update option } else { // if option inventory changed from Y to N, we should clear option combinations if (!empty($option_data['product_id']) && !empty($option_data['inventory']) && $option_data['inventory'] == 'N') { $condition = fn_get_company_condition('?:product_options.company_id'); $old_option_inventory = db_get_field("SELECT inventory FROM ?:product_options WHERE option_id = ?i {$condition}", $option_id); if ($old_option_inventory == 'Y') { $inventory_filled = db_get_field('SELECT COUNT(*) FROM ?:product_options_inventory WHERE product_id = ?i', $option_data['product_id']); if ($inventory_filled) { fn_delete_product_option_combinations($option_data['product_id']); } } } if (fn_allowed_for('ULTIMATE') && !empty($option_data['product_id']) && fn_ult_is_shared_product($option_data['product_id']) == 'Y') { $product_company_id = db_get_field('SELECT company_id FROM ?:products WHERE product_id = ?i', $option_data['product_id']); $option_id = fn_ult_update_shared_product_option($option_data, $option_id, Registry::ifGet('runtime.company_id', $product_company_id), $lang_code); if (Registry::get('runtime.company_id') && Registry::get('runtime.company_id') != $product_company_id) { $deleted_variants = array(); fn_set_hook('update_product_option_post', $option_data, $option_id, $deleted_variants, $lang_code); return $option_id; } } db_query("UPDATE ?:product_options SET ?u WHERE option_id = ?i", $option_data, $option_id); db_query("UPDATE ?:product_options_descriptions SET ?u WHERE option_id = ?i AND lang_code = ?s", $option_data, $option_id, $lang_code); } if (fn_allowed_for('ULTIMATE')) { // options of shared product under the shared store hasn't a company_id. No necessary for updating. if (!empty($option_data['company_id'])) { fn_ult_update_share_object($option_id, 'product_options', $option_data['company_id']); } if (!empty($option_data['product_id'])) { fn_ult_share_product_option($option_id, $option_data['product_id']); } } if (!empty($option_data['variants'])) { $var_ids = array(); // Generate special variants structure for checkbox (2 variants, 1 hidden) if ($option_data['option_type'] == 'C') { $option_data['variants'] = array_slice($option_data['variants'], 0, 1); // only 1 variant should be here reset($option_data['variants']); $_k = key($option_data['variants']); $option_data['variants'][$_k]['position'] = 1; // checked variant $v_id = db_get_field("SELECT variant_id FROM ?:product_option_variants WHERE option_id = ?i AND position = 0", $option_id); $option_data['variants'][] = array('position' => 0, 'variant_id' => $v_id); } $variant_images = array(); foreach ($option_data['variants'] as $k => $v) { if ((!isset($v['variant_name']) || $v['variant_name'] == '') && $option_data['option_type'] != 'C') { continue; } // Update product options variants if (isset($v['modifier'])) { $v['modifier'] = floatval($v['modifier']); if (floatval($v['modifier']) > 0) { $v['modifier'] = '+' . $v['modifier']; } } if (isset($v['weight_modifier'])) { $v['weight_modifier'] = floatval($v['weight_modifier']); if (floatval($v['weight_modifier']) > 0) { $v['weight_modifier'] = '+' . $v['weight_modifier']; } } // if (isset($v['set_by_user'])) { // // } $v['option_id'] = $option_id; if (empty($v['variant_id']) || !empty($v['variant_id']) && !db_get_field("SELECT variant_id FROM ?:product_option_variants WHERE variant_id = ?i", $v['variant_id'])) { $v['variant_id'] = db_query("INSERT INTO ?:product_option_variants ?e", $v); foreach (fn_get_translation_languages() as $v['lang_code'] => $_v) { db_query("INSERT INTO ?:product_option_variants_descriptions ?e", $v); } } else { db_query("DELETE FROM ?:product_option_variants_disabled WHERE product_id=?i AND option_id =?i AND variant_id=?i", $option_data['extraProductId'], $option_id, $v['variant_id']); if ($v['status'] == 'Y') { $vd = array('product_id' => $option_data['extraProductId'], 'option_id' => $option_id, 'variant_id' => $v['variant_id']); db_query("INSERT INTO ?:product_option_variants_disabled ?e", $vd); unset($v['status']); } db_query("UPDATE ?:product_option_variants SET ?u WHERE variant_id = ?i", $v, $v['variant_id']); db_query("UPDATE ?:product_option_variants_descriptions SET ?u WHERE variant_id = ?i AND lang_code = ?s", $v, $v['variant_id'], $lang_code); } $var_ids[] = $v['variant_id']; if ($option_data['option_type'] == 'C') { fn_delete_image_pairs($v['variant_id'], 'variant_image'); // force deletion of variant image for "checkbox" option } else { $variant_images[$k] = $v['variant_id']; } } if ($option_data['option_type'] != 'C' && !empty($variant_images)) { fn_attach_image_pairs('variant_image', 'variant_image', 0, $lang_code, $variant_images); } // Delete obsolete variants $condition = !empty($var_ids) ? db_quote('AND variant_id NOT IN (?n)', $var_ids) : ''; $deleted_variants = db_get_fields("SELECT variant_id FROM ?:product_option_variants WHERE option_id = ?i {$condition}", $option_id, $var_ids); if (!empty($deleted_variants)) { db_query("DELETE FROM ?:product_option_variants WHERE variant_id IN (?n)", $deleted_variants); db_query("DELETE FROM ?:product_option_variants_descriptions WHERE variant_id IN (?n)", $deleted_variants); foreach ($deleted_variants as $v_id) { fn_delete_image_pairs($v_id, 'variant_image'); } } } if (!fn_allowed_for('ULTIMATE:FREE')) { // Rebuild exceptions if (!empty($create) && !empty($option_data['product_id'])) { fn_update_exceptions($option_data['product_id']); } } /** * Update product option (running after fn_update_product_option() function) * * @param array $option_data Array with option data * @param int $option_id Option identifier * @param array $deleted_variants Array with deleted variants ids * @param string $lang_code Language code to add/update option for */ fn_set_hook('update_product_option_post', $option_data, $option_id, $deleted_variants, $lang_code); return $option_id; }
/** * Create/Update shipping name * * @param array $shipping_data shipping info * @param int $shipping_id shipping identifier * @param string $lang_code 2-letter language code (e.g. 'en', 'ru', etc.) * @return string Shipping name if shipping identifier is not null; false otherwise */ function fn_update_shipping($shipping_data, $shipping_id, $lang_code = DESCR_SL) { if (!empty($shipping_data['shipping']) || !empty($shipping_id)) { $shipping_data['localization'] = empty($shipping_data['localization']) ? '' : fn_implode_localizations($shipping_data['localization']); $shipping_data['tax_ids'] = !empty($shipping_data['tax_ids']) ? fn_create_set($shipping_data['tax_ids']) : ''; $shipping_data['usergroup_ids'] = empty($shipping_data['usergroup_ids']) ? USERGROUP_ALL : (is_array($shipping_data['usergroup_ids']) ? implode(',', $shipping_data['usergroup_ids']) : $shipping_data['usergroup_ids']); unset($shipping_data['shipping_id']); if (isset($shipping_data['rate_calculation']) && $shipping_data['rate_calculation'] == 'M') { $shipping_data['service_id'] = 0; $shipping_data['service_params'] = array(); } if (isset($shipping_data['service_params'])) { $shipping_data['service_params'] = serialize($shipping_data['service_params']); } fn_set_hook('update_shipping', $shipping_data, $shipping_id, $lang_code); if (!empty($shipping_id)) { $action = 'update'; $arow = db_query("UPDATE ?:shippings SET ?u WHERE shipping_id = ?i", $shipping_data, $shipping_id); db_query("UPDATE ?:shipping_descriptions SET ?u WHERE shipping_id = ?i AND lang_code = ?s", $shipping_data, $shipping_id, $lang_code); if ($arow === false) { fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('shipping'))), '', '404'); $shipping_id = false; } } else { $action = 'add'; $shipping_id = $shipping_data['shipping_id'] = db_query("INSERT INTO ?:shippings ?e", $shipping_data); foreach (fn_get_translation_languages() as $shipping_data['lang_code'] => $_v) { db_query("INSERT INTO ?:shipping_descriptions ?e", $shipping_data); } } fn_set_hook('update_shipping_post', $shipping_data, $shipping_id, $lang_code, $action); if ($shipping_id) { fn_attach_image_pairs('shipping', 'shipping', $shipping_id, $lang_code); if (!empty($shipping_data['rates'])) { fn_update_shipping_rates($shipping_data, $shipping_id); } } } return $shipping_id; }
function fn_update_product_feature($feature_data, $feature_id, $lang_code = DESCR_SL) { $deleted_variants = array(); // If this feature belongs to the group, get categories assignment from this group if (!empty($feature_data['parent_id'])) { $gdata = db_get_row("SELECT categories_path, display_on_product, display_on_catalog FROM ?:product_features WHERE feature_id = ?i", $feature_data['parent_id']); $feature_data = fn_array_merge($feature_data, $gdata); } if (!intval($feature_id)) { // check for intval as we use "0G" for new group $feature_data['feature_id'] = $feature_id = db_query("INSERT INTO ?:product_features ?e", $feature_data); foreach (Registry::get('languages') as $feature_data['lang_code'] => $_d) { db_query("INSERT INTO ?:product_features_descriptions ?e", $feature_data); } } else { db_query("UPDATE ?:product_features SET ?u WHERE feature_id = ?i", $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 this feature is group, set its categories to all children if ($feature_data['feature_type'] == 'G') { $u = array('categories_path' => $feature_data['categories_path'], 'display_on_product' => $feature_data['display_on_product'], 'display_on_catalog' => $feature_data['display_on_catalog']); db_query("UPDATE ?:product_features SET ?u WHERE parent_id = ?i", $u, $feature_id); } // Delete variants for simple features if (strpos('SMNE', $feature_data['feature_type']) === false) { $var_ids = db_get_fields("SELECT variant_id FROM ?:product_feature_variants WHERE feature_id = ?i", $feature_id); if (!empty($var_ids)) { db_query("DELETE FROM ?:product_feature_variants WHERE variant_id IN (?n)", $var_ids); db_query("DELETE FROM ?:product_feature_variant_descriptions WHERE variant_id IN (?n)", $var_ids); db_query("DELETE FROM ?:product_features_values WHERE variant_id IN (?n)", $var_ids); foreach ($var_ids as $v_id) { fn_delete_image_pairs($v_id, 'feature_variant'); } } } elseif (!empty($feature_data['variants'])) { $var_ids = array(); foreach ($feature_data['variants'] as $k => $v) { if (empty($v['variant'])) { continue; } $v['feature_id'] = $feature_id; if (empty($v['variant_id'])) { $v['variant_id'] = db_query("INSERT INTO ?:product_feature_variants ?e", $v); foreach (Registry::get('languages') as $v['lang_code'] => $_v) { db_query("INSERT INTO ?:product_feature_variant_descriptions ?e", $v); } } else { db_query("UPDATE ?:product_feature_variants SET ?u WHERE variant_id = ?i", $v, $v['variant_id']); db_query("UPDATE ?:product_feature_variant_descriptions SET ?u WHERE variant_id = ?i AND lang_code = ?s", $v, $v['variant_id'], $lang_code); } if ($feature_data['feature_type'] == 'N') { // number db_query('UPDATE ?:product_features_values SET ?u WHERE variant_id = ?i AND lang_code = ?s', array('value_int' => $v['variant']), $v['variant_id'], $lang_code); } $var_ids[$k] = $v['variant_id']; $feature_data['variants'][$k]['variant_id'] = $v['variant_id']; // for addons } if (!empty($var_ids)) { fn_attach_image_pairs('variant_image', 'feature_variant', 0, $lang_code, $var_ids); } // Delete obsolete variants $deleted_variants = db_get_fields("SELECT variant_id FROM ?:product_feature_variants WHERE feature_id = ?i AND variant_id NOT IN (?n)", $feature_id, $var_ids); if (!empty($deleted_variants)) { db_query("DELETE FROM ?:product_feature_variants WHERE variant_id IN (?n)", $deleted_variants); db_query("DELETE FROM ?:product_feature_variant_descriptions WHERE variant_id IN (?n)", $deleted_variants); db_query("DELETE FROM ?:product_features_values WHERE variant_id IN (?n)", $deleted_variants); foreach ($deleted_variants as $v_id) { fn_delete_image_pairs($v_id, 'feature_variant'); } } } fn_set_hook('update_product_feature', $feature_data, $feature_id, $deleted_variants, $lang_code); return $feature_id; }
if ($mode == 'add_combinations') { if (is_array($_REQUEST['add_inventory'])) { foreach ($_REQUEST['add_inventory'] as $k => $v) { $combination_hash = fn_generate_cart_id($_REQUEST['product_id'], array('product_options' => $_REQUEST['add_options_combination'][$k])); $combination = fn_get_options_combination($_REQUEST['add_options_combination'][$k]); $product_code = fn_get_product_code($_REQUEST['product_id'], $_REQUEST['add_options_combination'][$k]); $_data = array('product_id' => $_REQUEST['product_id'], 'combination_hash' => $combination_hash, 'combination' => $combination, 'product_code' => !empty($product_code) ? $product_code : ''); $_data = fn_array_merge($v, $_data); db_query("REPLACE INTO ?:product_options_inventory ?e", $_data); } } $suffix = ".inventory?product_id={$_REQUEST['product_id']}"; } if ($mode == 'update_combinations') { // Updating images fn_attach_image_pairs('combinations', 'product_option', 0, CART_LANGUAGE, array()); $inventory = db_get_hash_array("SELECT * FROM ?:product_options_inventory WHERE product_id = ?i", 'combination_hash', $_REQUEST['product_id']); foreach ($inventory as $i) { $inventory_ids[] = $i['combination_hash']; } fn_attach_aditional_image_pairs('product_option_add_additional', 'product_option', 0, CART_LANGUAGE, $inventory_ids); if (!empty($_REQUEST['inventory'])) { foreach ($_REQUEST['inventory'] as $k => $v) { db_query("UPDATE ?:product_options_inventory SET ?u WHERE combination_hash = ?s", $v, $k); if ($inventory[$k]['amount'] <= 0 && $v['amount'] > 0) { fn_send_product_notifications($_REQUEST['product_id']); } } } $suffix = ".inventory?product_id={$_REQUEST['product_id']}"; }
* This is commercial software, only users who have purchased a valid * * license and accept to the terms of the License Agreement can install * * and use this program. * * * **************************************************************************** * PLEASE READ THE FULL TEXT OF THE SOFTWARE LICENSE AGREEMENT IN THE * * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE. * ****************************************************************************/ use Tygh\Registry; if (!defined('BOOTSTRAP')) { die('Access denied'); } fn_trusted_vars("processor_params", "payment_data"); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($mode == 'update') { $payment_id = fn_attach_image_pairs('path_stamp', 'stamp', $_REQUEST['payment_id'], DESCR_SL); } return array(CONTROLLER_STATUS_OK, "payments.manage"); } if ($mode == 'update' || $mode == 'manage') { $processors = Tygh::$app['view']->getTemplateVars('payment_processors'); if (!empty($processors)) { $rus_payments = array(); foreach (fn_get_schema('rus_payments', 'processors') as $rus_payment) { $rus_payments[$rus_payment['processor']] = $rus_payment; } foreach ($processors as &$processor) { $processor['position'] = 'default_' . $processor['processor']; if (!empty($rus_payments[$processor['processor']])) { $processor['russian'] = 'Y'; $processor['type'] = 'R';
function fn_banners_update_banner($data, $banner_id, $lang_code = DESCR_SL) { if (isset($data['timestamp'])) { $data['timestamp'] = fn_parse_date($data['timestamp']); } $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']); if (!empty($banner_id)) { db_query("UPDATE ?:banners SET ?u WHERE banner_id = ?i", $data, $banner_id); db_query("UPDATE ?:banner_descriptions SET ?u WHERE banner_id = ?i AND lang_code = ?s", $data, $banner_id, $lang_code); $banner_image_id = fn_get_banner_image_id($banner_id, $lang_code); $banner_image_exist = !empty($banner_image_id); $banner_is_multilang = Registry::get('addons.banners.banner_multilang') == 'Y'; $image_is_update = fn_banners_need_image_update(); if ($banner_is_multilang) { if ($banner_image_exist && $image_is_update) { fn_delete_image_pairs($banner_image_id, 'promo'); db_query("DELETE FROM ?:banner_images WHERE banner_id = ?i AND lang_code = ?s", $banner_id, $lang_code); $banner_image_exist = false; } } else { if (isset($data['url'])) { db_query("UPDATE ?:banner_descriptions SET url = ?s WHERE banner_id = ?i", $data['url'], $banner_id); } } if ($image_is_update && !$banner_image_exist) { $banner_image_id = db_query("INSERT INTO ?:banner_images (banner_id, lang_code) VALUE(?i, ?s)", $banner_id, $lang_code); } $pair_data = fn_attach_image_pairs('banners_main', 'promo', $banner_image_id, $lang_code); if (!$banner_is_multilang && !$banner_image_exist) { fn_banners_image_all_links($banner_id, $pair_data, $lang_code); } } else { $banner_id = $data['banner_id'] = db_query("REPLACE INTO ?:banners ?e", $data); foreach (Languages::getAll() as $data['lang_code'] => $v) { db_query("REPLACE INTO ?:banner_descriptions ?e", $data); } if (fn_banners_need_image_update()) { $data_banner_image = array('banner_id' => $banner_id, 'lang_code' => $lang_code); $banner_image_id = db_get_next_auto_increment_id('banner_images'); $pair_data = fn_attach_image_pairs('banners_main', 'promo', $banner_image_id, $lang_code); if (!empty($pair_data)) { db_query("INSERT INTO ?:banner_images ?e", $data_banner_image); fn_banners_image_all_links($banner_id, $pair_data, $lang_code); } } } return $banner_id; }
function fn_update_configurator_group($data, $group_id, $lang_code = DESCR_SL) { if (!empty($group_id)) { db_query('UPDATE ?:conf_groups SET ?u WHERE group_id = ?i', $data, $group_id); db_query('UPDATE ?:conf_group_descriptions SET ?u WHERE group_id = ?i AND lang_code = ?s', $data, $group_id, $lang_code); } else { $group_id = $data['group_id'] = db_query('INSERT INTO ?:conf_groups ?e', $data); foreach ((array) Registry::get('languages') as $data['lang_code'] => $_v) { db_query("INSERT INTO ?:conf_group_descriptions ?e", $data); } } // Updating category images fn_attach_image_pairs('configurator_main', 'conf_group', $group_id, $lang_code); // Update group products db_query("DELETE FROM ?:conf_group_products WHERE group_id = ?i", $group_id); if (!empty($data['product_ids'])) { $p_ids = explode(',', $data['product_ids']); foreach ($p_ids as $p_id) { db_query("INSERT INTO ?:conf_group_products (group_id, product_id) VALUES (?i, ?i)", $group_id, $p_id); } } return $group_id; }
function fn_projects_update_page_post($page_data, $page_id, $lang_code, $create, $old_page_data) { if (!empty($page_data['page_type']) && $page_data['page_type'] == PAGE_TYPE_PROJECTS) { fn_attach_image_pairs('projects_image', 'projects', $page_id, $lang_code); db_query("REPLACE INTO ?:projects_authors ?e", array('page_id' => $page_id, 'user_id' => $_SESSION['auth']['user_id'])); } }
function fn_update_shipping($data, $shipping_id, $lang_code = DESCR_SL) { $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']); $data['tax_ids'] = !empty($data['tax_ids']) ? fn_create_set($data['tax_ids']) : ''; $data['usergroup_ids'] = empty($data['usergroup_ids']) ? '' : implode(',', $data['usergroup_ids']); fn_set_hook('update_shipping', $data, $shipping_id, $lang_code); if (!empty($shipping_id)) { db_query("UPDATE ?:shippings SET ?u WHERE shipping_id = ?i", $data, $shipping_id); db_query("UPDATE ?:shipping_descriptions SET ?u WHERE shipping_id = ?i AND lang_code = ?s", $data, $shipping_id, $lang_code); } else { $shipping_id = $data['shipping_id'] = db_query("INSERT INTO ?:shippings ?e", $data); foreach ((array) Registry::get('languages') as $data['lang_code'] => $_v) { db_query("INSERT INTO ?:shipping_descriptions ?e", $data); } } if ($shipping_id) { fn_attach_image_pairs('shipping', 'shipping', $shipping_id, $lang_code); } return $shipping_id; }
/** * Adds logo * @param array $logo_data logo data (layout_id, image path, type) * @param integer $company_id company ID * @return integer ID of created logo */ function fn_create_logo($logo_data, $company_id = null) { $condition = ''; if (!empty($logo_data['layout_id'])) { $condition .= db_quote(" AND layout_id = ?i", $logo_data['layout_id']); } if (!empty($company_id)) { $condition .= db_quote(" AND company_id = ?i", $company_id); } $logo_id = db_get_field("SELECT logo_id FROM ?:logos WHERE type = ?s ?p", $logo_data['type'], $condition); if (empty($logo_id)) { $logo_id = db_query("INSERT INTO ?:logos ?e", array('type' => $logo_data['type'], 'layout_id' => !empty($logo_data['layout_id']) ? $logo_data['layout_id'] : 0, 'company_id' => $company_id)); } if (!empty($logo_data['image_path'])) { if (file_exists($logo_data['image_path'])) { $_REQUEST['logotypes_image_data'] = array(array('type' => 'M', 'object_id' => $logo_id)); $_REQUEST['type_logotypes_image_icon'] = array('server'); $_REQUEST['file_logotypes_image_icon'] = array($logo_data['image_path']); fn_attach_image_pairs('logotypes', 'logos'); } } return $logo_id; }
/** * Save uploaded logo and favicon and return array of their urls * @return Array of Strings */ private static function _saveUploadedLogos() { $logo_names = array('logo', 'favicon'); $options = array(); foreach ($logo_names as $logo_name) { $pair_ids = fn_attach_image_pairs($logo_name, 'twg_logos'); if (!empty($pair_ids)) { $image_id = TwigmoImage::getImageId(array('pair_id' => reset($pair_ids), 'object_type' => 'twg_logos')); $image_data = fn_get_image($image_id, 'twg_logos'); $options[$logo_name . '_url'] = $image_data['http_image_path']; } } return $options; }
function fn_update_store_location($store_location_data, $store_location_id, $lang_code = DESCR_SL) { $store_location_data['localization'] = empty($store_location_data['localization']) ? '' : fn_implode_localizations($store_location_data['localization']); if (empty($store_location_id)) { if (empty($store_location_data['position'])) { $store_location_data['position'] = db_get_field('SELECT MAX(position) FROM ?:store_locations'); $store_location_data['position'] += 10; } $store_location_id = db_query('INSERT INTO ?:store_locations ?e', $store_location_data); $store_location_data['store_location_id'] = $store_location_id; foreach (fn_get_translation_languages() as $store_location_data['lang_code'] => $v) { db_query("INSERT INTO ?:store_location_descriptions ?e", $store_location_data); } } else { db_query('UPDATE ?:store_locations SET ?u WHERE store_location_id = ?i', $store_location_data, $store_location_id); db_query('UPDATE ?:store_location_descriptions SET ?u WHERE store_location_id = ?i AND lang_code = ?s', $store_location_data, $store_location_id, $lang_code); } // Update main images pair fn_attach_image_pairs('store_locations', 'store_locations', $store_location_id, $lang_code); // Update additional images fn_attach_image_pairs('store_locations_additional', 'store_locations', $store_location_id, $lang_code); // Adding new additional images fn_attach_image_pairs('store_locations_add_additional', 'store_locations', $store_location_id, $lang_code); //die($store_location_id); return $store_location_id; }
function fn_update_watermark_image_settings($wt_settings, $company_id = null, $attached_image_id = null) { if (!($setting_id = Settings::instance()->getId('watermark', ''))) { $setting_id = Settings::instance()->update(array('name' => 'watermark', 'section_id' => 0, 'section_tab_id' => 0, 'type' => 'A', 'position' => 0, 'is_global' => 'N', 'handler' => '')); } Settings::instance()->updateValueById($setting_id, serialize($wt_settings), $company_id); if ($wt_settings['type'] == 'G') { $_REQUEST['wt_image_image_data'][0]['image_alt'] = ''; $_REQUEST['wt_image_image_data'][0]['detailed_alt'] = ''; $image_id = !empty($company_id) ? $company_id : WATERMARK_IMAGE_ID; if (!is_null($attached_image_id)) { fn_clone_image_pairs($image_id, $attached_image_id, 'watermark'); } else { $pair_ids = fn_attach_image_pairs('wt_image', 'watermark', $image_id); if (!empty($pair_ids)) { $attached_image_id = $image_id; } } } return $attached_image_id; }
function fn_blog_update_page_post($page_data, $page_id, $lang_code, $create, $old_page_data) { if (!empty($page_data['page_type']) && $page_data['page_type'] == PAGE_TYPE_BLOG) { fn_attach_image_pairs('blog_image', 'blog', $page_id, $lang_code); db_query("REPLACE INTO ?:blog_authors ?e", array('page_id' => $page_id, 'user_id' => Tygh::$app['session']['auth']['user_id'])); } }
fn_set_notification('N', __('notice'), __('text_products_added')); } } $suffix = ".manage" . (empty($p_ids) ? "" : "?pid[]=" . implode('&pid[]=', $p_ids)); } // // Processing multiple updating of product elements // if ($mode == 'm_update') { // Update multiple products data if (!empty($_REQUEST['products_data'])) { if (fn_allowed_for('MULTIVENDOR') && !fn_company_products_check(array_keys($_REQUEST['products_data']))) { return array(CONTROLLER_STATUS_DENIED); } // Update images fn_attach_image_pairs('product_main', 'product', 0, DESCR_SL); foreach ($_REQUEST['products_data'] as $k => $v) { if (!empty($v['product'])) { // Checking for required fields for new product if (fn_allowed_for('ULTIMATE,MULTIVENDOR') && Registry::get('runtime.company_id')) { unset($v['company_id']); } fn_companies_filter_company_product_categories($_REQUEST, $v); if (!empty($v['category_ids'])) { $v['category_ids'] = explode(',', $v['category_ids']); } fn_update_product($v, $k, DESCR_SL); // Updating products position in category if (isset($v['position']) && !empty($_REQUEST['category_id'])) { db_query("UPDATE ?:products_categories SET position = ?i WHERE category_id = ?i AND product_id = ?i", $v['position'], $_REQUEST['category_id'], $k); }
/** * Import image pair * * @param string $prefix path prefix * @param string $image_file thumbanil path or filename * @param string $detailed_path detailed image path or filename * @param string $type pair type * @param int $object_id ID of object to attach images to * @param string $object name of object to attach images to * @return boolean true if images were imported */ function fn_import_images($prefix, $image_file, $detailed_file, $type, $object_id, $object) { if (!empty($object_id)) { $_REQUEST["server_import_image_icon"] = ''; $_REQUEST["type_import_image_icon"] = ''; // Get image alternative text if exists if (!empty($image_file) && strpos($image_file, '#') !== false) { list($image_file, $image_alt) = explode('#', $image_file); } if (!empty($detailed_file) && strpos($detailed_file, '#') !== false) { list($detailed_file, $detailed_alt) = explode('#', $detailed_file); } $_REQUEST["type_import_image_icon"] = array('server'); $_REQUEST["type_import_image_detailed"] = array('server'); if (($image_file = fn_find_file($prefix, $image_file)) !== false) { $_REQUEST["file_import_image_icon"] = array(str_ireplace(DIR_ROOT, '', $image_file)); } else { $_REQUEST["file_import_image_icon"] = array(); } if (($detailed_file = fn_find_file($prefix, $detailed_file)) !== false) { $_REQUEST["file_import_image_detailed"] = array(str_ireplace(DIR_ROOT, '', $detailed_file)); } else { $_REQUEST["file_import_image_detailed"] = array(); } $_REQUEST['import_image_data'] = array(array('type' => $type, 'image_alt' => !empty($image_alt) ? unserialize($image_alt) : '', 'detailed_alt' => !empty($detailed_alt) ? unserialize($detailed_alt) : '')); return fn_attach_image_pairs('import', $object, $object_id); } }
<?php use Tygh\Registry; if (!defined('BOOTSTRAP')) { die('Access denied'); } $_REQUEST['user_id'] = empty($_REQUEST['user_id']) ? 0 : (int) $_REQUEST['user_id']; if ($_SERVER['REQUEST_METHOD'] == 'POST') { // // Create/update staff member // if ($mode == 'update') { fn_trusted_vars('user_data'); $user_id = fn_staff_update_staff_member_data($_REQUEST['user_data'], $_REQUEST['user_id'], DESCR_SL); if (!empty($user_id)) { fn_attach_image_pairs('staff_member_main', 'staff', $user_id, DESCR_SL); $suffix = ".update?user_id={$user_id}"; } else { $suffix = '.manage'; } } // // Delete product // if ($mode == 'delete') { if (!empty($_REQUEST['user_id'])) { $result = fn_staff_delete_staff_member($_REQUEST['user_id']); if ($result) { fn_set_notification('N', __('notice'), __('text_staff_member_has_been_deleted')); } else { return array(CONTROLLER_STATUS_REDIRECT, 'staff.update?user_id=' . $_REQUEST['user_id']);
function fn_update_banner($data, $banner_id, $lang_code = DESCR_SL) { if (isset($data['timestamp'])) { $data['timestamp'] = fn_parse_date($data['timestamp']); } $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']); if (!empty($banner_id)) { db_query("UPDATE ?:banners SET ?u WHERE banner_id = ?i", $data, $banner_id); db_query("UPDATE ?:banner_descriptions SET ?u WHERE banner_id = ?i AND lang_code = ?s", $data, $banner_id, $lang_code); } else { $banner_id = $data['banner_id'] = db_query("REPLACE INTO ?:banners ?e", $data); foreach ((array) Registry::get('languages') as $data['lang_code'] => $v) { db_query("REPLACE INTO ?:banner_descriptions ?e", $data); } } fn_attach_image_pairs('banners_main', 'banner', $banner_id, $lang_code); return $banner_id; }
function fn_update_static_data($data, $param_id, $section, $lang_code = DESCR_SL) { $current_id_path = ''; $schema = fn_get_schema('static_data', 'schema'); $section_data = $schema[$section]; if (!empty($section_data['has_localization'])) { $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']); } if (!empty($data['megabox'])) { // parse megabox value foreach ($data['megabox']['type'] as $p => $v) { if (!empty($v)) { $data[$p] = $v . ':' . intval($data[$p][$v]) . ':' . $data['megabox']['use_item'][$p]; } else { $data[$p] = ''; } } } if (!empty($param_id)) { $current_id_path = db_get_field("SELECT id_path FROM ?:static_data WHERE param_id = ?i", $param_id); db_query("UPDATE ?:static_data SET ?u WHERE param_id = ?i", $data, $param_id); db_query('UPDATE ?:static_data_descriptions SET ?u WHERE param_id = ?i AND lang_code = ?s', $data, $param_id, $lang_code); } else { $data['section'] = $section; $param_id = $data['param_id'] = db_query("INSERT INTO ?:static_data ?e", $data); foreach ((array) Registry::get('languages') as $data['lang_code'] => $_v) { db_query('REPLACE INTO ?:static_data_descriptions ?e', $data); } } // Generate ID path if (isset($data['parent_id'])) { if (!empty($data['parent_id'])) { $new_id_path = db_get_field("SELECT id_path FROM ?:static_data WHERE param_id = ?i", $data['parent_id']); $new_id_path .= '/' . $param_id; } else { $new_id_path = $param_id; } if (!empty($current_id_path) && $current_id_path != $new_id_path) { db_query("UPDATE ?:static_data SET id_path = CONCAT(?s, SUBSTRING(id_path, ?i)) WHERE id_path LIKE ?l", "{$new_id_path}/", strlen($current_id_path . '/') + 1, "{$current_id_path}/%"); } db_query("UPDATE ?:static_data SET id_path = ?s WHERE param_id = ?i", $new_id_path, $param_id); } if (!empty($section_data['icon'])) { fn_attach_image_pairs('static_data_icon', $section_data['icon']['type'], $param_id, $lang_code); } return $param_id; }
/** * Adds logo * @param array $logo_data logo data (layout_id, image path, type) * @param integer $company_id company ID * @return integer ID of created logo */ function fn_update_logo($logo_data, $company_id = null) { $condition = ''; $logo_data['style_id'] = empty($logo_data['style_id']) ? '' : $logo_data['style_id']; if (!empty($logo_data['layout_id'])) { $condition .= db_quote(" AND layout_id = ?i", $logo_data['layout_id']); } if (!empty($company_id)) { $condition .= db_quote(" AND company_id = ?i", $company_id); } $logo_id = db_get_field("SELECT logo_id FROM ?:logos WHERE type = ?s AND style_id = ?s ?p", $logo_data['type'], $logo_data['style_id'], $condition); if (empty($logo_id)) { if (is_null($company_id)) { // We cannot insert new record with null company_id return false; } $logo_id = db_query("INSERT INTO ?:logos ?e", array('type' => $logo_data['type'], 'layout_id' => !empty($logo_data['layout_id']) ? $logo_data['layout_id'] : 0, 'style_id' => !empty($logo_data['style_id']) ? $logo_data['style_id'] : '', 'company_id' => $company_id)); } else { db_query("UPDATE ?:logos SET ?u WHERE logo_id = ?i", array('type' => $logo_data['type'], 'layout_id' => !empty($logo_data['layout_id']) ? $logo_data['layout_id'] : 0, 'style_id' => !empty($logo_data['style_id']) ? $logo_data['style_id'] : '', 'company_id' => $company_id), $logo_id); } if (!empty($logo_data['image_path'])) { Registry::set('runtime.skip_area_checking', true); Registry::set('runtime.allow_upload_external_paths', true); if (file_exists($logo_data['image_path'])) { $_REQUEST['logotypes_image_data'] = array(array('type' => 'M', 'object_id' => $logo_id)); $_REQUEST['type_logotypes_image_icon'] = array('server'); $_REQUEST['file_logotypes_image_icon'] = array($logo_data['image_path']); fn_attach_image_pairs('logotypes', 'logos'); } Registry::set('runtime.skip_area_checking', false); Registry::set('runtime.allow_upload_external_paths', false); // Clear temporarilty created data unset($_REQUEST['type_logotypes_image_icon'], $_REQUEST['file_logotypes_image_icon'], $_REQUEST['logotypes_image_data']); } return $logo_id; }
function fn_update_banner($data, $banner_id, $lang_code = DESCR_SL) { if (!empty($data['width'])) { $data['width'] = abs(intval($data['width'])); } if (!empty($data['height'])) { $data['height'] = abs(intval($data['height'])); } if ($data['type'] == 'P') { $data['data'] = serialize($data['data']); } if (!empty($banner_id)) { db_query("UPDATE ?:aff_banners SET ?u WHERE banner_id = ?i", $data, $banner_id); db_query("UPDATE ?:aff_banner_descriptions SET ?u WHERE banner_id = ?i AND lang_code = ?s", $data, $banner_id, $lang_code); } else { $banner_id = $data['banner_id'] = db_query("INSERT INTO ?:aff_banners ?e", $data); foreach ((array) Registry::get('languages') as $data['lang_code'] => $v) { db_query("INSERT INTO ?:aff_banner_descriptions ?e", $data); } } if ($data['type'] == 'G') { // Adding banner images pair fn_attach_image_pairs('banner', 'aff_banners', $banner_id, $lang_code); } return $banner_id; }
/** * Import image pair * * @param string $prefix path prefix * @param string $image_file thumbanil path or filename * @param string $detailed_path detailed image path or filename * @param string $position image position * @param string $type pair type * @param int $object_id ID of object to attach images to * @param string $object name of object to attach images to * @return array|bool True if images were imported */ function fn_import_images($prefix, $image_file, $detailed_file, $position, $type, $object_id, $object) { static $updated_products = array(); if (!empty($object_id)) { // Process multilang requests if (!is_array($object_id)) { $object_id = array($object_id); } foreach ($object_id as $_id) { if (empty($updated_products[$_id]) && !empty($_REQUEST['import_options']['remove_images']) && $_REQUEST['import_options']['remove_images'] == 'Y') { $updated_products[$_id] = true; fn_delete_image_pairs($_id, $object, 'A'); } $_REQUEST["server_import_image_icon"] = ''; $_REQUEST["type_import_image_icon"] = ''; // Get image alternative text if exists if (!empty($image_file) && strpos($image_file, '#') !== false) { list($image_file, $image_alt) = explode('#', $image_file); } if (!empty($detailed_file) && strpos($detailed_file, '#') !== false) { list($detailed_file, $detailed_alt) = explode('#', $detailed_file); } if (!empty($image_alt)) { preg_match_all('/\\[([A-Za-z]+?)\\]:(.*?);/', $image_alt, $matches); if (!empty($matches[1]) && !empty($matches[2])) { $image_alt = array_combine(array_values($matches[1]), array_values($matches[2])); } } if (!empty($detailed_alt)) { preg_match_all('/\\[([A-Za-z]+?)\\]:(.*?);/', $detailed_alt, $matches); if (!empty($matches[1]) && !empty($matches[2])) { $detailed_alt = array_combine(array_values($matches[1]), array_values($matches[2])); } } $type_image_detailed = strpos($detailed_file, '://') === false ? 'server' : 'url'; $type_image_icon = strpos($image_file, '://') === false ? 'server' : 'url'; $_REQUEST["type_import_image_icon"] = array($type_image_icon); $_REQUEST["type_import_image_detailed"] = array($type_image_detailed); $image_file = fn_find_file($prefix, $image_file); if ($image_file !== false) { if ($type_image_icon == 'url') { $_REQUEST["file_import_image_icon"] = array($image_file); } elseif (strpos($image_file, Registry::get('config.dir.root')) === 0) { $_REQUEST["file_import_image_icon"] = array(str_ireplace(fn_get_files_dir_path(), '', $image_file)); } else { fn_set_notification('E', __('error'), __('error_images_need_located_root_dir')); $_REQUEST["file_import_image_detailed"] = array(); } } else { $_REQUEST["file_import_image_icon"] = array(); } $detailed_file = fn_find_file($prefix, $detailed_file); if ($detailed_file !== false) { if ($type_image_detailed == 'url') { $_REQUEST["file_import_image_detailed"] = array($detailed_file); } elseif (strpos($detailed_file, Registry::get('config.dir.root')) === 0) { $_REQUEST["file_import_image_detailed"] = array(str_ireplace(fn_get_files_dir_path(), '', $detailed_file)); } else { fn_set_notification('E', __('error'), __('error_images_need_located_root_dir')); $_REQUEST["file_import_image_detailed"] = array(); } } else { $_REQUEST["file_import_image_detailed"] = array(); } $_REQUEST['import_image_data'] = array(array('type' => $type, 'image_alt' => empty($image_alt) ? '' : $image_alt, 'detailed_alt' => empty($detailed_alt) ? '' : $detailed_alt, 'position' => empty($position) ? 0 : $position)); $result = fn_attach_image_pairs('import', $object, $_id); } return $result; } return false; }
$theme = Themes::factory(fn_get_theme_path('[theme]', 'C')); if ($mode == 'save') { $theme_manifest = $theme->getManifest(); if (empty($theme_manifest['converted_to_css'])) { // FIXME: Backward preset compatibility if (!empty($_REQUEST['preset_id'])) { $_REQUEST['style_id'] = $_REQUEST['preset_id']; } if (!empty($_REQUEST['preset'])) { $_REQUEST['style'] = $_REQUEST['preset']; } $style_id = fn_theme_editor_save_style($_REQUEST['style_id'], $_REQUEST['style']); if (!empty($style_id)) { $logos = fn_get_logos(Registry::get('runtime.company_id'), Registry::get('runtime.layout.layout_id'), $style_id); // TODO: Make proper logo saving. Logo will be saved only for active style and not for newly created. fn_attach_image_pairs('logotypes', 'logos'); } } else { if ($theme->updateCssFile($_REQUEST['selected_css_file'], $_REQUEST['css_content'])) { Tygh::$app['ajax']->assign('css_url', $theme->getCssUrl()); fn_set_notification('N', __('notice'), __('text_changes_saved')); } else { fn_set_notification('E', __('error'), __('error_occurred')); } $_suffix = '?selected_css_file=' . $_REQUEST['selected_css_file']; } } elseif ($mode == 'convert_to_css') { if ($theme->convertToCss()) { foreach (Layout::instance()->getList() as $layout_id => $layout_data) { Layout::instance()->update(array('style_id' => Registry::get('runtime.layout.style_id')), $layout_id); }
} } } if ($is_added) { fn_set_notification('N', __('notice'), __('categories_have_been_added')); } } $suffix = ".manage"; } // // Processing multiple updating of category elements // if ($mode == 'm_update') { // Update multiple categories data if (is_array($_REQUEST['categories_data'])) { fn_attach_image_pairs('category_main', 'category', 0, DESCR_SL); foreach ($_REQUEST['categories_data'] as $k => $v) { if (!fn_allowed_for('ULTIMATE') || fn_allowed_for('ULTIMATE') && fn_check_company_id('categories', 'category_id', $k)) { if (fn_allowed_for('ULTIMATE')) { fn_set_company_id($v); } fn_update_category($v, $k, DESCR_SL); } } } $suffix = ".manage"; } // // Processing deleting of multiple category elements // if ($mode == 'm_delete') {
/** * Updates/Creates options combination * * @param array $combination_data Combination data * @param string $combination_hash Combination hash * @return string Combination hash */ function fn_update_option_combination($combination_data, $combination_hash = 0) { /** * Change parameters for updating options combination * * @param array $combination_data Combination data * @param string $combination_hash Combination hash */ fn_set_hook('update_option_combination_pre', $combination_data, $combination_hash); $inventory_amount = db_get_field('SELECT amount FROM ?:product_options_inventory WHERE combination_hash = ?s', $combination_hash); if (empty($combination_hash)) { $combination_hash = fn_generate_cart_id($combination_data['product_id'], array('product_options' => $combination_data['combination'])); $combination = fn_get_options_combination($combination_data['combination']); $product_code = fn_get_product_code($combination_data['product_id'], $combination_data['combination']); $_data = array('product_id' => $combination_data['product_id'], 'combination_hash' => $combination_hash, 'combination' => $combination, 'product_code' => !empty($product_code) ? $product_code : '', 'amount' => !empty($combination_data['amount']) ? $combination_data['amount'] : 0, 'position' => !empty($combination_data['position']) ? $combination_data['position'] : 0); db_query("REPLACE INTO ?:product_options_inventory ?e", $_data); } else { // Forbid to update options in the existing combination. Only qty/code/pos. unset($combination_data['combination']); db_query("UPDATE ?:product_options_inventory SET ?u WHERE combination_hash = ?s", $combination_data, $combination_hash); } if (isset($combination_data['amount']) && $combination_data['amount'] > 0 && $inventory_amount <= 0) { fn_send_product_notifications($combination_data['product_id']); } // Updating images fn_attach_image_pairs('combinations', 'product_option'); /** * Makes extra actions after updating options combination * * @param array $combination_data Combination data * @param string $combination_hash Combination hash * @param int $inventory_amount Previous (before update) inventory amount of the combination */ fn_set_hook('update_option_combination_pre', $combination_data, $combination_hash, $inventory_amount); return $combination_hash; }
function fn_update_company($company_data, $company_id = 0, $lang_code = CART_LANGUAGE) { $can_update = true; /** * Update company data (running before fn_update_company() function) * * @param array $company_data Company data * @param int $company_id Company identifier * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) * @param boolean $can_update Flag, allows addon to forbid to create/update company */ fn_set_hook('update_company_pre', $company_data, $company_id, $lang_code, $can_update); if ($can_update == false) { return false; } if (fn_allowed_for('MULTIVENDOR') && Registry::get('runtime.company_id')) { unset($company_data['comission'], $company_data['comission_type'], $company_data['categories'], $company_data['shippings']); } elseif (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) { unset($company_data['storefront'], $company_data['secure_storefront']); } if (fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id')) { if (isset($company_data['storefront'])) { if (empty($company_data['storefront'])) { fn_set_notification('E', __('error'), __('storefront_url_not_defined')); return false; } else { if (empty($company_data['secure_storefront'])) { $company_data['secure_storefront'] = $company_data['storefront']; } $company_data['storefront'] = Url::clean($company_data['storefront']); $company_data['secure_storefront'] = Url::clean($company_data['secure_storefront']); } } } unset($company_data['company_id']); $_data = $company_data; if (fn_allowed_for('MULTIVENDOR')) { // Check if company with same email already exists $is_exist = db_get_field("SELECT email FROM ?:companies WHERE company_id != ?i AND email = ?s", $company_id, $_data['email']); if (!empty($is_exist)) { $_text = 'error_vendor_exists'; fn_set_notification('E', __('error'), __($_text)); return false; } } if (fn_allowed_for('ULTIMATE') && !empty($company_data['storefront'])) { // Check if company with the same Storefront URL already exists $http_exist = db_get_row('SELECT company_id, storefront FROM ?:companies WHERE storefront = ?s', $company_data['storefront']); $https_exist = db_get_row('SELECT company_id, secure_storefront FROM ?:companies WHERE secure_storefront = ?s', $company_data['secure_storefront']); if (!empty($http_exist) || !empty($https_exist)) { if (empty($company_id)) { if (!empty($http_exist)) { fn_set_notification('E', __('error'), __('storefront_url_already_exists')); } else { fn_set_notification('E', __('error'), __('secure_storefront_url_already_exists')); } return false; } elseif (!empty($http_exist) && $company_id != $http_exist['company_id'] || !empty($https_exist) && $company_id != $https_exist['company_id']) { if (!empty($http_exist) && $company_id != $http_exist['company_id']) { fn_set_notification('E', __('error'), __('storefront_url_already_exists')); unset($_data['storefront']); } else { fn_set_notification('E', __('error'), __('secure_storefront_url_already_exists')); unset($_data['secure_storefront']); } return false; } } } if (isset($company_data['shippings'])) { $_data['shippings'] = empty($company_data['shippings']) ? '' : fn_create_set($company_data['shippings']); } if (!empty($_data['countries_list'])) { $_data['countries_list'] = implode(',', $_data['countries_list']); } else { $_data['countries_list'] = ''; } // add new company if (empty($company_id)) { // company title can't be empty if (empty($company_data['company'])) { fn_set_notification('E', __('error'), __('error_empty_company_name')); return false; } $_data['timestamp'] = TIME; $company_id = db_query("INSERT INTO ?:companies ?e", $_data); if (empty($company_id)) { return false; } $_data['company_id'] = $company_id; foreach (fn_get_translation_languages() as $_data['lang_code'] => $_v) { db_query("INSERT INTO ?:company_descriptions ?e", $_data); } $action = 'add'; // update company information } else { if (isset($company_data['company']) && empty($company_data['company'])) { unset($company_data['company']); } if (!empty($_data['status'])) { $status_from = db_get_field("SELECT status FROM ?:companies WHERE company_id = ?i", $company_id); } db_query("UPDATE ?:companies SET ?u WHERE company_id = ?i", $_data, $company_id); if (isset($status_from) && $status_from != $_data['status']) { fn_companies_change_status($company_id, $_data['status'], '', $status_from, true); } // unset data lang code as it determines company main language not description language unset($_data['lang_code']); db_query("UPDATE ?:company_descriptions SET ?u WHERE company_id = ?i AND lang_code = ?s", $_data, $company_id, $lang_code); $action = 'update'; } /** * Update company data (running after fn_update_company() function) * * @param array $company_data Company data * @param int $company_id Company integer identifier * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) * @param string $action Flag determines if company was created (add) or just updated (update). */ fn_set_hook('update_company', $company_data, $company_id, $lang_code, $action); $logo_ids = array(); if ($action == 'add') { $theme_name = !empty($company_data['theme_name']) ? $company_data['theme_name'] : Registry::get('config.base_theme'); if (fn_allowed_for('ULTIMATE')) { $clone_from = !empty($company_data['clone_from']) && $company_data['clone_from'] != 'all' ? $company_data['clone_from'] : null; if (!is_null($clone_from)) { $theme_name = fn_get_theme_path('[theme]', 'C', $clone_from); } } if (fn_allowed_for('ULTIMATE')) { $logo_ids = fn_install_theme($theme_name, $company_id, false); } else { $logo_ids = fn_create_theme_logos_by_layout_id($theme_name, 0, $company_id, true); } } fn_attach_image_pairs('logotypes', 'logos', 0, $lang_code, $logo_ids); return $company_id; }
function fn_update_payment($payment_data, $payment_id, $lang_code = DESCR_SL) { if (!empty($payment_data['processor_id'])) { $payment_data['template'] = db_get_field("SELECT processor_template FROM ?:payment_processors WHERE processor_id = ?i", $payment_data['processor_id']); } $payment_data['localization'] = !empty($payment_data['localization']) ? fn_implode_localizations($payment_data['localization']) : ''; $payment_data['usergroup_ids'] = !empty($payment_data['usergroup_ids']) ? implode(',', $payment_data['usergroup_ids']) : ''; if (!empty($payment_id)) { db_query("UPDATE ?:payments SET ?u WHERE payment_id = ?i", $payment_data, $payment_id); db_query("UPDATE ?:payment_descriptions SET ?u WHERE payment_id = ?i AND lang_code = ?s", $payment_data, $payment_id, $lang_code); } else { $payment_data['payment_id'] = $payment_id = db_query("INSERT INTO ?:payments ?e", $payment_data); foreach ((array) Registry::get('languages') as $payment_data['lang_code'] => $_v) { db_query("INSERT INTO ?:payment_descriptions ?e", $payment_data); } } fn_attach_image_pairs('payment_image', 'payment', $payment_id, $lang_code); // Update payment processor settings if (!empty($payment_data['processor_params'])) { db_query("UPDATE ?:payments SET params = ?s WHERE payment_id = ?i", serialize($payment_data['processor_params']), $payment_id); } return $payment_id; }