https://medium.com/@lmeyer./get-an-error-free-e-commerce-web-site-using-sentry-b6061264efc8...
Remplacer par Gratuit lorsque le produit est à 0 euros - Prestashop 1.7
Ce module va vous permettre de changer l'affichage du prix quand le produit est gratuit
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class Baba_displayfreeproduct extends Module
{
public function __construct()
{
$this->name = 'baba_displayfreeproduct';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'presta.cafe';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('baba_displayfreeproduct');
$this->description = $this->l('Display free product instead price');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
}
public function install()
{
return parent::install() &&
$this->registerHook('filterProductContent') &&
$this->registerHook('actionOutputHTMLBefore') &&
$this->registerHook('displayHeader');
}
public function uninstall()
{
return parent::uninstall();
}
public function getContent()
{
$this->context->smarty->assign('module_dir', $this->_path);
$output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');
return $output;
}
public function hookFilterProductContent(array $params)
{
$params['object']['price'] = $this->_updateContentVars($params['object']['price'], $params);
return [
'object' => $params['object']
];
}
public function hookActionOutputHTMLBefore(array $params)
{
$page = Dispatcher::getInstance()->getController();
if ($page == 'category') {
$params['html'] = $this->_updateContentVars($params['html'], $params);
return true;
}
}
protected function _updateContentVars($content, $params)
{
$content = urldecode($content);
$regex = '/(?J)(?<num>[0-9]*[.,]?[0-9] )\s*(?<cur>\p{Sc})|(?<cur>\p{Sc})\s*(?<num>[0-9]*[.,]?[0-9] )/u';
preg_match_all($regex, $content, $prices); ///^\d (\.\d{2})?€/
if (isset($prices) && sizeof($prices)) {
foreach ($prices[1] as $price) {
if ($price =='0,00') {
$value='GRATUIT';
$content = preg_replace($regex, $value, $content);
}
}
}
return $content;
}
public function hookDisplayHeader($params)
{
$page = Dispatcher::getInstance()->getController();
if ($page == 'product') {
Media::addJsDef(['free' => 'GRATUIT']);
$this->context->controller->addJS(($this->_path).'views/js/baba_displayfreeproduct.js');
} else {
return false;
}
}
}
Publié dans:
Pimp Prestashop
Laissez un commentaire