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'); } } }
/** * Copy style * @param string $from style ID to copy from * @param string $to style ID to copy to * @return boolean true on success, false otherwise */ public function copy($from, $to) { $from = fn_basename($from); $to = fn_basename($to); $style_file_from = $this->getStyleFile($from); $style_file_to = $this->getStyleFile($to, 'less'); if (is_file($style_file_from)) { if (fn_copy($style_file_from, $style_file_to)) { $types = array('css'); foreach ($types as $type) { $style_file_from = $this->getStyleFile($from, $type); if (file_exists($style_file_from)) { fn_copy($style_file_from, $this->getStyleFile($to, $type)); } } fn_copy(Patterns::instance($this->params)->getPath($from), Patterns::instance($this->params)->getPath($to)); $content = fn_get_contents($style_file_to); $content = str_replace('/patterns/' . $from . '/', '/patterns/' . $to . '/', $content); fn_put_contents($style_file_to, $content); // Clone logos for new style $logos = db_get_array('SELECT * FROM ?:logos WHERE style_id = ?s AND company_id = ?i', $from, $this->company_id); foreach ($logos as $logo) { $object_id = fn_update_logo(array('type' => $logo['type'], 'layout_id' => $logo['layout_id'], 'style_id' => $to), $this->company_id); fn_clone_image_pairs($object_id, $logo['logo_id'], 'logos'); } return true; } } return false; }
/** * Copy all layout data from one layout to another by ID * @param integer $from_layout_id source layout ID * @param integer $to_layout_id target layout ID * @return boolean true on success, false - otherwise */ public function copyById($from_layout_id, $to_layout_id) { $from_layout = $this->get($from_layout_id); if (empty($from_layout)) { return false; } $object_ids = array(); $location = Location::instance($from_layout_id)->copy($to_layout_id); $target_company_id = 0; if (fn_allowed_for('ULTIMATE')) { $target_company_id = db_get_field("SELECT company_id FROM ?:bm_layouts WHERE layout_id = ?i", $to_layout_id); } // Copy logos $types = fn_get_logo_types(); foreach ($types as $type => $data) { if (!empty($data['for_layout'])) { $object_ids[$type] = fn_create_logo(array('type' => $type, 'layout_id' => $to_layout_id), $target_company_id); } } $logo_ids = db_get_hash_single_array("SELECT logo_id, type FROM ?:logos WHERE layout_id = ?i AND type IN (?a)", array('type', 'logo_id'), $from_layout_id, array_keys($object_ids)); foreach ($logo_ids as $type => $logo_id) { fn_clone_image_pairs($object_ids[$type], $logo_id, 'logos'); } return true; }
function fn_clone_product($product_id) { // Clone main data $data = db_get_row("SELECT * FROM ?:products WHERE product_id = ?i", $product_id); unset($data['product_id']); $data['status'] = 'D'; $pid = db_query("INSERT INTO ?:products ?e", $data); // Clone descriptions $data = db_get_array("SELECT * FROM ?:product_descriptions WHERE product_id = ?i", $product_id); foreach ($data as $v) { $v['product_id'] = $pid; if ($v['lang_code'] == CART_LANGUAGE) { $orig_name = $v['product']; $new_name = $v['product'] . ' [CLONE]'; } $v['product'] .= ' [CLONE]'; db_query("INSERT INTO ?:product_descriptions ?e", $v); } // Clone prices $data = db_get_array("SELECT * FROM ?:product_prices WHERE product_id = ?i", $product_id); foreach ($data as $v) { $v['product_id'] = $pid; unset($v['price_id']); db_query("INSERT INTO ?:product_prices ?e", $v); } // Clone categories links $data = db_get_array("SELECT * FROM ?:products_categories WHERE product_id = ?i", $product_id); $_cids = array(); foreach ($data as $v) { $v['product_id'] = $pid; db_query("INSERT INTO ?:products_categories ?e", $v); $_cids[] = $v['category_id']; } fn_update_product_count($_cids); // Clone product options fn_clone_product_options($product_id, $pid); // Clone global linked options $gl_options = db_get_fields("SELECT option_id FROM ?:product_global_option_links WHERE product_id = ?i", $product_id); if (!empty($gl_options)) { foreach ($gl_options as $v) { db_query("INSERT INTO ?:product_global_option_links (option_id, product_id) VALUES (?i, ?i)", $v, $pid); } } // Clone product features $data = db_get_array("SELECT * FROM ?:product_features_values WHERE product_id = ?i", $product_id); foreach ($data as $v) { $v['product_id'] = $pid; db_query("INSERT INTO ?:product_features_values ?e", $v); } // Clone blocks fn_clone_block_links('products', $product_id, $pid); // Clone addons fn_set_hook('clone_product', $product_id, $pid); // Clone images fn_clone_image_pairs($pid, $product_id, 'product'); // Clone product files if (is_dir(DIR_DOWNLOADS . $product_id)) { $data = db_get_array("SELECT * FROM ?:product_files WHERE product_id = ?i", $product_id); foreach ($data as $v) { $v['product_id'] = $pid; $old_file_id = $v['file_id']; unset($v['file_id']); $file_id = db_query("INSERT INTO ?:product_files ?e", $v); $file_descr = db_get_row("SELECT * FROM ?:product_file_descriptions WHERE file_id = ?i", $old_file_id); $file_descr['file_id'] = $file_id; db_query("INSERT INTO ?:product_file_descriptions ?e", $file_descr); } fn_copy(DIR_DOWNLOADS . $product_id, DIR_DOWNLOADS . $pid); } fn_build_products_cache(array($pid)); return array('product_id' => $pid, 'orig_name' => $orig_name, 'product' => $new_name); }
/** * Copies all layout data from one layout to another by their IDs. * * @param integer $source_layout_id Source layout ID * @param integer $target_layout_id Target layout ID * * @return boolean True on success, false - otherwise */ public function copyById($source_layout_id, $target_layout_id) { $source_layout = $this->get($source_layout_id); if (empty($source_layout)) { return false; } // Copy locations, their containers, grids and blocks to the target layout Location::instance($source_layout_id)->copy($target_layout_id); $source_layout_company_id = 0; $target_layout_company_id = 0; if (fn_allowed_for('ULTIMATE')) { $source_layout_company_id = $source_layout['company_id']; $target_layout_company_id = db_get_field("SELECT company_id FROM ?:bm_layouts WHERE layout_id = ?i", $target_layout_id); } // Copy logos /** * Get the list of logos, bounded to source layout and given company. * List has the following format: * * [ * logo_type => [ * style_id => logo_id, * ... * ], * ... * ] */ $source_layout_logos = db_get_hash_multi_array('SELECT `type`, `style_id`, `logo_id` FROM ?:logos WHERE `layout_id` = ?i AND `company_id` = ?i', array('type', 'style_id', 'logo_id'), $source_layout_id, $source_layout_company_id); $logo_types = fn_get_logo_types(); foreach ($logo_types as $logo_type => $logo_type_metadata) { if (empty($logo_type_metadata['for_layout']) || empty($source_layout_logos[$logo_type])) { continue; } foreach ($source_layout_logos[$logo_type] as $source_layout_style_id => $source_layout_logo_id) { $created_target_layout_logo_id = fn_update_logo(array('type' => $logo_type, 'layout_id' => $target_layout_id, 'style_id' => $source_layout_style_id), $target_layout_company_id); fn_clone_image_pairs($created_target_layout_logo_id, $source_layout_logo_id, 'logos'); } } return true; }
function fn_clone_product($product_id) { /** * Adds additional actions before product cloning * * @param int $product_id Original product identifier */ fn_set_hook('clone_product_pre', $product_id); // Clone main data $data = db_get_row("SELECT * FROM ?:products WHERE product_id = ?i", $product_id); unset($data['product_id']); $data['status'] = 'D'; $data['timestamp'] = $data['updated_timestamp'] = time(); $pid = db_query("INSERT INTO ?:products ?e", $data); // Clone descriptions $data = db_get_array("SELECT * FROM ?:product_descriptions WHERE product_id = ?i", $product_id); foreach ($data as $v) { $v['product_id'] = $pid; if ($v['lang_code'] == CART_LANGUAGE) { $orig_name = $v['product']; $new_name = $v['product'] . ' [CLONE]'; } $v['product'] .= ' [CLONE]'; db_query("INSERT INTO ?:product_descriptions ?e", $v); } // Clone prices $data = db_get_array("SELECT * FROM ?:product_prices WHERE product_id = ?i", $product_id); foreach ($data as $v) { $v['product_id'] = $pid; unset($v['price_id']); db_query("INSERT INTO ?:product_prices ?e", $v); } // Clone categories links $data = db_get_array("SELECT * FROM ?:products_categories WHERE product_id = ?i", $product_id); $_cids = array(); foreach ($data as $v) { $v['product_id'] = $pid; db_query("INSERT INTO ?:products_categories ?e", $v); $_cids[] = $v['category_id']; } fn_update_product_count($_cids); // Clone product options fn_clone_product_options($product_id, $pid); // Clone global linked options $gl_options = db_get_fields("SELECT option_id FROM ?:product_global_option_links WHERE product_id = ?i", $product_id); if (!empty($gl_options)) { foreach ($gl_options as $v) { db_query("INSERT INTO ?:product_global_option_links (option_id, product_id) VALUES (?i, ?i)", $v, $pid); } } // Clone product features $data = db_get_array("SELECT * FROM ?:product_features_values WHERE product_id = ?i", $product_id); foreach ($data as $v) { $v['product_id'] = $pid; db_query("INSERT INTO ?:product_features_values ?e", $v); } // Clone blocks Block::instance()->cloneDynamicObjectData('products', $product_id, $pid); // Clone tabs info ProductTabs::instance()->cloneStatuses($pid, $product_id); // Clone addons fn_set_hook('clone_product', $product_id, $pid); // Clone images fn_clone_image_pairs($pid, $product_id, 'product'); // Clone product files fn_clone_product_files($product_id, $pid); /** * Adds additional actions after product cloning * * @param int $product_id Original product identifier * @param int $pid Cloned product identifier * @param string $orig_name Original product name * @param string $new_name Cloned product name */ fn_set_hook('clone_product_post', $product_id, $pid, $orig_name, $new_name); return array('product_id' => $pid, 'orig_name' => $orig_name, 'product' => $new_name); }
function fn_watermarks_update_company(&$company_data, &$company_id, &$lang_code, &$action) { if ($action == 'add') { // Clone watermark images $clone_from = !empty($company_data['clone_from']) && $company_data['clone_from'] != 'all' ? $company_data['clone_from'] : null; if (!is_null($clone_from)) { if (!empty($company_id)) { $clone_to = $company_id; $image_pair = fn_get_image_pairs($clone_from, 'watermark', 'M'); } else { $clone_to = WATERMARK_IMAGE_ID; $image_pair = fn_get_image_pairs(WATERMARK_IMAGE_ID, 'watermark', 'M'); } if (!empty($image_pair)) { fn_clone_image_pairs($clone_to, $clone_from, 'watermark'); } } else { // check if company options are valid $option_types = fn_get_apply_watermark_options(); foreach ($option_types as $type => $options) { foreach ($options as $name => $option_id) { $image_name = $type == 'icons' ? 'icon' : 'detailed'; Settings::instance($company_id)->updateValueById($option_id, 'N', $company_id); } } } } }
function fn_projects_clone_page($page_id, $new_page_id) { fn_clone_image_pairs($new_page_id, $page_id, 'projects'); db_query("INSERT INTO ?:projects_authors (page_id, user_id) SELECT ?i as page_id, user_id FROM ?:projects_authors WHERE page_id = ?i", $new_page_id, $page_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_clone_page($page_id, $new_page_id) { fn_clone_image_pairs($new_page_id, $page_id, 'blog'); db_query("INSERT INTO ?:blog_authors (page_id, user_id) SELECT ?i as page_id, user_id FROM ?:blog_authors WHERE page_id = ?i", $new_page_id, $page_id); }
function fn_clone_post_process_categories($new_id, $table_data, $row, $clone_data, $new_ids) { if (!empty($row['id_path'])) { $path = explode('/', $row['id_path']); $new_path = array(); foreach ($path as $id) { $new_path[] = isset($new_ids[$id]) ? $new_ids[$id] : $id; } $path = implode('/', $new_path); $parent_id = isset($new_ids[$row['parent_id']]) ? $new_ids[$row['parent_id']] : 0; db_query('UPDATE ?:categories SET id_path = ?s, parent_id = ?i WHERE category_id = ?i', $path, $parent_id, $new_id); } fn_clone_image_pairs($new_id, array_search($new_id, $new_ids), 'category'); fn_update_product_count(array($new_id)); }
function fn_clone_options_inventory($from_product_id, $to_product_id, $options, $variants) { $inventory = db_get_array("SELECT * FROM ?:product_options_inventory WHERE product_id = ?i", $from_product_id); foreach ($inventory as $key => $value) { $_variants = explode('_', $value['combination']); $inventory[$key]['combination'] = ''; foreach ($_variants as $kk => $vv) { if ($kk % 2 == 0 && !empty($_variants[$kk + 1])) { $_comb[0] = $options[$vv]; $_comb[1] = $variants[$_variants[$kk + 1]]; $new_variants[$kk] = $_comb[1]; $inventory[$key]['combination'] .= implode('_', $_comb) . (!empty($_variants[$kk + 2]) ? '_' : ''); } } $_data['product_id'] = $to_product_id; $_data['combination_hash'] = fn_generate_cart_id($to_product_id, array('product_options' => $new_variants)); $_data['combination'] = rtrim($inventory[$key]['combination'], "|"); $_data['amount'] = $value['amount']; $_data['product_code'] = $value['product_code']; db_query("INSERT INTO ?:product_options_inventory ?e", $_data); // Clone option images fn_clone_image_pairs($_data['combination_hash'], $value['combination_hash'], 'product_option', null, $to_product_id, 'product'); } }