function fn_exim_pickup_set_company_id($company, $pickup_id) { $company_id = fn_get_company_id_by_name($company); db_query("UPDATE ?:store_locations SET company_id = ?i WHERE store_location_id = ?i ", $company_id, $pickup_id); $store_location_data = array('share_company_id' => $company_id, 'share_object_id' => $pickup_id, 'share_object_type' => 'store_locations'); db_query("REPLACE INTO ?:ult_objects_sharing ?e", $store_location_data); return true; }
/** * Generates SEO name for imported product * * @param int $object_id Product identificator * @param int $object_type One-letter object type identificator * @param string $object_name SEO-name to import with * @param array $product_name Product name for specified language code * @param int $index * @param string $dispatch * @param string $company_id Company identifier * @param string $lang_code Two-letter language code * @param string $company_name Company name product imported for * @return array SEO name for specified language code */ function fn_create_import_seo_name($object_id, $object_type = 'p', $object_name, $product_name, $index = 0, $dispatch = '', $company_id = '', $lang_code = CART_LANGUAGE, $company_name = '') { if (empty($company_id) && !empty($company_name) && !Registry::get('runtime.company_id')) { $company_id = fn_get_company_id_by_name($company_name); } if (!is_array($object_name)) { $object_name = array($lang_code => $object_name); } $result = array(); foreach ($object_name as $name_lang_code => $seo_name) { if (empty($seo_name)) { $seo_name = reset($product_name); } $result[$name_lang_code] = fn_create_seo_name($object_id, $object_type, $seo_name, $index, $dispatch, $company_id, $name_lang_code); } return $result; }
function fn_import_set_user_company_id(&$import_data) { foreach ($import_data as $key => $data) { if ((empty($import_data[$key]['user_type']) || $import_data[$key]['user_type'] != 'A') && !Registry::get('runtime.simple_ultimate')) { if (!Registry::get('runtime.company_id')) { $import_data[$key]['company_id'] = !empty($import_data[$key]['company_id']) ? fn_get_company_id_by_name($import_data[$key]['company_id']) : 0; } else { $import_data[$key]['company_id'] = Registry::get('runtime.company_id'); } } else { $user = fn_exim_get_user_info($import_data[$key]['email']); if (!empty($user)) { $import_data[$key]['company_id'] = (int) $user['company_id']; } else { if (!Registry::get('runtime.company_id')) { $import_data[$key]['company_id'] = !empty($import_data[$key]['company_id']) ? fn_get_company_id_by_name($import_data[$key]['company_id']) : 0; } else { $import_data[$key]['company_id'] = Registry::get('runtime.company_id'); } } } } return true; }
/** * Import company * * @param string $object_type Type of object ('currencies', 'pages', etc) * @param integer $object_id Product ID * @param string $company_name Company name * @return integer $company_id Company identifier. */ function fn_exim_set_company($object_type, $object_key, $object_id, $company_name) { if (empty($company_name) || empty($object_id) || empty($object_type)) { return false; } if (Registry::get('runtime.company_id')) { $company_id = Registry::get('runtime.company_id'); } else { $company_id = fn_get_company_id_by_name($company_name); if (!$company_id) { $company_data = array('company' => $company_name, 'email' => ''); $company_id = fn_update_company($company_data, 0); } } db_query("UPDATE ?:{$object_type} SET company_id = ?s WHERE {$object_key} = ?i", $company_id, $object_id); return $company_id; }
function fn_import_feature($data, &$processed_data, &$skip_record, $category_delimiter = '///') { static $new_groups = array(); $skip_record = true; $feature = reset($data); $langs = array_keys($data); $main_lang = reset($langs); if (Registry::get('runtime.company_id')) { $company_id = Registry::get('runtime.company_id'); } else { if (!empty($feature['company'])) { $company_id = fn_get_company_id_by_name($feature['company']); } else { $company_id = isset($feature['company_id']) ? $feature['company_id'] : Registry::get('runtime.company_id'); } } if (!empty($feature['feature_id'])) { $feature_id = db_get_field('SELECT ?:product_features.feature_id FROM ?:product_features WHERE feature_id = ?i', $feature['feature_id']); } $parent_id = fn_exim_get_product_feature_group_id($feature['parent_id'], $company_id, $new_groups, $main_lang); if (empty($feature_id)) { $condition = db_quote("WHERE description = ?s AND lang_code = ?s AND feature_type = ?s", $feature['description'], $main_lang, $feature['feature_type']); $condition .= db_quote(" AND parent_id = ?i", $parent_id); $feature_id = db_get_field('SELECT ?:product_features.feature_id FROM ?:product_features_descriptions ' . 'LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_features_descriptions.feature_id ' . $condition); } unset($feature['feature_id']); $feature['company_id'] = $company_id; $feature['parent_id'] = $parent_id; $feature['variants'] = array(); if (!empty($feature['Variants'])) { $variants = str_getcsv($feature['Variants'], ',', "'"); array_walk($variants, 'fn_trim_helper'); list($origin_variants) = fn_get_product_feature_variants(array('feature_id' => $feature_id), 0, $main_lang); $feature['original_var_ids'] = implode(',', array_keys($origin_variants)); foreach ($variants as $variant) { $feature['variants'][]['variant'] = $variant; } } $skip = false; if (empty($feature_id)) { $feature_id = fn_update_product_feature($feature, 0, $main_lang); $processed_data['N']++; fn_set_progress('echo', __('updating') . ' features <b>' . $feature_id . '</b>. ', false); } else { if (!fn_check_company_id('product_features', 'feature_id', $feature_id)) { $processed_data['S']++; $skip = true; } else { // Convert categories from Names to C_IDS: Electronics,Processors -> 3,45 $_data = $feature; $_data['categories_path'] = fn_exim_get_features_convert_category_path($feature, $main_lang, $category_delimiter); fn_update_product_feature($_data, $feature_id, $main_lang); if (in_array($feature_id, $new_groups)) { $processed_data['N']++; } else { $processed_data['E']++; fn_set_progress('echo', __('creating') . ' features <b>' . $feature_id . '</b>. ', false); } } } if (!$skip) { fn_exim_set_product_feature_categories($feature_id, $feature, $main_lang, $category_delimiter); foreach ($data as $lang_code => $feature_data) { unset($feature_data['feature_id']); db_query('UPDATE ?:product_features_descriptions SET ?u WHERE feature_id = ?i AND lang_code = ?s', $feature_data, $feature_id, $lang_code); } if (fn_allowed_for('ULTIMATE')) { if (!empty($company_id)) { fn_exim_update_share_feature($feature_id, $company_id); } } } return $feature_id; }
function fn_import_fill_products_alt_keys($pattern, &$alt_keys, &$object, &$skip_get_primary_object_id) { if (Registry::get('runtime.company_id')) { $alt_keys['company_id'] = Registry::get('runtime.company_id'); } elseif (!empty($object['company'])) { // field store is set $company_id = fn_get_company_id_by_name($object['company']); if ($company_id !== null) { $alt_keys['company_id'] = $company_id; } else { $skip_get_primary_object_id = true; } } else { // field store is not set $skip_get_primary_object_id = true; } }
/** * Hook is used for changing query that selects primary object ID. * * @param array $pattern Array with import pattern data * @param array $_alt_keys Array with key=>value data of possible primary object (used for 'where' condition) * @param array $v Array with importing data (one row) * @param boolean $skip_get_primary_object_id Skip or not getting Primary object ID */ function fn_mve_import_get_primary_object_id(&$pattern, &$_alt_keys, &$v, &$skip_get_primary_object_id) { if ($pattern['section'] == 'products' && $pattern['pattern_id'] == 'products') { if (Registry::get('runtime.company_id')) { $_alt_keys['company_id'] = Registry::get('runtime.company_id'); } elseif (!empty($v['company'])) { // field vendor is set $company_id = fn_get_company_id_by_name($v['company']); if ($company_id !== null) { $_alt_keys['company_id'] = $company_id; } else { $skip_get_primary_object_id = true; } } else { // field vendor is not set, so import for the base company $_alt_keys['company_id'] = 0; } } }
/** * Adds current company_id as altkey if object doesn't * have store defined. Needed to determine primary object * correctly. * * @param array $pattern Pattern structure * @param array $alt_keys Keys that act as primary when adding/updating * @param array $object Object structure to export * @param boolean $skip_get_primary_object_id Flag to leave primary object empty */ function fn_exim_apply_company($pattern, &$alt_keys, &$object, &$skip_get_primary_object_id) { if (empty($object['company'])) { //object doesn't have store name defined if (Registry::get('runtime.company_id') && empty($alt_keys['company_id'])) { $alt_keys['company_id'] = Registry::get('runtime.company_id'); } } else { $company_id = fn_get_company_id_by_name($object['company']); if ($company_id !== null) { $alt_keys['company_id'] = $company_id; } } }