Current path: home/webdevt/www/schtroumpf.fr/modules/an_simple_contact/
?? Go up: /home/webdevt/www/schtroumpf.fr/modules
<?php
/**
* 2022 Anvanto
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
*
* @author Anvanto <anvantoco@gmail.com>
* @copyright 2022 Anvanto
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
class an_simple_contact extends Module implements WidgetInterface
{
const PREFIX = 'an_s_b_';
protected $_tabs = array(
array(
'class_name' => 'AdminAnContact',
'parent' => 'AdminParentModulesSf',
'name' => 'Simple Contact Block',
'active' => 0
),
);
public function __construct()
{
$this->name = 'an_simple_contact';
$this->tab = 'others';
$this->version = '1.0.0';
$this->author = 'Anvanto';
$this->need_instance = 0;
$this->bootstrap = true;
$this->module_key = '';
parent::__construct();
$this->displayName = $this->l('Simple Contact Block');
$this->description = $this->l('Simple Contact Block');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall the module?');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
$this->modulePath = _MODULE_DIR_ . 'an_simple_contact/';
}
public function install()
{
$languages = Language::getLanguages();
foreach ($this->_tabs as $tab) {
$_tab = new Tab();
$_tab->active = $tab['active'];
$_tab->class_name = $tab['class_name'];
$_tab->id_parent = Tab::getIdFromClassName($tab['parent']);
if (empty($_tab->id_parent)) {
$_tab->id_parent = 0;
}
$_tab->module = $this->name;
foreach ($languages as $language) {
$_tab->name[$language['id_lang']] = $this->l($tab['name']);
}
$_tab->add();
}
$valueTitle = [];
$valueText = [];
foreach ($languages as $lang) {
$valueTitle[$lang['id_lang']] = 'Phone';
$valueText[$lang['id_lang']] = '8 (800) 2000 3000';
}
Configuration::updateValue(self::PREFIX.'title', $valueTitle);
Configuration::updateValue(self::PREFIX.'text', $valueText);
return parent::install()
&& $this->registerHook('displayNav1');
}
public function uninstall()
{
foreach ($this->_tabs as $tab) {
$_tab_id = Tab::getIdFromClassName($tab['class_name']);
$_tab = new Tab($_tab_id);
$_tab->delete();
}
return parent::uninstall();
}
public function renderWidget($hookName, array $params)
{
$widget = [
'title' => Configuration::get(an_simple_contact::PREFIX . 'title', Context::getContext()->language->id),
'text' => Configuration::get(an_simple_contact::PREFIX . 'text', Context::getContext()->language->id),
];
$this->smarty->assign('widget', $widget);
return $this->fetch('module:' . $this->name . '/views/templates/front/widget.tpl');
}
public function getWidgetVariables($hookName, array $params)
{
}
public function getContent()
{
Tools::redirectAdmin($this->context->link->getAdminLink('AdminAnContact'));
}
public function topPromo()
{
$this->context->smarty->assign('theme', $this->getThemeInfo());
return $this->display(__FILE__, 'views/templates/admin/top.tpl');
}
public function getThemeInfo()
{
$theme = [];
$themeFileJson = _PS_THEME_DIR_.'/config/theme.json';
if (Tools::file_exists_no_cache($themeFileJson)) {
$theme = (array)json_decode(Tools::file_get_contents($themeFileJson), 1);
}
if (!isset($theme['url_contact_us']) || $theme['url_contact_us'] == ''){
$urlContactUs = 'https://addons.prestashop.com/contact-form.php';
if (isset($theme['addons_id']) && $theme['addons_id'] != ''){
$urlContactUs .= '?id_product=' .$theme['addons_id'];
} elseif (isset($this->url_contact_us) && $this->url_contact_us != ''){
$urlContactUs = $this->url_contact_us;
} elseif (isset($this->addons_product_id) && $this->addons_product_id != ''){
$urlContactUs .= '?id_product=' .$this->addons_product_id;
}
$theme['url_contact_us'] = $urlContactUs;
}
if (!isset($theme['url_rate']) || $theme['url_rate'] == ''){
$urlRate = 'https://addons.prestashop.com/ratings.php';
if (isset($theme['addons_id']) && $theme['addons_id'] != ''){
$urlRate .= '?id_product=' .$theme['addons_id'];
} elseif (isset($this->url_rate) && $this->url_rate != ''){
$urlRate = $this->url_rate;
} elseif (isset($this->addons_product_id) && $this->addons_product_id != ''){
$urlRate .= '?id_product=' .$this->addons_product_id;
}
$theme['url_rate'] = $urlRate;
}
return $theme;
}
}