* @copyright 2011-2017 PresTeamShop * @license see file: LICENSE.txt * @category PrestaShop * @category Module * @revision 33 */ use PrestaShop\PrestaShop\Adapter\Cart\CartPresenter; if (!defined('_PS_VERSION_')) { exit; } require_once _PS_MODULE_DIR_.'/onepagecheckoutps/classes/OnePageCheckoutPSCore.php'; class OnePageCheckoutPS extends OnePageCheckoutPSCore { const VERSION = '1.0.1'; public $onepagecheckoutps_dir; public $onepagecheckoutps_tpl; public $translation_dir; public $fields_to_capitalize = array('firstname', 'lastname', 'address1', 'address2', 'city', 'company', 'postcode'); protected $configure_vars = array( array('name' => 'OPC_VERSION', 'default_value' => self::VERSION, 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_OVERRIDE_CSS', 'default_value' => '', 'is_html' => true, 'is_bool' => false), array('name' => 'OPC_OVERRIDE_JS', 'default_value' => '', 'is_html' => true, 'is_bool' => false), /* general */ array('name' => 'OPC_SHOW_DELIVERY_VIRTUAL', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array( 'name' => 'OPC_ID_CONTENT_PAGE', 'default_value' => '#content-wrapper #main', 'is_html' => false, 'is_bool' => false ), array('name' => 'OPC_DEFAULT_PAYMENT_METHOD', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_DEFAULT_GROUP_CUSTOMER', 'default_value' => 3, 'is_html' => false, 'is_bool' => false), array( 'name' => 'OPC_GROUPS_CUSTOMER_ADDITIONAL', 'default_value' => '', 'is_html' => false, 'is_bool' => false ), array('name' => 'OPC_ID_CUSTOMER', 'default_value' => 0, 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_VALIDATE_DNI', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_REDIRECT_DIRECTLY_TO_OPC', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), /* register - step 1 */ array('name' => 'OPC_SHOW_BUTTON_REGISTER', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_USE_SAME_NAME_CONTACT_DA', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_USE_SAME_NAME_CONTACT_BA', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_REQUEST_PASSWORD', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array( 'name' => 'OPC_OPTION_AUTOGENERATE_PASSWORD', 'default_value' => 1, 'is_html' => false, 'is_bool' => true ), array('name' => 'OPC_ENABLE_INVOICE_ADDRESS', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_REQUIRED_INVOICE_ADDRESS', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_REQUEST_CONFIRM_EMAIL', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_CHOICE_GROUP_CUSTOMER', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array( 'name' => 'OPC_CHOICE_GROUP_CUSTOMER_ALLOW', 'default_value' => '', 'is_html' => false, 'is_bool' => false ), array('name' => 'OPC_SHOW_LIST_CITIES_GEONAMES', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_AUTO_ADDRESS_GEONAMES', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_AUTOCOMPLETE_GOOGLE_ADDRESS', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_GOOGLE_API_KEY', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_CAPITALIZE_FIELDS', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), /* shipping - step 2 */ array('name' => 'OPC_RELOAD_SHIPPING_BY_STATE', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_DESCRIPTION_CARRIER', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_IMAGE_CARRIER', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_FORCE_NEED_POSTCODE', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_FORCE_NEED_CITY', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array( 'name' => 'OPC_MODULE_CARRIER_NEED_POSTCODE', 'default_value' => '', 'is_html' => false ), array( 'name' => 'OPC_MODULE_CARRIER_NEED_CITY', 'default_value' => '', 'is_html' => false ), /* payment - step 3 */ //array('name' => 'OPC_SHOW_POPUP_PAYMENT', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), //array('name' => 'OPC_PAYMENTS_WITHOUT_RADIO', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), //array('name' => 'OPC_MODULES_WITHOUT_POPUP', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_SHOW_IMAGE_PAYMENT', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_DETAIL_PAYMENT', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_PAYMENT_NEED_REGISTER', 'default_value' => '', 'is_html' => false, 'is_bool' => false), /* review - step 4 */ array('name' => 'OPC_SHOW_LINK_CONTINUE_SHOPPING', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_LINK_CONTINUE_SHOPPING', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_SHOW_ZOOM_IMAGE_PRODUCT', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_TOTAL_PRODUCT', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_TOTAL_DISCOUNT', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_TOTAL_WRAPPING', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_TOTAL_SHIPPING', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_TOTAL_WITHOUT_TAX', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_TOTAL_TAX', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_TOTAL_PRICE', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array( 'name' => 'OPC_SHOW_REMAINING_FREE_SHIPPING', 'default_value' => 1, 'is_html' => false, 'is_bool' => true ), array('name' => 'OPC_ENABLE_TERMS_CONDITIONS', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_ID_CMS_TEMRS_CONDITIONS', 'default_value' => 0, 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_ENABLE_PRIVACY_POLICY', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_ID_CMS_PRIVACY_POLICY', 'default_value' => 0, 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_SHOW_WEIGHT', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_REFERENCE', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_UNIT_PRICE', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_AVAILABILITY', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_ENABLE_HOOK_SHOPPING_CART', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_COMPATIBILITY_REVIEW', 'default_value' => 0, 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_SHOW_VOUCHER_BOX', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), /* theme */ array('name' => 'OPC_THEME_BACKGROUND_COLOR', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_THEME_BORDER_COLOR', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_THEME_ICON_COLOR', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_THEME_CONFIRM_COLOR', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_THEME_CONFIRM_TEXT_COLOR', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_THEME_TEXT_COLOR', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_THEME_SELECTED_COLOR', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_THEME_SELECTED_TEXT_COLOR', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_ALREADY_REGISTER_BUTTON', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array( 'name' => 'OPC_ALREADY_REGISTER_BUTTON_TEXT', 'default_value' => '', 'is_html' => false, 'is_bool' => false ), array('name' => 'OPC_THEME_LOGIN_BUTTON', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_THEME_LOGIN_BUTTON_TEXT', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_THEME_VOUCHER_BUTTON', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_THEME_VOUCHER_BUTTON_TEXT', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array('name' => 'OPC_BACKGROUND_BUTTON_FOOTER', 'default_value' => '', 'is_html' => false, 'is_bool' => false), array( 'name' => 'OPC_THEME_BORDER_BUTTON_FOOTER', 'default_value' => '', 'is_html' => false, 'is_bool' => false ), array('name' => 'OPC_CONFIRMATION_BUTTON_FLOAT', 'default_value' => 1, 'is_html' => false, 'is_bool' => true), /* social */ array('name' => 'OPC_SOCIAL_NETWORKS', 'default_value' => '', 'is_html' => false, 'is_bool' => false), /* debug mode */ array('name' => 'OPC_ENABLE_DEBUG', 'default_value' => '0', 'is_html' => false, 'is_bool' => true), array('name' => 'OPC_IP_DEBUG', 'default_value' => '', 'is_html' => false, 'is_bool' => false), ); public function __construct() { $this->prefix_module = 'OPC'; $this->name = 'onepagecheckoutps'; $this->displayName = 'One Page Checkout PrestaShop'; $this->tab = 'checkout'; $this->version = '1.0.1'; $this->author = 'PresTeamShop'; $this->need_instance = 0; $this->bootstrap = true; $this->module_key = ''; if (property_exists($this, 'controllers')) { $this->controllers = array('login', 'payment', 'actions'); } parent::__construct(); $this->description = $this->l('The simplest and fastest way to increase sales.'); $this->confirmUninstall = $this->l('Are you sure you want uninstall?'); $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); $this->globals->object = (object) array( 'customer' => 'customer', 'delivery' => 'delivery', 'invoice' => 'invoice', ); $this->globals->type = (object) array( 'isAddress' => 'string', 'isBirthDate' => 'string', 'isDate' => 'string', 'isBool' => 'boolean', 'isCityName' => 'string', 'isDniLite' => 'string', 'isEmail' => 'string', 'isGenericName' => 'string', 'isMessage' => 'text', 'isName' => 'string', 'isPasswd' => 'password', 'isPhoneNumber' => 'string', 'isPostCode' => 'string', 'isVatNumber' => 'string', 'number' => 'integer', 'url' => 'string', 'confirmation' => 'string', ); $this->globals->theme = (object) array( 'gray' => 'gray', 'blue' => 'blue', 'black' => 'black', 'green' => 'green', 'red' => 'red', ); $this->globals->lang->object = array( 'customer' => $this->l('Customer'), 'delivery' => $this->l('Address delivery'), 'invoive' => $this->l('Address invoice'), ); $this->globals->lang->theme = array( 'gray' => $this->l('Gray'), 'blue' => $this->l('Blue'), 'black' => $this->l('Black'), 'green' => $this->l('Green'), 'red' => $this->l('Red'), ); $this->onepagecheckoutps_dir = __PS_BASE_URI__.'modules/'.$this->name.'/'; $this->onepagecheckoutps_tpl = _PS_ROOT_DIR_.'/modules/'.$this->name.'/'; $this->translation_dir = _PS_MODULE_DIR_.$this->name.'/translations/'; if (property_exists($this, 'controllers')) { $this->controllers = array('login', 'payment'); } $overrides = array( 'override/controllers/front/OrderController.php' ); $text_override_must_copy = $this->l('You must copy the file'); $text_override_at_root = $this->l('at the root of your store'); $text_override_create_folders = $this->l('Create folders if necessary.'); foreach ($overrides as $override) { if (!$this->existOverride($override)) { if (!$this->copyOverride($override)) { $text_override = $text_override_must_copy.' "/modules/'.$this->name.'/public/'.$override.'" ' .$text_override_at_root.' "/'.$override.'". '.$text_override_create_folders; $this->warnings[] = $text_override; } } else { if (!$this->existOverride($override, '/KEY_'.$this->prefix_module.'_'.$this->version.'/')) { rename(_PS_ROOT_DIR_.'/'.$override, _PS_ROOT_DIR_.'/'.$override.'_BK-'.$this->prefix_module.'-PTS_'.date('Y-m-d')); if (!$this->copyOverride($override)) { $text_override = $text_override_must_copy.' "/modules/'.$this->name.'/public/'.$override.'" ' .$text_override_at_root.' "/'.$override.'". '.$text_override_create_folders; $this->warnings[] = $text_override; } } } } //----------------------------------------------------------------------------------- $query_cs = new DbQuery(); $query_cs->from('customer'); $query_cs->where('id_customer = '.(int) Configuration::get('OPC_ID_CUSTOMER')); $result_cs = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query_cs); $query_csg = new DbQuery(); $query_csg->from('customer_group'); $query_csg->where('id_customer = '.(int) Configuration::get('OPC_ID_CUSTOMER')); $result_csg = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query_csg); if ((!$result_cs || !$result_csg) && Module::isInstalled($this->name)) { $this->createCustomerOPC(); } //----------------------------------------------------------------------------------- if (Configuration::get('PS_DISABLE_OVERRIDES') == 1 && Validate::isLoadedObject($this->context->employee)) { $this->warnings[] = $this->l('This module does not work with the override disabled in your store. Turn off option -Disable all overrides- on -Advanced Parameters--Performance-'); } require_once _PS_MODULE_DIR_.'onepagecheckoutps/classes/FieldClass.php'; require_once _PS_MODULE_DIR_.'onepagecheckoutps/classes/FieldControl.php'; require_once _PS_MODULE_DIR_.'onepagecheckoutps/classes/FieldOptionClass.php'; require_once _PS_MODULE_DIR_.'onepagecheckoutps/classes/PaymentClass.php'; //Delete fields required, this cause problem on our module. Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('DELETE FROM '._DB_PREFIX_.'required_field'); if (!array_key_exists('sortby', $this->context->smarty->registered_plugins['modifier'])) { $this->context->smarty->registerPlugin('modifier', 'sortby', array($this, 'smartyModifierSortby')); } $this->checkModulePTS(); if (isset($this->context->cookie->opc_suggest_address) && (!$this->context->customer->isLogged() || ($this->context->customer->isLogged() && !isset($this->context->cookie->id_cart))) ) { unset($this->context->cookie->opc_suggest_address); } if (!function_exists('curl_init') && !function_exists('curl_setopt') && !function_exists('curl_exec') && !function_exists('curl_close') ) { $this->errors[] = $this->l('CURL functions not available for registration module.'); } } /** * @return bool */ public function install() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } if (!parent::install() || !$this->registerHook('displayHeader') || !$this->registerHook('displayShoppingCart') || !$this->registerHook('actionShopDataDuplication') || !$this->registerHook('displayAdminOrder') || !$this->registerHook('displayAdminHomeQuickLinks') || !$this->registerHook('actionCarrierUpdate') ) { return false; } $this->createCustomerOPC(); //install field shops $this->installLanguageShop(); //social network for login $sc_google = 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'; $json_networks = array( 'facebook' => array( 'network' => 'Facebook', 'name_network' => 'Facebook', 'client_id' => '', 'client_secret' => '', 'scope' => 'email,public_profile', 'class_icon' => 'facebook', ), 'google' => array( 'network' => 'Google', 'name_network' => 'Google', 'client_id' => '', 'client_secret' => '', 'scope' => $sc_google, 'class_icon' => 'google', ), 'paypal' => array( 'network' => 'Paypal', 'name_network' => 'Paypal', 'client_id' => '', 'client_secret' => '', 'scope' => 'openid profile email address', 'class_icon' => 'paypal', ) ); Configuration::updateValue('OPC_SOCIAL_NETWORKS', Tools::jsonEncode($json_networks)); //desactiva el tema movil Configuration::updateValue('PS_ALLOW_MOBILE_DEVICE', 0); //config default group customer $id_customer_group = Configuration::get('PS_CUSTOMER_GROUP'); if (!empty($id_customer_group)) { Configuration::updateValue('OPC_DEFAULT_GROUP_CUSTOMER', $id_customer_group); } $id_country_default = Configuration::get('PS_COUNTRY_DEFAULT'); //update default country $sql_country = 'UPDATE '._DB_PREFIX_.'opc_field_shop fs'; $sql_country .= ' INNER JOIN '._DB_PREFIX_.'opc_field f ON f.id_field = fs.id_field'; $sql_country .= ' SET fs.default_value = \''.(int)$id_country_default.'\''; $sql_country .= ' WHERE f.name = \'id_country\''; Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql_country); //update state default $country = new Country($id_country_default); if (Validate::isLoadedObject($country) && $country->contains_states) { $states = State::getStatesByIdCountry($id_country_default); if (count($states)) { $id_state = $states[0]['id_state']; if (!empty($id_state)) { $sql_state = 'UPDATE '._DB_PREFIX_.'opc_field_shop fs'; $sql_state .= ' INNER JOIN '._DB_PREFIX_.'opc_field f ON f.id_field = fs.id_field'; $sql_state .= ' SET fs.default_value = \''.(int)$id_state.'\''; $sql_state .= ' WHERE f.name = \'id_state\''; Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($sql_state); } } } //remove class_cache.php $file_class_cache = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR. 'app'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.(_PS_MODE_DEV_ ? 'dev' : 'prod').DIRECTORY_SEPARATOR.'class_index.php'; if (file_exists($file_class_cache)) { unlink($file_class_cache); } //remove hook displayOverrideTemplate, else our module dont show. if ($ps_legalcompliance = $this->isModuleActive('ps_legalcompliance')) { $ps_legalcompliance->unregisterHook('displayOverrideTemplate'); } return true; } public function uninstall() { $query = 'DELETE FROM `'._DB_PREFIX_.'customer` WHERE id_customer = '.$this->config_vars['OPC_ID_CUSTOMER']; Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($query); $query = 'DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE id_customer = '.(int)$this->config_vars['OPC_ID_CUSTOMER']; Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($query); if (!parent::uninstall()) { return false; } return true; } public function getContent() { $forms = $this->getHelperForm(); if (is_array($forms) && count($forms) && isset($forms['forms']) && is_array($forms['forms']) && count($forms['forms']) ) { foreach ($forms['forms'] as $key => $form) { if (Tools::isSubmit('form-'.$key)) { $this->smarty->assign('CURRENT_FORM', $key); //save form data in configuration $this->saveFormData($form); //show message $this->smarty->assign('show_saved_message', true); break; } } } if (Tools::isSubmit('form-review')) { Configuration::updateValue('PS_CONDITIONS', $this->config_vars['OPC_ENABLE_TERMS_CONDITIONS']); Configuration::updateValue('PS_CONDITIONS_CMS_ID', $this->config_vars['OPC_ID_CMS_TEMRS_CONDITIONS']); } $this->displayErrors(); $this->displayForm(); return $this->html; } public function saveCustomConfigValue($option, &$config_var_value) { $config_var_value = $config_var_value; switch ($option['name']) { case 'redirect_directly_to_opc': if (Tools::getIsset('enable_guest_checkout')) { Configuration::updateValue('PS_GUEST_CHECKOUT_ENABLED', 1); } else { Configuration::updateValue('PS_GUEST_CHECKOUT_ENABLED', 0); } break; } } public function downloadFileTranslation() { $iso_code = Tools::getValue('iso_code'); $file_name = $iso_code.'.php'; $file_path = realpath($this->translation_dir.$file_name); if (file_exists($file_path)) { header("Content-Disposition: attachment; filename=".$iso_code.'.php'); header("Content-Type: application/octet-stream"); header("Content-Length: ".filesize($file_path)); readfile($file_path); exit; } } public function shareTranslation() { $iso_code = Tools::getValue('iso_code'); $file_name = $iso_code.'.php'; $file_path = realpath($this->translation_dir.$file_name); if (file_exists($file_path)) { $file_attachment = array(); $file_attachment['content'] = Tools::file_get_contents($file_path); $file_attachment['name'] = $iso_code.'.php'; $file_attachment['mime'] = 'application/octet-stream'; $sql = 'SELECT id_lang FROM '._DB_PREFIX_.'lang WHERE iso_code = "en"'; $id_lang = DB::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); if (empty($id_lang)) { $sql = 'SELECT id_lang FROM '._DB_PREFIX_.'lang WHERE iso_code = "es"'; $id_lang = DB::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } $data = Mail::Send( $id_lang, 'test', $_SERVER['SERVER_NAME'].' '.$this->l('he shared a translation with you'), array(), 'info@presteamshop.com', null, null, null, $file_attachment, null, _PS_MAIL_DIR_, null, $this->context->shop->id ); if ($data) { return array( 'message_code' => self::CODE_SUCCESS, 'message' => $this->l('Your translation has been sent, we will consider it for future upgrades of the module') ); } } return array( 'message_code' => self::CODE_ERROR, 'message' => $this->l('An error has occurred to attempt send the translation') ); } public function saveTranslations() { $data_translation = Tools::getValue('array_translation'); $iso_code_selected = Tools::getValue('lang'); $file_name = $iso_code_selected.'.php'; $file_path = realpath($this->translation_dir.$file_name); if (!file_exists($file_path)) { touch($file_path); } if (is_writable($file_path)) { $line = ''; $line .= ' $value) { foreach ($value as $data) { $data['key_translation'] = trim($data['key_translation']); $data['value_translation'] = trim($data['value_translation']); if (empty($data['value_translation'])) { continue; } $line .= '$_MODULE[\'<{'.$this->name.'}prestashop>'.$key.'_'; $line .= $data['key_translation'].'\'] = \''; $line .= str_replace("'", "\'", $data['value_translation']).'\';'."\n"; } } if (!file_put_contents($file_path, $line)) { return array( 'message_code' => self::CODE_ERROR, 'message' => $this->l('An error has occurred while attempting to save the translations') ); } else { $path_file_template = dirname(__FILE__).'/../../themes/'._THEME_NAME_.'/modules/'.$this->name.'/translations/'.$iso_code_selected.'.php'; if (file_exists($path_file_template)) { unlink($path_file_template); } return array( 'message_code' => self::CODE_SUCCESS, 'message' => $this->l('The translations have been successfully saved') ); } } else { return array( 'message_code' => self::CODE_ERROR, 'message' => $this->l('An error has occurred while attempting to save the translations') ); } } public function getTranslations() { if (isset($this->context->cookie->id_lang)) { $id_lang = $this->context->cookie->id_lang; } else { $id_lang = Configuration::get('PS_LANG_DEFAULT'); } $iso_code_selected = Language::getIsoById($id_lang); if (Tools::isSubmit('iso_code')) { $iso_code_selected = Tools::getValue('iso_code'); } $array_translate = $this->readFile($this->name, 'en'); if (sizeof($array_translate)) { $array_translate_lang_selected = $this->readFile($this->name, $iso_code_selected, true); if (Tools::isSubmit('iso_code')) { foreach ($array_translate_lang_selected as &$items_array_translate_lang) { if (in_array('', $items_array_translate_lang)) { $items_array_translate_lang['empty_elements'] = true; } } return array('message_code' => self::CODE_SUCCESS, 'data' => $array_translate_lang_selected); } foreach ($array_translate as $key_page => $translate_en) { foreach ($translate_en as $md5 => $label) { $label = $label; if (!empty($md5) && !empty($key_page)) { $array_translate[$key_page][$md5]['lang_selected'] = ''; if (sizeof($array_translate_lang_selected) && isset($array_translate_lang_selected[$key_page][$md5]) ) { $array_translate[$key_page][$md5]['lang_selected'] = $array_translate_lang_selected[$key_page][$md5]; if (empty($array_translate_lang_selected[$key_page][$md5])) { $array_translate[$key_page]['empty_elements'] = true; } } } } } } return $array_translate; } public function readFile($module, $iso_code, $detail = false) { $file_name = $iso_code.'.php'; $file_path = realpath($this->translation_dir.$file_name); if (!file_exists($file_path)) { return array(); } $file = fopen($file_path, 'r') or exit($this->l('Unable to open file')); $array_translate = array(); while (!feof($file)) { $line = fgets($file); $line_explode = explode('=', $line); $search_string = strpos($line_explode[0], '<{'.$module.'}prestashop>'); if (array_key_exists(1, $line_explode) && $search_string) { $file_md5 = str_replace("$"."_MODULE['<{".$module."}prestashop>", '', $line_explode[0]); $file_md5 = str_replace("']", '', trim($file_md5)); $explode_file_md5 = explode('_', $file_md5); $md5 = array_pop($explode_file_md5); $file_name = join('_', $explode_file_md5); $label_title = $file_name; $description_lang = str_replace(';', '', $line_explode[1]); $description_lang = str_replace("'", '', trim($description_lang)); if ($detail) { $array_translate[$label_title][$md5] = $description_lang; } else { $array_translate[$label_title][$md5] = array( $iso_code => str_replace("'", '', $description_lang) ); } } } fclose($file); return $array_translate; } protected function displayForm() { //update version module //--------------------------------------------------------------------------- $registered_version = Configuration::get($this->prefix_module.'_VERSION'); if ($registered_version != $this->version) { $this->installTab(); $this->smarty->assign(array( 'token' => Tools::encrypt($this->name.'/index'), 'module_name' => $this->displayName, 'module_version' => $this->version, 'url_call' => $this->context->link->getAdminLink('AdminActions'.$this->prefix_module) )); $this->html = $this->display(__FILE__, 'views/templates/admin/update_version.tpl'); return; } //--------------------------------------------------------------------------- $js_files = array(); $css_files = array(); //own bootstrap if ($this->context->language->is_rtl) { array_push($css_files, $this->_path.'views/css/lib/pts/pts-bootstrap_rtl.css'); } //sortable array_push($js_files, $this->_path.'views/js/lib/jquery/plugins/sortable/jquery-sortable.js'); array_push($css_files, $this->_path.'views/css/lib/jquery/plugins/sortable/jquery-sortable.css'); //fileinput array_push($js_files, $this->_path.'views/js/lib/bootstrap/plugins/fileinput/bootstrap-fileinput.js'); array_push($css_files, $this->_path.'views/css/lib/bootstrap/plugins/fileinput/bootstrap-fileinput.css'); //color picker array_push($js_files, $this->_path.'views/js/lib/bootstrap/plugins/colorpicker/bootstrap-colorpicker.js'); array_push($css_files, $this->_path.'views/css/lib/bootstrap/plugins/colorpicker/bootstrap-colorpicker.css'); //tab drop array_push($js_files, $this->_path.'views/js/lib/bootstrap/plugins/tabdrop/tabdrop.js'); array_push($css_files, $this->_path.'views/css/lib/bootstrap/plugins/tabdrop/tabdrop.css'); //totalStorage array_push($js_files, $this->_path.'views/js/lib/jquery/plugins/total-storage/jquery.total-storage.min.js'); //array_push($js_files, $this->_path.'views/js/lib/jquery/plugins/linedtextarea/jquery-linedtextarea.js'); //array_push($css_files, $this->_path.'views/css/lib/jquery/plugins/linedtextarea/jquery-linedtextarea.css'); $carriers = Carrier::getCarriers(Configuration::get('PS_LANG_DEFAULT'), true, false, false, null, 5); $payments = $this->getPaymentModulesInstalled(); $field_position = $this->getFieldsPosition(); $default_language = (int) Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(false); //ids lang $lang_separator = utf8_encode(chr(164)); $ids_flag = array('field_description', 'option_field_description', 'custom_field_description'); $ids_flag = join($lang_separator, $ids_flag); $iso = Language::getIsoById((int) Configuration::get('PS_LANG_DEFAULT')); $server_name = Tools::strtolower($_SERVER['SERVER_NAME']); $server_name = str_ireplace('www.', '', $server_name); //update files editor with configuration values. $this->updateContentCodeEditors(); $helper_form = $this->getHelperForm(); //extra tabs for PresTeamShop $this->getExtraTabs($helper_form); //Asignacion de varibles a tpl de administracion. $this->params_back = array( 'MODULE_PREFIX' => $this->prefix_module, 'DEFAULT_LENGUAGE' => $default_language, 'LANGUAGES' => $languages, 'ISO_LANG' => $iso, 'FLAGS_FIELD_DESCRIPTION' => $this->displayFlags( $languages, $default_language, $ids_flag, 'field_description', true ), 'FLAGS_CUSTOM_FIELD_DESCRIPTION' => $this->displayFlags( $languages, $default_language, $ids_flag, 'custom_field_description', true ), 'FLAGS_OPTION_FIELD_DESCRIPTION' => $this->displayFlags( $languages, $default_language, $ids_flag, 'option_field_description', true ), 'STATIC_TOKEN' => Tools::getAdminTokenLite('AdminModules'), 'HELPER_FORM' => $helper_form, 'JS_FILES' => $js_files, 'CSS_FILES' => $css_files, 'CARRIERS' => $carriers, 'PAYMENTS' => $payments, 'FIELDS_POSITION' => $field_position, 'GLOBALS_JS' => Tools::jsonEncode($this->globals), 'GROUPS_CUSTOMER' => Group::getGroups($this->cookie->id_lang), 'DISPLAY_NAME' => $this->displayName, 'CMS' => CMS::listCms($this->cookie->id_lang), 'SOCIAL_LOGIN' => Tools::jsonDecode($this->config_vars['OPC_SOCIAL_NETWORKS']), 'SHOP' => $this->context->shop, 'LINK' => $this->context->link, 'SHOP_PROTOCOL' => Tools::getShopProtocol(), 'array_label_translate' => $this->getTranslations(), 'id_lang' => $this->context->language->id, 'iso_lang_backoffice_shop' => Language::getIsoById($this->context->employee->id_lang), 'code_editors' => $this->codeEditors(), 'remote_addr' => Tools::getRemoteAddr() ); parent::displayForm(); $this->smarty->assign('paramsBack', $this->params_back); $this->html .= $this->display(__FILE__, 'views/templates/admin/header.tpl'); $this->html .= $this->display(__FILE__, 'views/templates/admin/configure.tpl'); } private function installLanguageShop($shops = array()) { if (empty($shops)) { $shops = Shop::getShops(); $shops = array_keys($shops); } elseif (is_array($shops)) { $shops = array_values($shops); } else { $shops = array($shops); } $sql_shops = Tools::file_get_contents(dirname(__FILE__).'/sql/shop.sql'); if ($sql_shops) { $sql_shops = str_replace('PREFIX_', _DB_PREFIX_, $sql_shops); foreach ($shops as $id_shop) { $sql_shop = str_replace('ID_SHOP', $id_shop, $sql_shops); $sql_shop = preg_split("/;\s*[\r\n]+/", $sql_shop); foreach ($sql_shop as $query_shop) { if (!Db::getInstance(_PS_USE_SQL_SLAVE_)->execute(trim($query_shop))) { return false; } } } } //install languages $languages = Language::getLanguages(false); foreach ($languages as $lang) { $iso_code = 'en'; if (file_exists(dirname(__FILE__).'/translations/sql/'.$lang['iso_code'].'.sql')) { $iso_code = $lang['iso_code']; } $sql_langs = Tools::file_get_contents(dirname(__FILE__).'/translations/sql/'.$iso_code.'.sql'); if ($sql_langs) { $sql_lang = str_replace('PREFIX_', _DB_PREFIX_, $sql_langs); $sql_lang = str_replace('ID_LANG', $lang['id_lang'], $sql_lang); foreach ($shops as $id_shop) { $sql_lang_shop = str_replace('ID_SHOP', $id_shop, $sql_lang); $sql_lang_shop = preg_split("/;\s*[\r\n]+/", $sql_lang_shop); foreach ($sql_lang_shop as $query_lang_shop) { if (!Db::getInstance(_PS_USE_SQL_SLAVE_)->execute(trim($query_lang_shop))) { return false; } } } } } } private function createCustomerOPC() { //create customer module opc //-------------------------------------------- $customer = new Customer(); $customer->firstname = 'OPC PTS Not Delete'; $customer->lastname = 'OPC PTS Not Delete'; $customer->email = 'noreply@presteamshop.com'; $customer->passwd = Tools::encrypt('OPC123456'); $customer->active = 0; $customer->deleted = 1; $cpfuser = $this->isModuleActive('cpfuser'); $pscielows = $this->isModuleActive('pscielows'); if ($cpfuser || $pscielows) { $customer->document = '.'; $customer->rg_ie = '.'; $customer->doc_type = '.'; } if (!$customer->add()) { return false; } else { Configuration::updateValue('OPC_ID_CUSTOMER', $customer->id); } //-------------------------------------------- } /** * Extra tabs for PresTeamShop * @param type $helper_form */ private function getExtraTabs(&$helper_form) { $helper_form['tabs']['translate'] = array( 'label' => $this->l('Translate'), 'href' => 'translate', 'icon' => 'globe' ); $helper_form['tabs']['code_editors'] = array( 'label' => $this->l('Code Editors'), 'href' => 'code_editors', 'icon' => 'code' ); if (file_exists(_PS_MODULE_DIR_.$this->name.'/docs/FAQs.json')) { $helper_form['tabs']['faqs'] = array( 'label' => $this->l('FAQs'), 'href' => 'faqs', 'icon' => 'question-circle' ); } $helper_form['tabs']['another_modules'] = array( 'label' => $this->l('Another modules'), 'href' => 'another_modules', 'icon' => 'cubes', ); $helper_form['tabs']['suggestions'] = array( 'label' => $this->l('Suggestions'), 'href' => 'suggestions', 'icon' => 'pencil' ); } public function codeEditors() { $code_editors = array( 'css' => array( array( 'filepath' => realpath(_PS_MODULE_DIR_.$this->name.'/views/css/front/override.css'), 'filename' => 'override', 'content' => Configuration::get('OPC_OVERRIDE_CSS') ) ), 'javascript' => array( array( 'filepath' => realpath(_PS_MODULE_DIR_.$this->name.'/views/js/front/override.js'), 'filename' => 'override', 'content' => Configuration::get('OPC_OVERRIDE_JS') ) ) ); return $code_editors; } public function updateContentCodeEditors() { $code_editors = $this->codeEditors(); foreach ($code_editors as $code_editor) { foreach ($code_editor as $value) { $filetype = pathinfo($value['filepath']); $content = ''; if ($filetype['extension'] === 'css') { $content = Configuration::get('OPC_OVERRIDE_CSS'); } elseif ($filetype['extension'] === 'js') { $content = Configuration::get('OPC_OVERRIDE_JS'); } if (!empty($content)) { $this->saveContentCodeEditors($value['filepath'], $content); } } } } public function saveContentCodeEditors($filepath = null, $content = null) { $content = (!is_null($content)) ? $content : urldecode(Tools::getValue('content')); $filepath = (!is_null($filepath)) ? $filepath : urldecode(Tools::getValue('filepath')); if (!file_exists($filepath)) { touch($filepath); } elseif (is_writable($filepath)) { $filetype = pathinfo($filepath); if ($filetype['extension'] === 'css') { Configuration::updateValue('OPC_OVERRIDE_CSS', $content); } elseif ($filetype['extension'] === 'js') { Configuration::updateValue('OPC_OVERRIDE_JS', $content); } $this->fillConfigVars(); file_put_contents($filepath, $content); } return array('message_code' => self::CODE_SUCCESS, 'message' => $this->l('The code was successfully saved')); } /** * Get position of fields * @return type array with positions in "group, row, col" order. */ public function getFieldsPosition() { //get fields $fields = FieldClass::getAllFields((int) $this->cookie->id_lang); $position = array(); foreach ($fields as $field) { $position[$field->group][$field->row][$field->col] = $field; } return $position; } private function getGeneralForm() { $payment_methods = array(array('id_module' => '', 'name' => '--')); $payment_methods_ori = PaymentModule::getInstalledPaymentModules(); foreach ($payment_methods_ori as $payment) { $payment_methods[] = $payment; } $options = array( 'enable_debug' => array( 'name' => 'enable_debug', 'prefix' => 'chk', 'label' => $this->l('Sandbox'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_ENABLE_DEBUG'], 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'depends' => array( 'ip_debug' => array( 'name' => 'ip_debug', 'prefix' => 'txt', 'label' => $this->l('IP'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_IP_DEBUG'], 'hidden_on' => false ) ) ), 'enable_guest_checkout' => array( 'name' => 'enable_guest_checkout', 'prefix' => 'chk', 'label' => $this->l('Enable guest checkout'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), ), 'redirect_directly_to_opc' => array( 'name' => 'redirect_directly_to_opc', 'prefix' => 'chk', 'label' => $this->l('Show shopping cart before checkout'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_REDIRECT_DIRECTLY_TO_OPC'], ), 'show_delivery_virtual' => array( 'name' => 'show_delivery_virtual', 'prefix' => 'chk', 'label' => $this->l('Show the delivery address for the purchase of virtual goods'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_DELIVERY_VIRTUAL'], ), 'default_payment_method' => array( 'name' => 'default_payment_method', 'prefix' => 'lst', 'label' => $this->l('Choose a default payment method'), 'type' => $this->globals->type_control->select, 'data' => $payment_methods, 'default_option' => $this->config_vars['OPC_DEFAULT_PAYMENT_METHOD'], 'option_value' => 'name', 'option_text' => 'name' ), 'default_group_customer' => array( 'name' => 'default_group_customer', 'prefix' => 'lst', 'label' => $this->l('Add new customers to the group'), 'type' => $this->globals->type_control->select, 'data' => Group::getGroups($this->cookie->id_lang), 'default_option' => $this->config_vars['OPC_DEFAULT_GROUP_CUSTOMER'], 'option_value' => 'id_group', 'option_text' => 'name', ), 'groups_customer_additional' => array( 'name' => 'groups_customer_additional', 'prefix' => 'lst', 'label' => $this->l('Add new customers in other groups'), 'type' => $this->globals->type_control->select, 'multiple' => true, 'data' => Group::getGroups($this->cookie->id_lang), 'selected_options' => $this->config_vars['OPC_GROUPS_CUSTOMER_ADDITIONAL'], 'option_value' => 'id_group', 'option_text' => 'name', 'condition' => array( 'compare' => $this->config_vars['OPC_DEFAULT_GROUP_CUSTOMER'], 'operator' => 'neq', 'value' => 'id_group', ), ), 'validate_dni' => array( 'name' => 'validate_dni', 'prefix' => 'chk', 'label' => $this->l('Validate DNI/CIF/NIF Spain'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_VALIDATE_DNI'], ), 'id_content_page' => array( 'name' => 'id_content_page', 'prefix' => 'txt', 'label' => $this->l('Container page (HTML)'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_ID_CONTENT_PAGE'], ), 'id_customer' => array( 'name' => 'id_customer', 'prefix' => 'txt', 'label' => $this->l('Customer ID'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_ID_CUSTOMER'], 'tooltip' => array( 'warning' => array( 'title' => $this->l('Warning'), 'content' => $this->l('Do not change unless you understand its functionality.'), ), ), ) ); $form = array( 'tab' => 'general', 'method' => 'post', 'actions' => array( 'save' => array( 'label' => $this->l('Save'), 'class' => 'save-general', 'icon' => 'save', ), ), 'options' => $options ); return $form; } private function getRegisterForm() { $options = array( 'show_button_register' => array( 'name' => 'show_button_register', 'prefix' => 'chk', 'label' => $this->l('Show button "Save Information"'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_BUTTON_REGISTER'], ), 'capitalize_fields' => array( 'name' => 'capitalize_fields', 'prefix' => 'chk', 'label' => $this->l('Capitalize fields'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_CAPITALIZE_FIELDS'], ), 'enable_privacy_policy' => array( 'name' => 'enable_privacy_policy', 'prefix' => 'chk', 'label' => $this->l('Require acceptance of privacy policy before buying'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_ENABLE_PRIVACY_POLICY'], 'depends' => array( 'id_cms_privacy_policy' => array( 'name' => 'id_cms_privacy_policy', 'prefix' => 'lst', 'type' => $this->globals->type_control->select, 'data' => CMS::listCms($this->cookie->id_lang), 'default_option' => $this->config_vars['OPC_ID_CMS_PRIVACY_POLICY'], 'hidden_on' => false, 'option_value' => 'id_cms', 'option_text' => 'meta_title', ), ) ), 'enable_invoice_address' => array( 'name' => 'enable_invoice_address', 'prefix' => 'chk', 'label' => $this->l('Request invoice address'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_ENABLE_INVOICE_ADDRESS'], 'data_toggle' => true, 'depends' => array( 'required_invoice_address' => array( 'name' => 'required_invoice_address', 'prefix' => 'chk', 'label' => $this->l('Required'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_REQUIRED_INVOICE_ADDRESS'], 'hidden_on' => false, ), 'use_same_name_contact_ba' => array( 'name' => 'use_same_name_contact_ba', 'prefix' => 'chk', 'label' => $this->l('Use the same first name and last name for the customers invoice address'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_USE_SAME_NAME_CONTACT_BA'], 'hidden_on' => false, ), ), ), 'use_same_name_contact_da' => array( 'name' => 'use_same_name_contact_da', 'prefix' => 'chk', 'label' => $this->l('Use the same first name and last name for the customers delivery address'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_USE_SAME_NAME_CONTACT_DA'], ), 'request_confirm_email' => array( 'name' => 'request_confirm_email', 'prefix' => 'chk', 'label' => $this->l('Request confirmation email'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_REQUEST_CONFIRM_EMAIL'], ), 'request_password' => array( 'name' => 'request_password', 'prefix' => 'chk', 'label' => $this->l('Password request'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_REQUEST_PASSWORD'], 'depends' => array( 'option_autogenerate_password' => array( 'name' => 'option_autogenerate_password', 'prefix' => 'chk', 'label' => $this->l('Option to auto-generate'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_OPTION_AUTOGENERATE_PASSWORD'], 'hidden_on' => false, 'class' => 'option_autogenerate_password', ), ), ), 'choice_group_customer' => array( 'name' => 'choice_group_customer', 'prefix' => 'chk', 'label' => $this->l('Show customer group list'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_CHOICE_GROUP_CUSTOMER'], 'depends' => array( 'choice_group_customer_allow' => array( 'name' => 'choice_group_customer_allow', 'prefix' => 'lst', 'hidden_on' => false, 'type' => $this->globals->type_control->select, 'multiple' => true, 'data' => Group::getGroups($this->cookie->id_lang), 'selected_options' => $this->config_vars['OPC_CHOICE_GROUP_CUSTOMER_ALLOW'], 'option_value' => 'id_group', 'option_text' => 'name', 'tooltip' => array( 'warning' => array( 'title' => $this->l('Warning'), 'content' => $this->l('If you choose a group then only the selected groups will be shown, otherwise all groups will be shown.'), ), ), ), ), ), 'show_list_cities_geonames' => array( 'name' => 'show_list_cities_geonames', 'prefix' => 'chk', 'label' => $this->l('Show list of cities using Geonames.org'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_LIST_CITIES_GEONAMES'], ), 'auto_address_geonames' => array( 'name' => 'auto_address_geonames', 'prefix' => 'chk', 'label' => $this->l('Use address autocomplete from Geonames.org'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_AUTO_ADDRESS_GEONAMES'], ), 'autocomplete_google_address' => array( 'name' => 'autocomplete_google_address', 'prefix' => 'chk', 'label' => $this->l('Use address autocomplete from Google'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_AUTOCOMPLETE_GOOGLE_ADDRESS'], 'data_toggle' => true, 'depends' => array( 'google_api_key' => array( 'name' => 'google_api_key', 'prefix' => 'txt', 'label' => $this->l('Google API KEY'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_GOOGLE_API_KEY'], 'hidden_on' => false, ), ), ), ); $form = array( 'tab' => 'register', 'method' => 'post', 'actions' => array( 'save' => array( 'label' => $this->l('Save'), 'class' => 'save-register', 'icon' => 'save', ), 'delete_address' => array( 'label' => $this->l('Delete empty addresses'), 'class' => 'delete-address', 'icon' => 'trash', ) ), 'options' => $options, ); return $form; } private function getShippingForm() { $options = array( 'show_description_carrier' => array( 'name' => 'show_description_carrier', 'prefix' => 'chk', 'label' => $this->l('Show description of carriers'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_DESCRIPTION_CARRIER'], ), 'show_image_carrier' => array( 'name' => 'show_image_carrier', 'prefix' => 'chk', 'label' => $this->l('Show image of carriers'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_IMAGE_CARRIER'], ), 'reload_shipping_by_state' => array( 'name' => 'reload_shipping_by_state', 'prefix' => 'chk', 'label' => $this->l('Reload shipping when changing state'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_RELOAD_SHIPPING_BY_STATE'], ), 'force_need_postcode' => array( 'name' => 'force_need_postcode', 'prefix' => 'chk', 'label' => $this->l('Require a postal code to be entered'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_FORCE_NEED_POSTCODE'], 'data_toggle' => true ), 'module_carrier_need_postcode' => array( 'name' => 'module_carrier_need_postcode', 'prefix' => 'txt', 'label' => $this->l('Carrier module that requires a postal code'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_MODULE_CARRIER_NEED_POSTCODE'], 'hidden_on' => $this->config_vars['OPC_FORCE_NEED_POSTCODE'], ), 'force_need_city' => array( 'name' => 'force_need_city', 'prefix' => 'chk', 'label' => $this->l('Require a city to be entered'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_FORCE_NEED_CITY'], 'data_toggle' => true ), 'module_carrier_need_city' => array( 'name' => 'module_carrier_need_city', 'prefix' => 'txt', 'label' => $this->l('Carrier module that requires a city'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_MODULE_CARRIER_NEED_CITY'], 'hidden_on' => $this->config_vars['OPC_FORCE_NEED_CITY'], ) ); $form = array( 'tab' => 'shipping', 'method' => 'post', 'actions' => array( 'save' => array( 'label' => $this->l('Save'), 'class' => 'save-shipping', 'icon' => 'save', ), ), 'options' => $options, ); return $form; } private function getPaymentForm() { //$popup_lang = $this->l('If you enable this option, some payment methods stop working. We recommend testing the operation.'); $options = array( 'show_image_payment' => array( 'name' => 'show_image_payment', 'prefix' => 'chk', 'label' => $this->l('Show images of payment methods'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_IMAGE_PAYMENT'] ), 'show_detail_payment' => array( 'name' => 'show_detail_payment', 'prefix' => 'chk', 'label' => $this->l('Show detailed description of payment methods'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_DETAIL_PAYMENT'] ) /*'show_popup_payment' => array( 'name' => 'show_popup_payment', 'prefix' => 'chk', 'label' => $this->l('Show popup window payment'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_POPUP_PAYMENT'], 'data_toggle' => true, 'tooltip' => array( 'information' => array( 'title' => $this->l('Information'), 'content' => $popup_lang, ), ), ), 'payments_without_radio' => array( 'name' => 'payments_without_radio', 'prefix' => 'chk', 'label' => $this->l('Activate compatibility with non-supported payment methods'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_PAYMENTS_WITHOUT_RADIO'], ), 'modules_without_popup' => array( 'name' => 'modules_without_popup', 'prefix' => 'ta', 'label' => $this->l('Deactivate a modules popup window'), 'type' => $this->globals->type_control->textarea, 'value' => $this->config_vars['OPC_MODULES_WITHOUT_POPUP'], 'data_hide' => 'show_popup_payment', ),*/ ); $form = array( 'tab' => 'payment_general', 'method' => 'post', 'actions' => array( 'save' => array( 'label' => $this->l('Save'), 'class' => 'save-payment', 'icon' => 'save', ), ), 'options' => $options, ); return $form; } private function getReviewForm() { $options = array( 'enable_terms_conditions' => array( 'name' => 'enable_terms_conditions', 'prefix' => 'chk', 'label' => $this->l('Require acceptance of terms and conditions before buying'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_ENABLE_TERMS_CONDITIONS'], 'depends' => array( 'id_cms_temrs_conditions' => array( 'name' => 'id_cms_temrs_conditions', 'prefix' => 'lst', 'type' => $this->globals->type_control->select, 'data' => CMS::listCms($this->cookie->id_lang), 'default_option' => $this->config_vars['OPC_ID_CMS_TEMRS_CONDITIONS'], 'hidden_on' => false, 'option_value' => 'id_cms', 'option_text' => 'meta_title', ), ), ), 'show_link_continue_shopping' => array( 'name' => 'show_link_continue_shopping', 'prefix' => 'chk', 'label' => $this->l('Show "Continue Shopping" link'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_LINK_CONTINUE_SHOPPING'], 'data_toggle' => true, 'depends' => array( 'link_continue_shopping' => array( 'name' => 'link_continue_shopping', 'prefix' => 'txt', 'label' => $this->l('Custom URL for the "Continue shopping" button'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_LINK_CONTINUE_SHOPPING'], 'hidden_on' => false, 'data_hide' => 'show_link_continue_shopping' ) ) ), 'compatibility_review' => array( 'name' => 'compatibility_review', 'prefix' => 'chk', 'label' => $this->l('Show compatibility summary'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_COMPATIBILITY_REVIEW'], 'data_toggle' => true, 'depends' => array( 'show_voucher_box' => array( 'name' => 'show_voucher_box', 'prefix' => 'chk', 'label' => $this->l('Show voucher box'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_VOUCHER_BOX'], 'hidden_on' => true, 'tooltip' => array( 'warning' => array( 'title' => $this->l('Warning'), 'content' => $this->l('So have enabled this option, you must have discounts created to be shown.'), ), ) ), 'show_zoom_image_product' => array( 'name' => 'show_zoom_image_product', 'prefix' => 'chk', 'label' => $this->l('Show zoom on image product'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_ZOOM_IMAGE_PRODUCT'], 'hidden_on' => true ), 'show_total_product' => array( 'name' => 'show_total_product', 'prefix' => 'chk', 'label' => $this->l('Show total of products'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_TOTAL_PRODUCT'], 'hidden_on' => true ), 'show_total_discount' => array( 'name' => 'show_total_discount', 'prefix' => 'chk', 'label' => $this->l('Show total discount'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_TOTAL_DISCOUNT'], 'hidden_on' => true ), 'show_total_wrapping' => array( 'name' => 'show_total_wrapping', 'prefix' => 'chk', 'label' => $this->l('Show gift wrapping total'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_TOTAL_WRAPPING'], 'data_hide' => 'compatibility_review', 'hidden_on' => true ), 'show_total_shipping' => array( 'name' => 'show_total_shipping', 'prefix' => 'chk', 'label' => $this->l('Show shipping total'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_TOTAL_SHIPPING'], 'hidden_on' => true ), 'show_total_without_tax' => array( 'name' => 'show_total_without_tax', 'prefix' => 'chk', 'label' => $this->l('Show total excluding tax'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_TOTAL_WITHOUT_TAX'], 'hidden_on' => true ), 'show_total_tax' => array( 'name' => 'show_total_tax', 'prefix' => 'chk', 'label' => $this->l('Show total tax'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_TOTAL_TAX'], 'hidden_on' => true ), 'show_total_price' => array( 'name' => 'show_total_price', 'prefix' => 'chk', 'label' => $this->l('Show total'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_TOTAL_PRICE'], 'data_hide' => 'compatibility_review', 'hidden_on' => true ), 'show_remaining_free_shipping' => array( 'name' => 'show_remaining_free_shipping', 'prefix' => 'chk', 'label' => $this->l('Show amount remaining to qualify for free shipping'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_REMAINING_FREE_SHIPPING'], 'hidden_on' => true ), 'show_weight' => array( 'name' => 'show_weight', 'prefix' => 'chk', 'label' => $this->l('Show weight'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_WEIGHT'], 'hidden_on' => true ), 'show_reference' => array( 'name' => 'show_reference', 'prefix' => 'chk', 'label' => $this->l('Show reference'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_REFERENCE'], 'data_hide' => 'compatibility_review', 'hidden_on' => true ), 'show_unit_price' => array( 'name' => 'show_unit_price', 'prefix' => 'chk', 'label' => $this->l('Show unit price'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_UNIT_PRICE'], 'hidden_on' => true ), 'show_availability' => array( 'name' => 'show_availability', 'prefix' => 'chk', 'label' => $this->l('Show availability'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_SHOW_AVAILABILITY'], 'hidden_on' => true ), 'enable_hook_shopping_cart' => array( 'name' => 'enable_hook_shopping_cart', 'prefix' => 'chk', 'label' => $this->l('Enable hook shopping cart'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_ENABLE_HOOK_SHOPPING_CART'], 'hidden_on' => true ) ) ) ); $form = array( 'tab' => 'review', 'method' => 'post', 'actions' => array( 'save' => array( 'label' => $this->l('Save'), 'class' => 'save-review', 'icon' => 'save', ), ), 'options' => $options, ); return $form; } private function getThemeForm() { $options = array( 'theme_background_color' => array( 'name' => 'theme_background_color', 'prefix' => 'txt', 'label' => $this->l('Background color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_BACKGROUND_COLOR'], 'color' => true ), 'theme_border_color' => array( 'name' => 'theme_border_color', 'prefix' => 'txt', 'label' => $this->l('Border color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_BORDER_COLOR'], 'color' => true ), 'theme_icon_color' => array( 'name' => 'theme_icon_color', 'prefix' => 'txt', 'label' => $this->l('Color of images'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_ICON_COLOR'], 'color' => true ), 'theme_text_color' => array( 'name' => 'theme_text_color', 'prefix' => 'txt', 'label' => $this->l('Text color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_TEXT_COLOR'], 'color' => true ), 'theme_selected_color' => array( 'name' => 'theme_selected_color', 'prefix' => 'txt', 'label' => $this->l('Carrier and Payment selected color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_SELECTED_COLOR'], 'color' => true ), 'theme_selected_text_color' => array( 'name' => 'theme_selected_text_color', 'prefix' => 'txt', 'label' => $this->l('Carrier and Payment selected text color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_SELECTED_TEXT_COLOR'], 'color' => true ), 'theme_confirm_color' => array( 'name' => 'theme_confirm_color', 'prefix' => 'txt', 'label' => $this->l('Checkout button color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_CONFIRM_COLOR'], 'color' => true ), 'theme_confirm_text_color' => array( 'name' => 'theme_confirm_text_color', 'prefix' => 'txt', 'label' => $this->l('Text color of checkout button'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_CONFIRM_TEXT_COLOR'], 'color' => true ), 'already_register_button' => array( 'name' => 'already_register_button', 'prefix' => 'txt', 'label' => $this->l('Already register button color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_ALREADY_REGISTER_BUTTON'], 'color' => true ), 'already_register_button_text' => array( 'name' => 'already_register_button_text', 'prefix' => 'txt', 'label' => $this->l('Already register text button color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_ALREADY_REGISTER_BUTTON_TEXT'], 'color' => true ), 'theme_login_button' => array( 'name' => 'theme_login_button', 'prefix' => 'txt', 'label' => $this->l('Login button color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_LOGIN_BUTTON'], 'color' => true ), 'theme_login_button_text' => array( 'name' => 'theme_login_button_text', 'prefix' => 'txt', 'label' => $this->l('Login text button color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_LOGIN_BUTTON_TEXT'], 'color' => true ), 'theme_voucher_button' => array( 'name' => 'theme_voucher_button', 'prefix' => 'txt', 'label' => $this->l('Voucher button color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_VOUCHER_BUTTON'], 'color' => true ), 'theme_voucher_button_text' => array( 'name' => 'theme_voucher_button_text', 'prefix' => 'txt', 'label' => $this->l('Voucher text button color'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_VOUCHER_BUTTON_TEXT'], 'color' => true ), 'confirmation_button_float' => array( 'name' => 'confirmation_button_float', 'prefix' => 'chk', 'label' => $this->l('Show confirmation button float'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => $this->config_vars['OPC_CONFIRMATION_BUTTON_FLOAT'], 'data_toggle' => true, 'depends' => array( 'background_button_footer' => array( 'name' => 'background_button_footer', 'prefix' => 'txt', 'label' => $this->l('Background color float confirmation button'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_BACKGROUND_BUTTON_FOOTER'], 'color' => true, 'hidden_on' => false, 'data_hide' => 'confirmation_button_float' ), 'theme_border_button_footer' => array( 'name' => 'theme_border_button_footer', 'prefix' => 'txt', 'label' => $this->l('Border color float confirmation button'), 'type' => $this->globals->type_control->textbox, 'value' => $this->config_vars['OPC_THEME_BORDER_BUTTON_FOOTER'], 'color' => true, 'hidden_on' => false, 'data_hide' => 'confirmation_button_float' ) ) ), ); $form = array( 'tab' => 'theme', 'method' => 'post', 'actions' => array( 'save' => array( 'label' => $this->l('Save'), 'class' => 'save-theme', 'icon' => 'save', ), ), 'options' => $options, ); return $form; } private function getRequiredFieldsForm() { $options = array( 'field_id' => array( 'name' => 'id_field', 'prefix' => 'hdn', 'type' => 'hidden', ), 'field_object' => array( 'name' => 'field_object', 'prefix' => 'lst', 'label' => $this->l('Object'), 'type' => $this->globals->type_control->select, 'data' => $this->globals->object, ), 'field_name' => array( 'name' => 'field_name', 'prefix' => 'txt', 'label' => $this->l('Name'), 'type' => $this->globals->type_control->textbox, ), 'field_description' => array( 'name' => 'field_description', 'prefix' => 'txt', 'label' => $this->l('Description'), 'type' => $this->globals->type_control->textbox, 'multilang' => true, ), 'field_type' => array( 'name' => 'field_type', 'prefix' => 'lst', 'label' => $this->l('Type'), 'type' => $this->globals->type_control->select, 'data' => $this->globals->type, 'key_as_value' => true, ), 'field_size' => array( 'name' => 'field_size', 'prefix' => 'txt', 'label' => $this->l('Size'), 'type' => $this->globals->type_control->textbox, ), 'field_type_control' => array( 'name' => 'field_type_control', 'prefix' => 'lst', 'label' => $this->l('Type control'), 'type' => $this->globals->type_control->select, 'data' => $this->globals->type_control, ), 'field_default_value' => array( 'name' => 'field_default_value', 'prefix' => 'txt', 'label' => $this->l('Default value'), 'type' => $this->globals->type_control->textbox, ), 'field_required' => array( 'name' => 'field_required', 'prefix' => 'chk', 'label' => $this->l('Required'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => true, ), 'field_active' => array( 'name' => 'field_active', 'prefix' => 'chk', 'label' => $this->l('Active'), 'label_on' => $this->l('YES'), 'label_off' => $this->l('NO'), 'type' => $this->globals->type_control->checkbox, 'check_on' => true, ), ); $list = $this->getRequiredFieldList(); $form = array( 'id' => 'form_required_fields', 'tab' => 'required_fields', 'class' => 'hidden', 'modal' => true, 'actions' => array( 'save' => array( 'label' => $this->l('Save'), 'name' => 'update_field', 'icon' => 'save', ) ), 'options' => $options, 'list' => $list, ); return $form; } private function getSocialSubTabs() { $social_networks = Tools::jsonDecode($this->config_vars['OPC_SOCIAL_NETWORKS']); $sub_tabs = array(); if ($social_networks) { foreach ($social_networks as $name => $social_network) { $sub_tabs[] = array( 'label' => $social_network->name_network, 'href' => 'social_login_'.$name, 'icon' => $social_network->class_icon, ); } } return $sub_tabs; } private function getHelperTabs() { $tabs = array( 'general' => array( 'label' => $this->l('General'), 'href' => 'general', ), 'register' => array( 'label' => $this->l('Register'), 'href' => 'register', 'icon' => 'user', ), 'shipping' => array( 'label' => $this->l('Shipping'), 'href' => 'shipping', 'icon' => 'truck', ), 'payment' => array( 'label' => $this->l('Payment'), 'href' => 'payment', 'icon' => 'credit-card', 'sub_tab' => array( 'payment_general' => array( 'label' => $this->l('General'), 'href' => 'payment_general', 'icon' => 'cogs', ), 'pay_methods' => array( 'label' => $this->l('Pay methods'), 'href' => 'pay_methods', 'icon' => 'credit-card', ), 'ship_pay' => array( 'label' => $this->l('Ship to Pay'), 'href' => 'ship_pay', 'icon' => 'truck', ), ), ), 'review' => array( 'label' => $this->l('Review'), 'href' => 'review', 'icon' => 'check', ), 'theme' => array( 'label' => $this->l('Theme'), 'href' => 'theme', 'icon' => 'paint-brush', ), 'required_fields' => array( 'label' => $this->l('Fields register'), 'href' => 'required_fields', 'icon' => 'pencil-square-o', ), 'fields_position' => array( 'label' => $this->l('Fields position'), 'href' => 'fields_position', 'icon' => 'arrows', ), 'social_login' => array( 'label' => $this->l('Social login'), 'href' => 'social_login', 'icon' => 'share-alt', 'sub_tab' => $this->getSocialSubTabs(), ) ); return $tabs; } private function getHelperForm() { $tabs = $this->getHelperTabs(); $general = $this->getGeneralForm(); $register = $this->getRegisterForm(); $shipping = $this->getShippingForm(); $payment = $this->getPaymentForm(); $review = $this->getReviewForm(); $theme = $this->getThemeForm(); $fields_register = $this->getRequiredFieldsForm(); $form = array( 'title' => $this->l('Menu'), 'tabs' => $tabs, 'forms' => array( 'general' => $general, 'register' => $register, 'shipping' => $shipping, 'payment_general' => $payment, 'review' => $review, 'theme' => $theme, 'fields_register' => $fields_register, ), ); return $form; } private function getPaymentModulesInstalled() { //get payments $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT m.`id_module`, h.`id_hook`, m.`name`, hm.`position` FROM `'._DB_PREFIX_.'module` m LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON (hm.`id_module` = m.`id_module` AND hm.id_shop='.(int) $this->context->shop->id.') LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook` INNER JOIN `'._DB_PREFIX_.'module_shop` ms ON (m.`id_module` = ms.`id_module` AND ms.id_shop='.(int) $this->context->shop->id.') WHERE h.`name` = "PaymentOptions" '); if ($result) { foreach ($result as &$row) { $row['force_display'] = 0; $row['name_image'] = $row['name'].'.gif'; $id_payment = PaymentClass::getIdPaymentBy('name', $row['name']); if (!empty($id_payment)) { $payment = new PaymentClass($id_payment); if (Validate::isLoadedObject($payment)) { $row['data']['title'] = $payment->title; $row['data']['description'] = $payment->description; if (!empty($payment->name_image)) { $row['name_image'] = $payment->name_image; } $row['force_display'] = $payment->force_display; $payment->id_module = $row['id_module']; $payment->update(); } } } } else { Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('TRUNCATE TABLE '._DB_PREFIX_.'opc_payment'); Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('TRUNCATE TABLE '._DB_PREFIX_.'opc_payment_lang'); Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('TRUNCATE TABLE '._DB_PREFIX_.'opc_payment_shop'); } return $result; } public function saveSocialLogin() { $data = Tools::getValue('data'); $social_networks = Tools::jsonDecode($this->config_vars['OPC_SOCIAL_NETWORKS']); foreach ($data['values'] as $key => $value) { $social_networks->{$data['social_network']}->{$key} = trim($value); } Configuration::updateValue('OPC_SOCIAL_NETWORKS', Tools::jsonEncode($social_networks)); return array( 'message_code' => self::CODE_SUCCESS, 'message' => $this->l('Social login data updated successful') ); } public function getOptionsByField() { $id_field = Tools::getValue('id_field'); $options = FieldOptionClass::getOptionsByIdField($id_field); //return result return array('message_code' => self::CODE_SUCCESS, 'options' => $options); } public function saveOptionsByField() { $id_field = Tools::getValue('id_field'); $options = Tools::getValue('options'); if (!empty($options)) { foreach ($options as $option) { if (empty($option['id_option']) || (int) $option['id_option'] === 0) { $option['id_option'] = null; } $field_option = new FieldOptionClass($option['id_option']); $description_value = array(); foreach ($option['description'] as $description) { $description_value[$description['id_lang']] = $description['value']; } $field_option->id_field = $id_field; $field_option->value = $option['value']; $field_option->description = $description_value; $field_option->save(); } } $options_to_remove = Tools::getValue('options_to_remove'); if (!empty($options_to_remove)) { foreach ($options_to_remove as $option_to_remove) { $field_option = new FieldOptionClass($option_to_remove); $field_option->delete(); } } //return result return array('message_code' => self::CODE_SUCCESS, 'message' => $this->l('Options updated successful.')); } public function getFieldsByObject() { $object_name = Tools::getValue('object'); $fields_db = FieldClass::getAllFields( $this->cookie->id_lang, $this->context->shop->id, $object_name, null, null, null, null, true ); $fields = array(); foreach ($fields_db as $field) { $fields[] = array( 'id_field' => $field->id, 'name' => $field->name, 'description' => $field->description, ); } //return result return array('message_code' => self::CODE_SUCCESS, 'fields' => $fields); } /** * Save field positions */ public function saveFieldsPosition() { //update positions $positions = Tools::getValue('positions'); if (is_array($positions) && count($positions)) { foreach ($positions as $row => $cols) { if (is_array($cols) && count($cols)) { foreach ($cols as $col => $data) { $field = new FieldClass($data['id_field']); $field->group = $data['group']; $field->row = $row; $field->col = $col; $field->save(); } } } } //return result return array('message_code' => self::CODE_SUCCESS, 'message' => $this->l('Positions updated successful.')); } /** * Toggle required fieldstatus. * @return type array */ public function toggleActiveField() { if (Tools::isSubmit('id_field')) { $field_class = new FieldClass((int) Tools::getValue('id_field')); if (Validate::isLoadedObject($field_class)) { $field_class->active = !$field_class->active; if ($field_class->update()) { return array( 'message_code' => self::CODE_SUCCESS, 'message' => $this->l('Field updated successful.'), ); } } } return array( 'message_code' => self::CODE_ERROR, 'message' => $this->l('An error occurred while trying to update.') ); } /** * Toggle required fieldstatus. * @return type array */ public function toggleRequiredField() { if (Tools::isSubmit('id_field')) { $field_class = new FieldClass((int) Tools::getValue('id_field')); if (Validate::isLoadedObject($field_class)) { $field_class->required = !$field_class->required; if ($field_class->update()) { return array( 'message_code' => self::CODE_SUCCESS, 'message' => $this->l('Field updated successful.'), ); } } } return array( 'message_code' => self::CODE_ERROR, 'message' => $this->l('An error occurred while trying to update.') ); } /** * Remove associations of shipment and payment, then will create again from data form. * @return type array */ public function updateShipToPay() { if (!Tools::isSubmit('payment_carrier')) { return array( 'message_code' => self::CODE_ERROR, 'message' => $this->l('An error occurred while trying to update.') ); } $carriers = Tools::getValue('payment_carrier'); //Reset table asociations $query = 'DELETE FROM '._DB_PREFIX_.'module_carrier WHERE id_shop = '.(int)$this->context->shop->id; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->execute($query); //Create new asociations from form $error = false; if ($result) { foreach ($carriers as $carrier) { if (isset($carrier['payments']) && is_array($carrier['payments']) && count($carrier['payments'])) { foreach ($carrier['payments'] as $id_module) { $values = array( 'id_reference' => $carrier['id_reference'], 'id_module' => $id_module, 'id_shop' => (int)$this->context->shop->id, ); if (!Db::getInstance(_PS_USE_SQL_SLAVE_)->insert('module_carrier', $values)) { $error = true; } } } } } if (!$error) { return array( 'message_code' => self::CODE_SUCCESS, 'message' => $this->l('The associations are updated correctly.') ); } else { return array( 'message_code' => self::CODE_ERROR, 'message' => $this->l('An error occurred while trying to update.') ); } } /** * Get data of carriers-payment asociation * @return type array */ public function getAssociationsShipToPay() { $sql = new DbQuery(); $sql->select('*'); $sql->from('module_carrier'); $sql->where('`id_shop` = '.(int)$this->context->shop->id); $carriers = Db::getInstance()->executeS($sql); return array('message_code' => self::CODE_SUCCESS, 'carriers' => $carriers); } /** * Sort fields. * @return type array */ public function updateFieldsPosition() { if (!Tools::isSubmit('order_fields')) { return array('message_code' => self::CODE_ERROR, 'message' => $this->l('Error to update fields position')); } $order_fields = Tools::getValue('order_fields'); $position = 1; $errors_field = array(); $message_code = self::CODE_SUCCESS; if (is_array($order_fields) && count($order_fields)) { foreach ($order_fields as $id_field) { if (!Db::getInstance(_PS_USE_SQL_SLAVE_)->update( 'opc_field', array('position' => $position), 'id_field = '.$id_field ) ) { $field_class = new FieldClass((int) $id_field); $errors_field[] = $field_class->name; } $position++; } } $message = $this->l('Sort positions of fields has been updated successful'); if (count($errors_field)) { $fields = implode(', ', $errors_field); $message = $this->l('Error to update position for field(s)').': '.$fields; $message_code = self::CODE_ERROR; } return array( 'message_code' => $message_code, 'message' => $message, ); } public function removeField() { $id_field = (int) Tools::getValue('id_field', null); if (empty($id_field) || (int) $id_field === 0) { return array('message_code' => self::CODE_ERROR, 'message' => $this->l('No field selected to remove.')); } $field_class = new FieldClass($id_field); if ((int) $field_class->is_custom === 0) { return array('message_code' => self::CODE_ERROR, 'message' => $this->l('Cannot remove this field.')); } if (!$field_class->delete()) { return array( 'message_code' => self::CODE_ERROR, 'message' => $this->l('An error occurred while trying to remove.') ); } return array('message_code' => self::CODE_SUCCESS, 'message' => $this->l('Field remove successful.')); } /** * Save the field data. * @return type array */ public function updateField() { if (!Tools::isSubmit('id_field')) { return array( 'message_code' => self::CODE_ERROR, 'message' => $this->l('An error occurred while trying to update.') ); } $id_field = (int) Tools::getValue('id_field', null); if (empty($id_field) || (int) $id_field === 0) { $id_field = null; } $field_class = new FieldClass($id_field); if (is_null($id_field)) { $field_class->is_custom = true; } $array_description = array(); $descriptions = Tools::getValue('description'); foreach ($descriptions as $description) { $array_description[$description['id_lang']] = $description['description']; } $field_class->description = $array_description; //only if field is custom can update data. if ($field_class->is_custom) { $field_class->name = Tools::getValue('name'); $field_class->object = Tools::getValue('object'); $field_class->type = Tools::getValue('type'); $field_class->size = (int) Tools::getValue('size'); $field_class->type_control = Tools::getValue('type_control'); //shop $field_class->group = $field_class->object; $field_class->row = (int) FieldClass::getLastRowByGroup($field_class->group) + 1; $field_class->col = 0; } $default_value = Tools::getValue('default_value'); // if ($field_class->type == $this->globals->type->string) // $default_value = Tools::substr($default_value, 0, $field_class->size); $field_class->default_value = $default_value; $field_class->required = (int) Tools::getValue('required'); $field_class->active = (int) Tools::getValue('active'); if ($field_class->validateFieldsLang(false) && $field_class->save()) { $result = array( 'message_code' => self::CODE_SUCCESS, 'message' => $this->l('The field was successfully updated.'), 'description' => $array_description[$this->cookie->id_lang], 'default_value' => $field_class->default_value, ); if (is_null($id_field)) { $result['id_field'] = $field_class->id; } } else { $result = array( 'message_code' => self::CODE_ERROR, 'message' => $this->l('An error occurred while trying to update.'), ); } return $result; } public function removeImagePayment() { $errors = array(); $id_module = Tools::getValue('id_module'); $name_payment = Tools::getValue('name_module'); $id_payment = PaymentClass::getIdPaymentBy('id_module', $id_module); $paymentClass = new PaymentClass($id_payment); $paymentClass->name_image = 'no-image.png'; $paymentClass->id_module = $id_module; $paymentClass->name = $name_payment; if (!$paymentClass->save()) { $errors[] = $this->l('There was an error while trying to delete the image.'); } if (!empty($errors)) { return array('message_code' => self::CODE_ERROR, 'message' => implode(', ', $errors)); } else { return array( 'message_code' => self::CODE_SUCCESS, 'message' => $this->l('Image deleted successfully.'), ); } } /** * * @param string $name * @return type */ public function uploadImage() { $errors = array(); $id_module = Tools::getValue('id_module'); $force_display = Tools::getValue('force_display'); $payment_data = Tools::getValue('payment_data'); $id_payment = PaymentClass::getIdPaymentBy('id_module', $id_module); $payment = new PaymentClass($id_payment); $payment->id_module = $id_module; $payment->force_display = $force_display; /* update payment image */ if (count($_FILES)) { foreach ($_FILES as $payment_name => $file) { $payment_name = $payment_name; if (!isset($file['tmp_name']) || is_null($file['tmp_name']) || empty($file['tmp_name'])) { $errors[] = $this->l('Cannot add file because it did not sent'); } if (!ImageManager::isRealImage($file['tmp_name'], $file['type']) && $file['type'] != 'image/png' && $file['type'] != 'image/gif') { $errors[] = $this->l('Image extension not allowed'); } if (empty($errors)) { $path = ''; $path_backup = ''; $extension = Tools::substr($file['type'], 6); if (!empty($payment->name_image) && $payment->name_image != 'no-image.png') { $path = dirname(__FILE__).'/views/img/payments/'.$payment->name_image; $path_backup = $path.'.backup'; if (file_exists($path)) { rename($path, $path_backup); } } $payment->name_image = $payment->name.'.'.$extension; $path = dirname(__FILE__).'/views/img/payments/'.$payment->name_image; if (move_uploaded_file($file['tmp_name'], $path)) { if (!empty($path_backup) && file_exists($path_backup)) { unlink($path_backup); } $payment->save(); } else { if (!empty($path_backup)) { rename($path_backup, Tools::substr($path_backup, 0, Tools::strlen($path_backup) - 7)); } $errors[] = $this->l('Cannot copy the file'); } } } } if (Tools::isSubmit('payment_data')) { //save description $payment_data = Tools::jsonDecode($payment_data); if (is_array($payment_data) && count($payment_data)) { $title = array(); $description = array(); foreach ($payment_data as $data) { $title[$data->id_lang] = $data->title; $description[$data->id_lang] = $data->description; } $payment->title = $title; $payment->description = $description; if (!$payment->save()) { $errors[] = $this->l('An error has ocurred while trying save'); } } } if (!empty($errors)) { return array('message_code' => self::CODE_ERROR, 'message' => implode(', ', $errors)); } else { return array( 'message_code' => self::CODE_SUCCESS, 'name_image' => count($_FILES) ? $payment->name_image : '', 'message' => $this->l('Payment configuration has been updated successfully.'), ); } } /** * List of provider packs * @return type array */ public function getRequiredFieldList() { //get content field list $content = FieldClass::getAllFields(null, null, null, null, null, array(), 'f.id_field'); $actions = array( 'edit' => array( 'action_class' => 'Fields', 'class' => 'has-action nohover', 'icon' => 'edit', 'title' => $this->l('Edit'), 'tooltip' => $this->l('Edit'), ), 'remove' => array( 'action_class' => 'Fields', 'class' => 'has-action nohover', 'icon' => 'times', 'title' => $this->l('Remove'), 'tooltip' => $this->l('Remove'), 'condition' => array( 'field' => 'is_custom', 'comparator' => '1', ), ), ); $headers = array( 'name' => $this->l('Name'), 'object' => $this->l('Object'), 'description' => $this->l('Description'), 'default_value' => $this->l('Default value'), 'required' => $this->l('Required'), 'active' => $this->l('Active'), 'actions' => $this->l('Actions'), ); $truncate = array( 'description' => 60, ); //use array with action_class (optional for var) and action (action name) for custom actions. $status = array( 'required' => array( 'action_class' => 'Fields', 'action' => 'toggleRequired', 'class' => 'has-action', ), 'active' => array( 'action_class' => 'Fields', 'action' => 'toggleActive', 'class' => 'has-action', ), ); $color = array( 'by' => 'object', 'colors' => array( 'customer' => 'primary', 'delivery' => 'success', 'invoice' => 'warning', ), ); return array( 'message_code' => self::CODE_SUCCESS, 'content' => $content, 'table' => 'table-required-fields', 'color' => $color, 'headers' => $headers, 'actions' => $actions, 'truncate' => $truncate, 'status' => $status, 'prefix_row' => 'field', ); } public function hookDisplayAdminHomeQuickLinks() { $tk = Tools::getAdminTokenLite('AdminModules'); echo '