* @copyright 2007-2025 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) { exit; } if (!defined('_MYSQL_ENGINE_')) { define('_MYSQL_ENGINE_', 'MyISAM'); } include_once _PS_MODULE_DIR_ . 'privateshoplite/classes/PrivateAcces.php'; include_once _PS_MODULE_DIR_ . 'privateshoplite/lib/simple_html_dom.php'; class PrivateShopLite extends Module { public $translations = []; public static $currentFormTab; protected $option_fields = []; protected $id_shop; protected $id_shop_group; protected $html; protected $config_form = false; public function __construct() { $this->name = 'privateshoplite'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'FMM Modules'; $this->need_instance = 0; $this->module_key = '84cf1d8d8e76ec7266a7cabd4e8d3ec2'; /* * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6) */ $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Private Shop Lite'); $this->description = $this->l('This module allows you to restrict your online store to be accessible only by registered customers.'); $this->translations = $this->getPrivateShopTranslations(); $this->ps_versions_compliancy = ['min' => '1.7', 'max' => _PS_VERSION_]; $this->setShopIdx(); } public function install() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } include dirname(__FILE__) . '/sql/install.php'; if (parent::install() && $this->installConfiguration() && $this->registerHook([ 'displayheader', 'ModuleRoutes', 'backOfficeHeader', 'actionCustomerAccountAdd', 'displayBackOfficeHeader', ]) ) { mkdir(_PS_UPLOAD_DIR_ . $this->name, 0777, true); return true; } return false; } public function uninstall() { include dirname(__FILE__) . '/sql/uninstall.php'; if (parent::uninstall() && $this->uninstallConfiguration()) { if (file_exists(_PS_UPLOAD_DIR_ . $this->name)) { rename(_PS_UPLOAD_DIR_ . $this->name, _PS_UPLOAD_DIR_ . $this->name . '_' . time()); } return true; } return false; } public function getContent() { $this->postProcess(); $this->html = $this->display(__FILE__, 'views/templates/hook/info.tpl'); return $this->html . $this->displayForm(); } public function getAvailableControllers($by_page_id = false) { $pages = []; $files = Meta::getPages(false); if ($files) { foreach ($files as $file) { $type = (preg_match('#^module-#', $file)) ? 'module' : false; if ($type) { $module_pages = explode('-', $file); if ($module_pages) { $module_name = isset($module_pages[1]) && $module_pages[1] ? $module_pages[1] : false; if ($module_name && Validate::isModuleName($module_name) && $module_name != $this->name && Module::isInstalled($module_name)) { if ($by_page_id) { $pages[$file] = $module_pages[2]; } else { $pages[$module_name][$file] = $module_pages[2]; } } } } } } return $pages; } public function ajaxProcessDeleteImage() { $key = Tools::getValue('key'); $filename = Configuration::get($key); $response = ['success' => false, 'message' => '']; $filePath = _PS_MODULE_DIR_ . 'privateshoplite/views/img/private/tmp/' . $filename; if (file_exists($filePath)) { if (unlink($filePath)) { if ($key == 'PL_BACKGROUND_VIDEO_IMG') { Configuration::deleteByName('PL_BACKGROUND_VIDEO_IMG'); } elseif ($key == 'PL_PRIVATE_CUSTOM_LOGO_IMG') { Configuration::deleteByName('PL_PRIVATE_CUSTOM_LOGO_IMG'); } } $response = ['success' => true, 'message' => 'File sucessfully deleted']; } else { $response = ['success' => false, 'message' => 'File could not be deleted or does not exist.']; } exit(json_encode($response)); } private function getBooleanEquivalentVal($id_field) { return [ [ 'id_extra_field' => $id_field, 'field_value_id' => 1, 'field_value' => $this->l('Yes'), ], [ 'id_extra_field' => $id_field, 'field_value_id' => 0, 'field_value' => $this->l('No'), ], ]; } private function postProcess() { if (Tools::isSubmit('saveConfiguration')) { $languages = Language::getLanguages(false); $values = []; foreach ($languages as $lang) { $values['LOGIN_TITLE'][$lang['id_lang']] = Tools::getValue('LOGIN_TITLE_' . $lang['id_lang']); $values['SIGNUP_TITLE'][$lang['id_lang']] = Tools::getValue('SIGNUP_TITLE_' . $lang['id_lang']); $values['PRIVATE_RESTRICT_MESSAGE'][$lang['id_lang']] = Tools::getValue('restrict_message_' . $lang['id_lang'], true); $values['PRIVATE_CUSTOMER_GROUP_MSG'][$lang['id_lang']] = Tools::getValue('PRIVATE_CUSTOMER_GROUP_MSG_' . $lang['id_lang']); } $form_position = (string) Tools::getValue('FORM_POSITION'); $private_signup = (int) Tools::getValue('PRIVATE_SIGNUP'); $background_type = (string) Tools::getValue('BACKGROUND_TYPE'); $background_color = (string) Tools::getValue('BACKGROUND_COLOR'); $bg_image = (string) Tools::getValue('bg_image_selected'); $bg_video_img = (string) Tools::getValue('bg_video_img'); $custom_logo_img = (string) Tools::getValue('custom_logo_img'); $privatize_shop = (string) Tools::getValue('PL_PRIVATIZE_SHOP'); $private_products = (Tools::getValue('private_products')) ? implode(',', Tools::getValue('private_products')) : ''; $category_box = (Tools::getValue('categoryBox')) ? implode(',', Tools::getValue('categoryBox')) : ''; $manufacturers = (Tools::getValue('manufacturers')) ? implode(',', Tools::getValue('manufacturers')) : ''; $suppliers = (Tools::getValue('suppliers')) ? implode(',', Tools::getValue('suppliers')) : ''; $cms_pages = (Tools::getValue('cms_pages')) ? implode(',', Tools::getValue('cms_pages')) : ''; $module_pages = Tools::getIsset('PL_MODULE_PAGES') && Tools::getValue('PL_MODULE_PAGES') ? implode(',', Tools::getValue('PL_MODULE_PAGES')) : ''; if ($_FILES && $_FILES['bg_image']['name']) { $img_real_name = $_FILES['bg_image']['name']; if (!file_exists(_PS_MODULE_DIR_ . $this->name . '/views/img/private')) { mkdir(_PS_MODULE_DIR_ . $this->name . '/views/img/private', 0777, true); } if (move_uploaded_file($_FILES['bg_image']['tmp_name'], _PS_MODULE_DIR_ . $this->name . '/views/img/private/' . (string) $img_real_name)) { $bg_image = $_FILES['bg_image']['name']; } } if ($_FILES && $_FILES['bg_video_img']['name'] && $background_type == 'background-video') { $img_real_name = $_FILES['bg_video_img']['name']; if (!file_exists(_PS_MODULE_DIR_ . $this->name . '/views/img/private/tmp')) { mkdir(_PS_MODULE_DIR_ . $this->name . '/views/img/private/tmp', 0777, true); } if (move_uploaded_file($_FILES['bg_video_img']['tmp_name'], _PS_MODULE_DIR_ . $this->name . '/views/img/private/tmp/' . (string) $img_real_name)) { $bg_video_img = $_FILES['bg_video_img']['name']; } } if ($_FILES && $_FILES['custom_logo_img']['name']) { $img_real_name = $_FILES['custom_logo_img']['name']; if (!file_exists(_PS_MODULE_DIR_ . $this->name . '/views/img/private/tmp')) { mkdir(_PS_MODULE_DIR_ . $this->name . '/views/img/private/tmp', 0777, true); } if (move_uploaded_file($_FILES['custom_logo_img']['tmp_name'], _PS_MODULE_DIR_ . $this->name . '/views/img/private/tmp/' . (string) $img_real_name)) { $custom_logo_img = $_FILES['custom_logo_img']['name']; } } Configuration::updateValue('PL_MODULE_PAGES', $module_pages, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PL_PRIVATIZE_SHOP', $privatize_shop, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PL_PRIVATE_SUPPLIERS', $suppliers, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_MANUFACTURERS', $manufacturers, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('LOGIN_TITLE', $values['LOGIN_TITLE'], null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('SIGNUP_TITLE', $values['SIGNUP_TITLE'], null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_RESTRICT_MESSAGE', $values['PRIVATE_RESTRICT_MESSAGE'], true, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_CUSTOMER_GROUP_MSG', $values['PRIVATE_CUSTOMER_GROUP_MSG'], true, $this->id_shop_group, $this->id_shop); Configuration::updateValue('FORM_POSITION', $form_position, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_SIGNUP', $private_signup, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('BACKGROUND_TYPE', $background_type, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('BACKGROUND_COLOR', $background_color, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('bg_image', $bg_image, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('private_products', $private_products, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('categoryBox', $category_box, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('cms_pages', $cms_pages, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_SIGNUP_RESTRICT', (int) Tools::getValue('PRIVATE_SIGNUP_RESTRICT'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_RESTRICT_GOOGLE', (int) Tools::getValue('PRIVATE_RESTRICT_GOOGLE'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_SHOW_STORE_TITLE', (int) Tools::getValue('PRIVATE_SHOW_STORE_TITLE'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_SHOW_HEADER_FOOTER', (int) Tools::getValue('PRIVATE_SHOW_HEADER_FOOTER'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_FORM_THEME', Tools::getValue('PRIVATE_FORM_THEME'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_ENABLED_DISABLED', Tools::getValue('PRIVATE_ENABLED_DISABLED'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('BG_OPACITY', Tools::getValue('BG_OPACITY'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_BDAY', Tools::getValue('PRIVATE_BDAY'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_GENDER_OPT', Tools::getValue('PRIVATE_GENDER_OPT'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_NLETTER_OPT', Tools::getValue('PRIVATE_NLETTER_OPT'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_OFFERS_OPT', Tools::getValue('PRIVATE_OFFERS_OPT'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_CUSTOM_LOGO', Tools::getValue('PRIVATE_CUSTOM_LOGO'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('BACKGROUND_VIDEO', Tools::getValue('BACKGROUND_VIDEO'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_CUSTOMER_GROUP_STATE', (int) Tools::getValue('PRIVATE_CUSTOMER_GROUP_STATE'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRODUCT_SELECTION_ENABLED_DISABLED', (int) Tools::getValue('PRODUCT_SELECTION_ENABLED_DISABLED'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('CATEGORY_SELECTION_ENABLED_DISABLED', (int) Tools::getValue('CATEGORY_SELECTION_ENABLED_DISABLED'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('SUPPLIER_SELECTION_ENABLED_DISABLED', (int) Tools::getValue('SUPPLIER_SELECTION_ENABLED_DISABLED'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('MANUFACTURER_SELECTION_ENABLED_DISABLED', (int) Tools::getValue('MANUFACTURER_SELECTION_ENABLED_DISABLED'), null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('CMS_SELECTION_ENABLED_DISABLED', (int) Tools::getValue('CMS_SELECTION_ENABLED_DISABLED'), null, $this->id_shop_group, $this->id_shop); if ($_FILES && $_FILES['bg_video_img']['name'] && $background_type == 'background-video') { Configuration::updateValue('PL_BACKGROUND_VIDEO_IMG', $bg_video_img, null, $this->id_shop_group, $this->id_shop); } if ($_FILES && $_FILES['custom_logo_img']['name']) { Configuration::updateValue('PL_PRIVATE_CUSTOM_LOGO_IMG', $custom_logo_img, null, $this->id_shop_group, $this->id_shop); } $groups = Tools::getValue('groups'); $groups = is_array($groups) ? implode(',', $groups) : ''; Configuration::updateValue('PRIVATE_CUSTOMERS_GROUPS', $groups, null, $this->id_shop_group, $this->id_shop); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&conf=4&token=' . Tools::getAdminTokenLite('AdminModules')); } elseif (Tools::isSubmit('activatecustomer')) { $id_customer = (int) Tools::getValue('id_customer'); if ($id_customer > 0) { $customer = new Customer($id_customer); if ((int) $customer->active <= 0) { $customer->active = 1; $customer->update(); $this->sendMailCustomerAccount($customer); } } } elseif (Tools::isSubmit('search')) { $n = ((int) Tools::getValue('n') > 10) ? (int) Tools::getValue('n') : 10; $sort = (int) Tools::getValue('filter_select_pos'); $state = (int) Tools::getValue('filter_select_state'); $name = Tools::getValue('search_by_name'); Configuration::updateValue('PRIVATESHOPLITE_FILTER_n', $n, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATESHOPLITE_FILTER_pos', $sort, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATESHOPLITE_FILTER_state', $state, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATESHOPLITE_FILTER_name', $name, null, $this->id_shop_group, $this->id_shop); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&conf=4&tab_module=customers&token=' . Tools::getAdminTokenLite('AdminModules')); } elseif (Tools::isSubmit('searchReset')) { Configuration::updateValue('PRIVATESHOPLITE_FILTER_n', 10, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATESHOPLITE_FILTER_pos', 0, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATESHOPLITE_FILTER_state', 0, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATESHOPLITE_FILTER_name', '', null, $this->id_shop_group, $this->id_shop); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&conf=4&tab_module=customers&token=' . Tools::getAdminTokenLite('AdminModules')); } } public function installConfiguration() { Configuration::updateValue('bg_image', '', null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('cms_pages', '', null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PS_JS_DEFER', 0, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('categoryBox', '', null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PL_MODULE_PAGES', '', null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_SIGNUP', 1, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('private_products', '', null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('FORM_POSITION', 'center', null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_ENABLED_DISABLED', 0, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('BACKGROUND_COLOR', '#0085a9', null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_SHOW_STORE_TITLE', 1, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PL_PRIVATIZE_SHOP', 'whole-shop', null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_SHOW_HEADER_FOOTER', 0, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_CUSTOMERS_GROUPS', '3', null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('PRIVATE_CUSTOMER_GROUP_STATE', 0, null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('BACKGROUND_TYPE', 'background-color', null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('LOGIN_TITLE', [$this->context->language->id => $this->l('Private Login')], null, $this->id_shop_group, $this->id_shop); Configuration::updateValue('SIGNUP_TITLE', [$this->context->language->id => $this->l('Private Signup')], null, $this->id_shop_group, $this->id_shop); return true; } public function uninstallConfiguration() { Configuration::deleteByName('cms_pages'); Configuration::deleteByName('bg_image'); Configuration::deleteByName('categoryBox'); Configuration::deleteByName('PS_JS_DEFER'); Configuration::deleteByName('PL_MODULE_PAGES'); Configuration::deleteByName('LOGIN_TITLE'); Configuration::deleteByName('SIGNUP_TITLE'); Configuration::deleteByName('FORM_POSITION'); Configuration::deleteByName('PL_PRIVATIZE_SHOP'); Configuration::deleteByName('PRIVATE_SIGNUP'); Configuration::deleteByName('BACKGROUND_TYPE'); Configuration::deleteByName('BACKGROUND_COLOR'); Configuration::deleteByName('private_products'); Configuration::deleteByName('PRIVATE_ENABLED_DISABLED'); Configuration::deleteByName('PRIVATE_FORM_THEME'); Configuration::deleteByName('PRIVATE_SHOW_STORE_TITLE'); Configuration::deleteByName('PRIVATE_CUSTOMERS_GROUPS'); Configuration::deleteByName('PRIVATE_SHOW_HEADER_FOOTER'); Configuration::deleteByName('PRIVATE_CUSTOMER_GROUP_STATE'); Configuration::deleteByName('MANUFACTURER_SELECTION_ENABLED_DISABLED'); Configuration::deleteByName('CMS_SELECTION_ENABLED_DISABLED'); Configuration::deleteByName('SUPPLIER_SELECTION_ENABLED_DISABLED'); Configuration::deleteByName('PL_PRIVATE_SUPPLIERS'); Configuration::deleteByName('PRIVATE_MANUFACTURERS'); return true; } public function getConfigurationValues() { $languages = Language::getLanguages(false); $fields = []; foreach ($languages as $lang) { $fields['login_title'][$lang['id_lang']] = Tools::getValue('LOGIN_TITLE_' . $lang['id_lang'], Configuration::get('LOGIN_TITLE', $lang['id_lang'])); $fields['signup_title'][$lang['id_lang']] = Tools::getValue('SIGNUP_TITLE_' . $lang['id_lang'], Configuration::get('SIGNUP_TITLE', $lang['id_lang'])); $fields['restrict_message'][$lang['id_lang']] = Tools::getValue('restrict_message_' . $lang['id_lang'], Configuration::get('PRIVATE_RESTRICT_MESSAGE', $lang['id_lang'])); $fields['cg_mesg'][$lang['id_lang']] = Tools::getValue('PRIVATE_CUSTOMER_GROUP_MSG_' . $lang['id_lang'], Configuration::get('PRIVATE_CUSTOMER_GROUP_MSG', $lang['id_lang'])); } $PRIVATE_ENABLED_DISABLED = Configuration::get('PRIVATE_ENABLED_DISABLED', false, $this->id_shop_group, $this->id_shop); $theme = (empty(Configuration::get('PRIVATE_FORM_THEME', false, $this->id_shop_group, $this->id_shop))) ? 'mod' : Configuration::get('PRIVATE_FORM_THEME', false, $this->id_shop_group, $this->id_shop); $conf_values = [ 'priv_form_theme' => $theme, 'cg_mesg' => $fields['cg_mesg'], 'login_title' => $fields['login_title'], 'signup_title' => $fields['signup_title'], 'restrict_message' => $fields['restrict_message'], 'pages' => Configuration::get('cms_pages', false, $this->id_shop_group, $this->id_shop), 'bg_img' => Configuration::get('bg_image', false, $this->id_shop_group, $this->id_shop), 'bday' => Configuration::get('PRIVATE_BDAY', false, $this->id_shop_group, $this->id_shop), 'category' => Configuration::get('categoryBox', false, $this->id_shop_group, $this->id_shop), 'bg_opacity' => Configuration::get('BG_OPACITY', false, $this->id_shop_group, $this->id_shop), 'position' => Configuration::get('FORM_POSITION', false, $this->id_shop_group, $this->id_shop), 'bg_type' => Configuration::get('BACKGROUND_TYPE', false, $this->id_shop_group, $this->id_shop), 'bg_color' => Configuration::get('BACKGROUND_COLOR', false, $this->id_shop_group, $this->id_shop), 'bg_video' => Configuration::get('BACKGROUND_VIDEO', false, $this->id_shop_group, $this->id_shop), 'products' => Configuration::get('private_products', false, $this->id_shop_group, $this->id_shop), 'suppliers' => Configuration::get('PL_PRIVATE_SUPPLIERS', false, $this->id_shop_group, $this->id_shop), 'manufacturers' => Configuration::get('PRIVATE_MANUFACTURERS', false, $this->id_shop_group, $this->id_shop), 'active_signup' => Configuration::get('PRIVATE_SIGNUP', false, $this->id_shop_group, $this->id_shop), 'offers_opt' => Configuration::get('PRIVATE_OFFERS_OPT', false, $this->id_shop_group, $this->id_shop), 'gender_opt' => Configuration::get('PRIVATE_GENDER_OPT', false, $this->id_shop_group, $this->id_shop), 'PL_PRIVATIZE_SHOP' => Configuration::get('PL_PRIVATIZE_SHOP', false, $this->id_shop_group, $this->id_shop), 'groups' => Configuration::get('PRIVATE_CUSTOMERS_GROUPS', false, $this->id_shop_group, $this->id_shop), 'custom_logo' => Configuration::get('PRIVATE_CUSTOM_LOGO', false, $this->id_shop_group, $this->id_shop), 'nletter_opt' => Configuration::get('PRIVATE_NLETTER_OPT', false, $this->id_shop_group, $this->id_shop), 'bg_video_img' => Configuration::get('PL_BACKGROUND_VIDEO_IMG', false, $this->id_shop_group, $this->id_shop), 'custom_logo_img' => Configuration::get('PL_PRIVATE_CUSTOM_LOGO_IMG', false, $this->id_shop_group, $this->id_shop), 'active_google' => (int) Configuration::get('PRIVATE_RESTRICT_GOOGLE', false, $this->id_shop_group, $this->id_shop), 'show_store_title' => (int) Configuration::get('PRIVATE_SHOW_STORE_TITLE', false, $this->id_shop_group, $this->id_shop), 'cgroup_active' => (int) Configuration::get('PRIVATE_CUSTOMER_GROUP_STATE', false, $this->id_shop_group, $this->id_shop), 'show_header_footer' => (int) Configuration::get('PRIVATE_SHOW_HEADER_FOOTER', false, $this->id_shop_group, $this->id_shop), 'active_signup_restrict' => (int) Configuration::get('PRIVATE_SIGNUP_RESTRICT', false, $this->id_shop_group, $this->id_shop), 'product_selection_enabled_disabled' => (int) Configuration::get('PRODUCT_SELECTION_ENABLED_DISABLED', false, $this->id_shop_group, $this->id_shop), 'category_selection_enabled_disabled' => (int) Configuration::get('CATEGORY_SELECTION_ENABLED_DISABLED', false, $this->id_shop_group, $this->id_shop), 'supplier_selection_enabled_disabled' => (int) Configuration::get('SUPPLIER_SELECTION_ENABLED_DISABLED', false, $this->id_shop_group, $this->id_shop), 'manufacturer_selection_enabled_disabled' => (int) Configuration::get('MANUFACTURER_SELECTION_ENABLED_DISABLED', false, $this->id_shop_group, $this->id_shop), 'cms_selection_enabled_disabled' => (int) Configuration::get('CMS_SELECTION_ENABLED_DISABLED', false, $this->id_shop_group, $this->id_shop), 'PRIVATE_ENABLED_DISABLED' => $PRIVATE_ENABLED_DISABLED, ]; return $conf_values; } public function displayForm() { $field_values = $this->getConfigurationValues(); $module_pages = $this->getAvailableControllers(); $token = Tools::getAdminTokenLite('AdminModules'); $module_link = $this->context->link->getAdminLink('AdminModules', false); $url = $module_link . '&configure=privateshoplite&token=' . $token . '&tab_module=administration&module_name=privateshoplite'; $category_tree = ''; $root = Category::getRootCategory(); $customers = PrivateAcces::getAllCustomers(); $customer_groups = Group::getGroups($this->context->language->id); foreach ($customer_groups as $key => $group) { if ($group['id_group'] <= 2) { unset($customer_groups[$key]); } } $languages = Language::getLanguages(false); if (Tools::version_compare(_PS_VERSION_, '1.6.0.0', '>=')) { $tree = new HelperTreeCategories('associated-categories-tree', $this->l('Associated categories')); $tree->setRootCategory($root->id); $tree->setUseCheckBox(true); $tree->setUseSearch(true); if (isset($field_values) && !empty($field_values['category'])) { $selected_categories = explode(',', $field_values['category']); $tree->setSelectedCategories($selected_categories); } $category_tree = $tree->render(); } else { $tree = new Helper(); $category_tree = $tree->renderCategoryTree( null, isset($field_values) && !empty($field_values['category']) ? explode(',', $field_values['category']) : [], 'categoryBox[]', true, true, [], false, false ); } $products = []; if (isset($field_values) && !empty($field_values['products'])) { $products = explode(',', $field_values['products']); } $pages = []; if (isset($field_values) && !empty($field_values['pages'])) { $pages = explode(',', $field_values['pages']); } $selected_groups = []; if (isset($field_values) && !empty($field_values['groups'])) { $selected_groups = explode(',', $field_values['groups']); } $selected_suppliers = []; if (isset($field_values) && !empty($field_values['suppliers'])) { $selected_suppliers = explode(',', $field_values['suppliers']); } $selected_manufacturers = []; if (isset($field_values) && !empty($field_values['manufacturers'])) { $selected_manufacturers = explode(',', $field_values['manufacturers']); } $module_controllers = Configuration::get('PL_MODULE_PAGES', false, $this->id_shop_group, $this->id_shop) && !empty(Configuration::get('PL_MODULE_PAGES', false, $this->id_shop_group, $this->id_shop)) ? explode(',', Configuration::get('PL_MODULE_PAGES', false, $this->id_shop_group, $this->id_shop)) : []; $iso_tiny_mce = $this->context->language->iso_code; $iso_tiny_mce = (file_exists(_PS_JS_DIR_ . 'tiny_mce/langs/' . $iso_tiny_mce . '.js') ? $iso_tiny_mce : 'en'); $this->context->controller->addJS([ _PS_JS_DIR_ . 'tiny_mce/tiny_mce.js', _PS_JS_DIR_ . 'admin/tinymce.inc.js', ]); $activate_customer = (int) Tools::getValue('activatecustomer'); $tab_select = (empty(Tools::getValue('tab_module'))) ? 'administration' : Tools::getValue('tab_module'); $search = [ 'n' => (int) Configuration::get('PRIVATESHOPLITE_FILTER_n', false, $this->id_shop_group, $this->id_shop), 'pos' => (int) Configuration::get('PRIVATESHOPLITE_FILTER_pos', false, $this->id_shop_group, $this->id_shop), 'state' => (int) Configuration::get('PRIVATESHOPLITE_FILTER_state', false, $this->id_shop_group, $this->id_shop), 'name' => Configuration::get('PRIVATESHOPLITE_FILTER_name', false, $this->id_shop_group, $this->id_shop), ]; $test = new PrivateShopLite(); Media::addJsDef(['currentIndex' => AdminController::$currentIndex . '&configure=' . $this->name]); $this->context->smarty->assign([ 'version' => _PS_VERSION_, 'URL' => $url, 'pages' => $pages, 'current_tab' => Tools::getValue('custom_tab'), 'module' => new PrivateShopLite(), 'categories' => $category_tree, 'link' => $this->context->link, 'admin_dir' => _PS_ADMIN_DIR_, 'customers' => $customers, 'products' => $products, 'languages' => $languages, 'tab_select' => $tab_select, 'search_result' => $search, 'groups' => $customer_groups, 'iso_tiny_mce' => $iso_tiny_mce, 'field_values' => $field_values, 'suppliers' => Supplier::getSuppliers(false, $this->context->language->id, false), 'manufacturers' => Manufacturer::getManufacturers(false, $this->context->language->id, false), 'module_pages' => $module_pages, 'images' => $this->readImageDir(), 'cur_ip' => Tools::getRemoteAddr(), 'selected_suppliers' => $selected_suppliers, 'selected_manufacturers' => $selected_manufacturers, 'selected_groups' => $selected_groups, 'activate_customer' => $activate_customer, 'currentFormTab' => static::$currentFormTab, 'module_controllers' => $module_controllers, 'ad' => __PS_BASE_URI__ . basename(_PS_ADMIN_DIR_), 'active_lang' => (int) $this->context->language->id, 'ctoken' => Tools::getAdminTokenLite('AdminCustomers'), 'cms_pages' => CMS::getLinks((int) $this->context->language->id), 'cIndex' => $this->context->link->getAdminLink('AdminCustomers'), 'delete_customers' => AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . $token, 'mIndex' => $this->context->link->getAdminLink('AdminPrivatePages'), 'mtoken' => Tools::getAdminTokenLite('AdminPrivatePages'), 'search_link' => $this->context->link->getAdminLink('AdminPrivatePages') . '&ajax=1&action=getProducts', 'activate_index' => AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . $token . '&tab_module=customers&activatecustomer=1&', ]); return $this->display(__FILE__, 'views/templates/admin/form.tpl'); } protected function readImageDir() { $dir = _PS_MODULE_DIR_ . 'privateshoplite/views/img/private'; if (is_dir($dir)) { if ($dh = opendir($dir)) { $images = []; while (($file = readdir($dh)) !== false) { if (!is_dir($dir . $file) && !in_array($file, ['.', '..', 'tmp', 'index.php'])) { $images[] = $file; } } closedir($dh); return $images; } } } public function hookDisplayHeader() { $this->checkPrivateShop(); $this->context->controller->addJS($this->_path . 'views/js/customer_message.js'); Media::addJsDef([ 'message_url' => $this->context->link->getModuleLink($this->name, 'thejax', ['action' => 'sendMessage'], true), ]); // return ''; } public function hookDisplayBackOfficeHeader() { if (true === Tools::version_compare(_PS_VERSION_, '1.7', '>=')) { if (Dispatcher::getInstance()->getController() == 'AdminCustomers' && Tools::getValue('action') == 'updatecustomer') { $this->context->controller->addJS(_PS_JS_DIR_ . 'jquery/jquery-' . _PS_JQUERY_VERSION_ . '.min.js'); } } else { $this->context->controller->addJquery(); } Media::addJsDef([ 'delete_url' => $this->context->link->getAdminLink('AdminModules') . '&configure=' . $this->name . '&action=deleteImage&ajax=1', ]); $this->context->controller->addCSS($this->_path . 'views/css/admin.css'); $this->context->controller->addJS($this->_path . 'views/js/back.js'); // $this->getCustomerDisplayFields(); } public function hookModuleRoutes() { return [ 'module-privateshoplite-restricted' => [ 'controller' => 'restricted', 'rule' => 'restricted', 'keywords' => [], 'params' => [ 'fc' => 'module', 'module' => $this->name, ], ], 'module-privateshoplite-thejax' => [ 'controller' => 'thejax', 'rule' => 'private', 'keywords' => [], 'params' => [ 'fc' => 'module', 'module' => $this->name, ], ], 'module-privateshoplite-private' => [ 'controller' => 'private', 'rule' => 'private-access{/:type}', 'keywords' => [ 'type' => ['regexp' => '[_a-zA-Z]+', 'param' => 'type'], ], 'params' => [ 'fc' => 'module', 'module' => $this->name, ], ], ]; } protected function disableNewCustomer($customer) { if (true === (bool) Configuration::get('PRIVATE_SIGNUP_RESTRICT', false, $this->context->shop->id_shop_group, $this->context->shop->id)) { $customer->active = 0; $customer->update(); $this->sendMailsUserPending($customer); $this->context->controller->errors[] = $this->translations['pending_validation']; $this->context->cookie->logout(); } } private function sendMailsUserPending($customer) { $module = new PrivateShopLite(); $id_lang = (int) $this->context->language->id; $employee = new Employee(1); $admin_email = Configuration::get('PS_SHOP_EMAIL'); $admin_email = (empty($admin_email)) ? $employee->email : $admin_email; $module->l('Account Pending Validation'); $template_pending_customer = 'messageforpendingcustomer'; $template_pending_customer_bo = 'messageforpendingcustomeradmin'; $heading_pending_customer = Translate::getModuleTranslation('privateshoplite', 'Account Pending Validation', 'privateshoplite'); Mail::Send( (int) $id_lang, $template_pending_customer, $heading_pending_customer, ['{name}' => $customer->firstname . ' ' . $customer->lastname], $customer->email, null, null, null, null, null, _PS_MODULE_DIR_ . 'privateshoplite/mails/', false, (int) $this->context->shop->id ); Mail::Send( (int) $id_lang, $template_pending_customer_bo, $heading_pending_customer, ['{name}' => $customer->firstname . ' ' . $customer->lastname, '{email}' => $customer->email, '{id}' => $customer->id], $admin_email, null, null, null, null, null, _PS_MODULE_DIR_ . 'privateshoplite/mails/', false, (int) $this->context->shop->id ); } private function sendMailCustomerAccount($customer) { $module = new PrivateShopLite(); $id_lang = (int) $this->context->language->id; $module->l('Account Approved'); $template_pending_customer = 'messageforaccountactive'; $heading_pending_customer = Translate::getModuleTranslation('privateshoplite', 'Account Approved', 'privateshoplite'); $link_account = $this->context->link->getPageLink('my-account', true); Mail::Send( (int) $id_lang, $template_pending_customer, $heading_pending_customer, ['{name}' => $customer->firstname . ' ' . $customer->lastname, '{email}' => $customer->email, '{account}' => $link_account], $customer->email, null, null, null, null, null, _PS_MODULE_DIR_ . 'privateshoplite/mails/', false, (int) $this->context->shop->id ); } public function hookActionCustomerAccountAdd($params) { $this->disableNewCustomer( $params['newCustomer'] ); } protected function checkPrivateShop() { $logged = false; if (isset($this->context->customer) && $this->context->customer->isLogged()) { $logged = true; $this->context->cookie->__set('access_granted', 1); } else { $logged = false; $this->context->cookie->__unset('access_granted'); } $google_bot = (bool) Configuration::get('PRIVATE_RESTRICT_GOOGLE', false, $this->context->shop->id_shop_group, $this->context->shop->id); if ($google_bot && strstr(Tools::strtolower($_SERVER['HTTP_USER_AGENT']), 'googlebot')) { return; } $controller = Dispatcher::getInstance()->getController(); $allowedControllers = Configuration::get('PL_MODULE_PAGES', false, $this->context->shop->id_shop_group, $this->context->shop->id) && !empty(Configuration::get('PL_MODULE_PAGES', false, $this->context->shop->id_shop_group, $this->context->shop->id)) ? explode(',', Configuration::get('PL_MODULE_PAGES', false, $this->context->shop->id_shop_group, $this->context->shop->id)) : []; $modulePages = $this->getAvailableControllers(true); $filteredControllers = ($allowedControllers && isset($modulePages) && $modulePages) ? array_intersect_key($modulePages, array_flip($allowedControllers)) : []; $filteredControllers = $filteredControllers ? array_values($filteredControllers) : []; $currentUrl = Tools::getHttpHost(true) . $_SERVER['REQUEST_URI']; $whiteListControllers = array_merge(['private', 'thejax', 'restricted', 'password', 'search'], $filteredControllers); if (in_array($controller, $whiteListControllers)) { return; } $ipList = []; $privateGroups = []; $privateType = Configuration::get('PL_PRIVATIZE_SHOP', false, $this->context->shop->id_shop_group, $this->context->shop->id); $groupMgt = (bool) Configuration::get('PRIVATE_CUSTOMER_GROUP_STATE', false, $this->context->shop->id_shop_group, $this->context->shop->id); $id_customer = isset($this->context->customer) ? $this->context->customer->id : 0; $id_group = ($id_customer) ? (int) Customer::getDefaultGroupId((int) $id_customer) : (int) Group::getCurrent()->id; $params = [ 'back' => Tools::htmlentitiesDecodeUTF8(urlencode($currentUrl)), ]; if (Configuration::get('PRIVATE_CUSTOMERS_GROUPS', false, $this->context->shop->id_shop_group, $this->context->shop->id)) { $privateGroups = explode(',', Configuration::get('PRIVATE_CUSTOMERS_GROUPS', false, $this->context->shop->id_shop_group, $this->context->shop->id)); } $PRIVATE_ENABLED_DISABLED = Configuration::get('PRIVATE_ENABLED_DISABLED'); if ($PRIVATE_ENABLED_DISABLED) { switch ($privateType) { case 'whole-shop': if (!$id_customer || !$logged) { $params['type'] = 'private_login'; Tools::redirect($this->context->link->getModuleLink( $this->name, 'private', $params, true, $this->context->language->id, $this->context->shop->id )); } break; case 'selected-parts': if (!$id_customer || !$logged) { $this->runPrivateShop(); } else { if (true === $groupMgt && $privateGroups && !in_array($id_group, $privateGroups)) { $this->runPrivateShop('deadend'); } } break; } } } protected function runPrivateShop($type = 'private_login') { $privateCms = []; $privateProduct = []; $privateCategory = []; $privateSuppliers = []; $privateManufacturers = []; $product = []; $currentUrl = Tools::getHttpHost(true) . $_SERVER['REQUEST_URI']; $controller = Dispatcher::getInstance()->getController(); if (Configuration::get('categoryBox', false, $this->context->shop->id_shop_group, $this->context->shop->id) && Configuration::get('CATEGORY_SELECTION_ENABLED_DISABLED') == 1) { $privateCategory = explode(',', Configuration::get('categoryBox', false, $this->context->shop->id_shop_group, $this->context->shop->id)); } if (Configuration::get('private_products', false, $this->context->shop->id_shop_group, $this->context->shop->id) && Configuration::get('PRODUCT_SELECTION_ENABLED_DISABLED') == 1) { $privateProduct = explode(',', Configuration::get('private_products', false, $this->context->shop->id_shop_group, $this->context->shop->id)); } if (Configuration::get('cms_pages', false, $this->context->shop->id_shop_group, $this->context->shop->id) && Configuration::get('CMS_SELECTION_ENABLED_DISABLED') == 1) { $privateCms = explode(',', Configuration::get('cms_pages', false, $this->context->shop->id_shop_group, $this->context->shop->id)); } if (Configuration::get('PL_PRIVATE_SUPPLIERS', false, $this->context->shop->id_shop_group, $this->context->shop->id) && Configuration::get('SUPPLIER_SELECTION_ENABLED_DISABLED') == 1) { $privateSuppliers = explode(',', Configuration::get('PL_PRIVATE_SUPPLIERS', false, $this->context->shop->id_shop_group, $this->context->shop->id)); } if (Configuration::get('PRIVATE_MANUFACTURERS', false, $this->context->shop->id_shop_group, $this->context->shop->id) && Configuration::get('MANUFACTURER_SELECTION_ENABLED_DISABLED') == 1) { $privateManufacturers = explode(',', Configuration::get('PRIVATE_MANUFACTURERS', false, $this->context->shop->id_shop_group, $this->context->shop->id)); } $params = [ 'type' => $type, ]; if ($type != 'deadend') { $params['back'] = Tools::htmlentitiesDecodeUTF8(urlencode($currentUrl)); } $identifier = false; $privateParent = false; $identifierResource = []; if (in_array($controller, ['product', 'category', 'cms', 'index'])) { $identifier = Tools::getValue('id_' . $controller); if ('index' === $controller) { $identifier = Configuration::get('PS_HOME_CATEGORY'); $identifierResource = $privateCategory; } else { $identifierResource = ${'private' . Tools::ucfirst($controller)}; } if ('category' === $controller) { $currentCategory = new Category((int) $identifier, $this->context->language->id, $this->context->shop->id); $parents = $currentCategory->getParentsCategories($this->context->language->id); foreach ($parents as $parent) { if ($privateCategory && in_array($parent['id_category'], $privateCategory)) { $privateParent = true; break; } } } if ('product' === $controller) { $product = new Product((int) $identifier, $this->context->language->id, $this->context->shop->id); } if ($privateSuppliers && $product) { $associatedSuppliers = PrivateAcces::getAssociatedSuppliers($product->id); if ($associatedSuppliers && is_array($associatedSuppliers)) { $identifierResource = $privateSuppliers; foreach ($associatedSuppliers as $supplier) { if (in_array($supplier['id_supplier'], $privateSuppliers)) { $identifier = $supplier['id_supplier']; break; } } } } if ($privateManufacturers && $product && isset($product->id_manufacturer) && PrivateAcces::isActiveManufacturer($product->id_manufacturer)) { $id_manufacturer = $product->id_manufacturer; if ($id_manufacturer) { $identifier = $id_manufacturer; $identifierResource = $privateManufacturers; } } } if ($privateParent || ($identifier && isset($identifierResource) && in_array($identifier, $identifierResource))) { Tools::redirect($this->context->link->getModuleLink( $this->name, 'private', $params, true, $this->context->language->id, $this->context->shop->id )); } } public function initPrivate() { $use_ssl = ((isset($this->context->controller->ssl) && $this->context->controller->ssl && Configuration::get('PS_SSL_ENABLED')) || Tools::usingSecureMode()) ? true : false; $protocol_content = ($use_ssl) ? 'https://' : 'http://'; $this->context->smarty->assign(Meta::getMetaTags($this->context->language->id, 'private_login')); $this->assignDate(); $jQueryPath = false; if (Tools::version_compare(_PS_VERSION_, '1.7', '<=') == true) { $jQueryPath = Media::getJqueryPath(_PS_JQUERY_VERSION_); // for compatibility with older versions if (is_array($jQueryPath) && isset($jQueryPath[0])) { $jQueryPath = $jQueryPath[0]; } } $this->context->smarty->assign(['jQuery_path' => $jQueryPath]); $this->context->smarty->assign([ 'modules_dir' => _MODULE_DIR_, 'js_dir' => _THEME_JS_DIR_, 'js_def' => Media::getJsDef(), 'version' => _PS_VERSION_, 'css_dir' => _THEME_CSS_DIR_, 'tpl_dir' => _PS_THEME_DIR_, 'token' => Tools::getToken(), 'static_token' => Tools::getToken(false), 'errors' => $this->context->controller->errors, 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'content_only' => (int) Tools::getValue('content_only'), 'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_, 'is_guest' => (bool) $this->context->customer->isGuest(), 'is_logged' => (bool) $this->context->customer->isLogged(), 'date_format' => $this->context->language->date_format_lite, 'favicon_url' => _PS_IMG_ . Configuration::get('PS_FAVICON'), 'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'), 'request_uri' => Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])), 'countries' => Country::getCountries($this->context->language->id, true), 'logo_url' => $this->context->link->getMediaLink(_PS_IMG_ . Configuration::get('PS_LOGO')), 'language_code' => $this->context->language->language_code ? $this->context->language->language_code : $this->context->language->iso_code, 'base_uri' => $protocol_content . Tools::getHttpHost() . __PS_BASE_URI__ . (!Configuration::get('PS_REWRITING_SETTINGS') ? 'index.php' : ''), ]); $jquery_array = []; if (_PS_VERSION_ >= '8.0') { $folder = _PS_JS_DIR_ . 'jquery/'; $component = '3.4.1'; $file = 'jquery-' . $component . '.min.js'; $jq_path = Media::getJSPath($folder . $file); $jquery_array[] = $jq_path; $this->context->smarty->assign([ 'js_files' => $jquery_array, ]); } else { $this->context->smarty->assign([ 'js_files' => Media::getJqueryPath(), // for compatibility with older versions ]); } } public function assignDate() { $selectedYears = (int) Tools::getValue('years', 0); $years = Tools::dateYears(); $selectedMonths = (int) Tools::getValue('months', 0); $months = Tools::dateMonths(); $selectedDays = (int) Tools::getValue('days', 0); $days = Tools::dateDays(); $this->context->smarty->assign([ 'years' => $years, 'sl_year' => $selectedYears, 'months' => $months, 'sl_month' => $selectedMonths, 'days' => $days, 'sl_day' => $selectedDays, ]); } public function assignCountries() { $id_country = (int) Tools::getCountry(); if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) { $countries = Carrier::getDeliveredCountries($this->context->language->id, true, true); } else { $countries = Country::getCountries($this->context->language->id, true); } $this->context->smarty->assign([ 'countries' => $countries, 'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'), 'sl_country' => (int) $id_country, 'vat_management' => Configuration::get('VATNUMBER_MANAGEMENT'), ]); } public function assignAddressFormat() { $id_country = (int) Tools::getCountry(); $addressItems = []; $addressFormat = AddressFormat::getOrderedAddressFields((int) $id_country, false, true); $requireFormFieldsList = AddressFormat::getFieldsRequired(); foreach ($addressFormat as $addressline) { foreach (explode(' ', $addressline) as $addressItem) { $addressItems[] = trim($addressItem); } } foreach ($requireFormFieldsList as $fieldName) { if (!in_array($fieldName, $addressItems)) { $addressItems[] = trim($fieldName); } } foreach (['inv', 'dlv'] as $addressType) { $this->context->smarty->assign([ $addressType . '_adr_fields' => $addressFormat, $addressType . '_all_fields' => $addressItems, 'required_fields' => $requireFormFieldsList, ]); } } public function getPrivateConfigurationValues() { $bg_video = rtrim(Configuration::get('BACKGROUND_VIDEO', false, $this->context->shop->id_shop_group, $this->context->shop->id), '/'); $bg_video = explode('/', $bg_video); $bg_video = end($bg_video); $bg_opacity = empty(Configuration::get('BG_OPACITY', false, $this->context->shop->id_shop_group, $this->context->shop->id)) ? 1 : Configuration::get('BG_OPACITY', false, $this->context->shop->id_shop_group, $this->context->shop->id); $theme = (empty(Configuration::get('PRIVATE_FORM_THEME', false, $this->context->shop->id_shop_group, $this->context->shop->id))) ? 'mod' : Configuration::get('PRIVATE_FORM_THEME', false, $this->context->shop->id_shop_group, $this->context->shop->id); // $privateshop_enable = Configuration::get('PRIVATE_FORM_THEME', false, $this->context->shop->id_shop_group, $this->context->shop->id); $conf_values = [ 'bg_video' => $bg_video, 'bg_opacity' => $bg_opacity, 'priv_form_theme' => $theme, 'bg_img' => Configuration::get('bg_image', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'pages' => Configuration::get('cms_pages', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'bday' => Configuration::get('PRIVATE_BDAY', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'category' => Configuration::get('categoryBox', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'position' => Configuration::get('FORM_POSITION', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'bg_type' => Configuration::get('BACKGROUND_TYPE', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'bg_color' => Configuration::get('BACKGROUND_COLOR', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'products' => Configuration::get('private_products', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'active_signup' => Configuration::get('PRIVATE_SIGNUP', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'PL_PRIVATIZE_SHOP' => Configuration::get('PL_PRIVATIZE_SHOP', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'gender_opt' => Configuration::get('PRIVATE_GENDER_OPT', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'nletter_opt' => Configuration::get('PRIVATE_NLETTER_OPT', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'offers_opt' => Configuration::get('PRIVATE_OFFERS_OPT', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'custom_logo' => Configuration::get('PRIVATE_CUSTOM_LOGO', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'bg_video_img' => Configuration::get('PL_BACKGROUND_VIDEO_IMG', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'custom_logo_img' => Configuration::get('PL_PRIVATE_CUSTOM_LOGO_IMG', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'show_store_title' => (int) Configuration::get('PRIVATE_SHOW_STORE_TITLE', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'show_header_footer' => (int) Configuration::get('PRIVATE_SHOW_HEADER_FOOTER', false, $this->context->shop->id_shop_group, $this->context->shop->id), 'login_title' => Configuration::get('LOGIN_TITLE', (int) $this->context->language->id, $this->context->shop->id_shop_group, $this->context->shop->id), 'signup_title' => Configuration::get('SIGNUP_TITLE', (int) $this->context->language->id, $this->context->shop->id_shop_group, $this->context->shop->id), 'restrict_message' => Configuration::get('PRIVATE_CUSTOMER_GROUP_MSG', (int) $this->context->language->id, $this->context->shop->id_shop_group, $this->context->shop->id), ]; return $conf_values; } public function getTypes($type) { switch ($type) { case 'product': return $this->l('Product'); case 'category': return $this->l('Category'); case 'cms': return $this->l('CMS'); case 'meta_pages': return $this->l('Meta Pages'); } } public function hasProduct($id_product, $products) { foreach ($products as $product) { if ((int) $product['id_product'] == (int) $id_product) { return true; } } return false; } public function installTab($controllerClassName, $tabName, $icon = null) { $tab = new Tab(); $tab->active = 1; $tab->id_parent = -1; $tab->module = $this->name; $tab->class_name = $controllerClassName; $tab->name = []; if (true === Tools::version_compare(_PS_VERSION_, '1.7', '>=') && !empty($icon)) { $tab->icon = $icon; } foreach (Language::getLanguages(true) as $lang) { $tab->name[$lang['id_lang']] = $tabName; } return (bool) $tab->add(); } public function updateCustomer(Customer $customer) { $this->context->customer = $customer; $this->context->cookie->id_customer = (int) $customer->id; $this->context->cookie->customer_lastname = $customer->lastname; $this->context->cookie->customer_firstname = $customer->firstname; $this->context->cookie->passwd = $customer->passwd; $this->context->cookie->logged = 1; $customer->logged = 1; $this->context->cookie->email = $customer->email; $this->context->cookie->is_guest = $customer->isGuest(); $this->context->cart->secure_key = $customer->secure_key; if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0) && $idCart = (int) Cart::lastNoneOrderedCart($this->context->customer->id)) { $this->context->cart = new Cart($idCart); } else { $idCarrier = (int) $this->context->cart->id_carrier; $this->context->cart->id_carrier = 0; $this->context->cart->setDeliveryOption(null); $this->context->cart->updateAddressId($this->context->cart->id_address_delivery, (int) Address::getFirstCustomerAddressId((int) $customer->id)); $this->context->cart->id_address_delivery = (int) Address::getFirstCustomerAddressId((int) $customer->id); $this->context->cart->id_address_invoice = (int) Address::getFirstCustomerAddressId((int) $customer->id); } $this->context->cart->id_customer = (int) $customer->id; if (isset($idCarrier) && $idCarrier) { $deliveryOption = [$this->context->cart->id_address_delivery => $idCarrier . ',']; $this->context->cart->setDeliveryOption($deliveryOption); } $this->context->cart->save(); $this->context->cookie->id_cart = (int) $this->context->cart->id; $this->context->cookie->write(); $this->context->cart->autosetProductAddress(); } public function setShopIdx() { if ($this->id_shop === null || !Shop::isFeatureActive()) { $this->id_shop = Shop::getContextShopID(); } else { $this->id_shop = Context::getContext()->shop->id; } if ($this->id_shop_group === null || !Shop::isFeatureActive()) { $this->id_shop_group = Shop::getContextShopGroupID(); } else { $this->id_shop_group = Context::getContext()->shop->id_shop_group; } } public function removeCache() { Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); Tools::generateIndex(); if (true === Tools::version_compare(_PS_VERSION_, '1.7', '>=') && is_callable(['Tools', 'clearAllCache'])) { Tools::clearAllCache(); } } protected function getPrivateShopTranslations() { return [ 'welcome' => $this->l('Welcome!'), 'email_required' => $this->l('An email address is required.'), 'passwd_required' => $this->l('Password is required.'), 'invalid_email' => $this->l('Invalid email address.'), 'message_required' => $this->l('Message Required.'), 'invalid_password' => $this->l('Invalid password.'), 'invalid_customer_message' => $this->l('Invalid Message content, only numbers letters and quotes are allowed.'), 'invalid-message-subject' => $this->l('Invalid subject.'), 'required_firstname' => $this->l('First name is required.'), 'invalid_firstname' => $this->l('First name is invalid.'), 'required_lastname' => $this->l('Last name is required.'), 'invalid_lastname' => $this->l('Last name is invalid.'), 'invalid_birthday' => $this->l('Birth date is invalid.'), 'account_deactive' => $this->l('Your account isn\'t available at this time, please contact us'), 'auth_error' => $this->l('Authentication failed.'), 'guest_account_error' => $this->l('You cannot create a guest account.'), 'duplicate_email_error' => $this->l('An account using this email address has already been registered.'), 'phone_error' => $this->l('You must register at least one phone number.'), 'account_creation_error' => $this->l('An error occurred while creating your account.'), 'country_error' => $this->l('Country cannot be loaded with address->id_country'), 'country_deactive' => $this->l('This country is not active.'), 'zipcode_required' => $this->l('A Zip / Postal code is required.'), 'zicode_invalid' => $this->l('The Zip / Postal code is invalid.'), 'invalid_zipcode' => $this->l('The Zip/Postal code you\'ve entered is invalid. It must follow this format: %s'), 'identificaion_invalid' => $this->l('The identification number is incorrect or has already been used.'), 'invalid_country' => $this->l('Country is invalid'), 'state_required' => $this->l('This country requires you to choose a State.'), 'address_error' => $this->l('An error occurred while creating your address.'), 'pending_validation' => $this->l('Please have patience. Your Account is pending for validation.'), 'no_account_registered' => $this->l('There is no account registered for this email address.'), 'cannot_regen_pwd' => $this->l('You cannot regenerate the password for this account.'), 'gen_pwd_after_x' => $this->l('You can regenerate your password only every %d minute(s)'), 'email_sending_error' => $this->l('An error occurred while sending the email.'), 'account_404' => $this->l('Customer account not found'), 'pwd_sending_failed' => $this->l('An error occurred with your account, which prevents us from sending you a new password. Please report this issue using the contact form.'), 'invalid_pwd_data' => $this->l('We cannot regenerate your password with the data you\'ve submitted.'), 'account_exists' => $this->l('An account using this email address has already been registered. Please enter a valid password or request a new one.'), 'invalid' => $this->l('is invalid.'), 'required' => $this->l('is required.'), 'type' => $this->l('invalid file type.'), 'size' => $this->l('size exceeds the limit.'), 'limit' => $this->l('character size exceeds the limit.'), 'upload_error' => $this->l( 'An error occurred while attempting to upload the file.' ), 'update_success' => $this->l('Registration fields updated successfully.'), ]; } public function paginateList($content, $page = 1, $pagination = 10) { if (count($content) > $pagination) { $content = array_slice($content, $pagination * ($page - 1), $pagination); } return $content; } protected function getCustomFieldTypes() { return [ 'text' => $this->l('Text Field'), 'textarea' => $this->l('Text Area'), 'date' => $this->l('Date'), 'boolean' => $this->l('Yes/No'), 'multiselect' => $this->l('Multiple Select'), 'select' => $this->l('Dropdown Select'), 'checkbox' => $this->l('Checkbox(s)'), 'radio' => $this->l('Radio Button(s)'), 'image' => $this->l('Image'), 'attachment' => $this->l('Attachment'), 'message' => $this->l('Message (Display Only)'), ]; } protected function getRequestStack() { if (!defined('PS_MODE_DEV')) { define('PS_MODE_DEV', false); // Default to false or set to true if in development mode } $kernel = null; if (!$kernel) { require_once _PS_ROOT_DIR_ . '/app/AppKernel.php'; $env = (true === PS_MODE_DEV) ? 'dev' : 'prod'; $kernel = new AppKernel($env, false); $kernel->boot(); } return $kernel->getContainer()->get('request_stack')->getCurrentRequest(); } }