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; }
private static function _installTheme($company_id = null) { $theme_name = 'basic'; $style = 'satori'; fn_install_theme($theme_name, $company_id); $layout = Layout::instance($company_id)->getDefault($theme_name); Styles::factory($theme_name)->setStyle($layout['layout_id'], $style); }
/** * Creates a clone of the theme. * * @param string $clone_name Name of the new theme * @param array $clone_data Array with "title" and "description" fields for the new theme * @param int $company_id ID of the owner company for the new theme * * @return bool Whether cloning has succeed */ public function cloneAs($clone_name, $clone_data = array(), $company_id = 0) { $cloned = new self($clone_name); if (file_exists($cloned->getThemePath())) { fn_set_notification('W', __('warning'), __('warning_theme_clone_dir_exists')); return false; } if (!fn_install_theme_files($this->getThemeName(), $cloned->getThemeName(), false)) { return false; } // Layouts that belong to the theme $layouts = Layout::instance()->getList(array('theme_name' => $this->getThemeName())); // Clone layouts one by one foreach ($layouts as $layout) { $src_layout_id = $layout['layout_id']; unset($layout['layout_id']); $layout['theme_name'] = $cloned->getThemeName(); $layout['from_layout_id'] = $src_layout_id; $dst_layout_id = Layout::instance()->update($layout); if (!empty($layout['is_default'])) { // Re-init layout data fn_init_layout(array('s_layout' => $dst_layout_id)); } } $manifest = $cloned->getManifest(); if (isset($clone_data['title'])) { $manifest['title'] = $clone_data['title']; } if (isset($clone_data['description'])) { $manifest['description'] = $clone_data['description']; } // Put logos of current layout to manifest $logos = fn_get_logos(Registry::get('runtime.company_id')); foreach ($logos as $type => $logo) { if (!empty($logo['image'])) { $filename = fn_basename($logo['image']['relative_path']); Storage::instance('images')->export($logo['image']['relative_path'], $cloned->getThemePath() . '/media/images/' . $filename); $manifest[$type] = 'media/images/' . $filename; } } $cloned->setManifest($manifest); $cloned->saveManifest(); fn_install_theme($cloned->getThemeName(), $company_id, false); $cloned->overrideSettings(null, $company_id); }
if ($mode == 'install') { if (!empty($_REQUEST['theme_name'])) { // Copy theme files to design/themes directory fn_install_theme_files($_REQUEST['theme_name'], $_REQUEST['theme_name']); } return array(CONTROLLER_STATUS_OK, 'themes.manage?selected_section=general'); } if ($mode == 'delete') { fn_delete_theme($_REQUEST['theme_name']); } if ($mode == 'set') { $is_exist = Layout::instance()->getList(array('theme_name' => $_REQUEST['theme_name'])); $company_id = Registry::get('runtime.company_id'); if (empty($is_exist)) { // Create new layout fn_install_theme($_REQUEST['theme_name'], $company_id); } else { Settings::instance()->updateValue('theme_name', $_REQUEST['theme_name'], '', true, $company_id); } $layout = Layout::instance($company_id)->getDefault($_REQUEST['theme_name']); if (!empty($_REQUEST['style'])) { $theme = Themes::factory(fn_get_theme_path('[theme]', 'C')); $theme_manifest = $theme->getManifest(); if (empty($theme_manifest['converted_to_css'])) { Styles::factory($_REQUEST['theme_name'])->setStyle($layout['layout_id'], $_REQUEST['style']); } else { fn_set_notification('E', __('error'), __('theme_editor.error_theme_converted_to_css', array('[url]' => fn_url("customization.update_mode?type=theme_editor&status=enable&s_layout={$layout['layout_id']}")))); } } // We need to re-init layout fn_init_layout(array('s_layout' => $layout['layout_id']));
/** * Setup themes * * @return bool True on success, false otherwise */ public function setupThemes() { if (!empty($this->_cart_settings['theme_name'])) { if (fn_allowed_for('ULTIMATE')) { fn_install_theme($this->_cart_settings['theme_name'], 1); } else { fn_install_theme($this->_cart_settings['theme_name'], 0); } return true; } return false; }