https://medium.com/@lmeyer./get-an-error-free-e-commerce-web-site-using-sentry-b6061264efc8...
Prestashop 1.7 - Mise à jour du prix en fonction de la quantité
baba_updqtprice.php
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class baba_updqtprice extends Module
{
public function __construct()
{
$this->name = 'baba_updqtprice';
$this->tab = 'others';
$this->version = '1.0.0';
$this->author = 'presta.cafe';
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('baba_updqtprice');
$this->description = $this->l('Update price by quantity on product page');
}
/**
* Installation du module
* @return bool
*/
public function install()
{
if (!parent::install()
|| !$this->registerHook([
'header',
])
) {
return false;
}
return true;
}
/**
* Désinstallation du module
* @return bool
*/
public function uninstall()
{
if (
!parent::uninstall()
) {
return false;
}
return true;
}
public function hookDisplayHeader($params)
{
$page = Dispatcher::getInstance()->getController();
if($page == 'product') {
// on instancie la currencie
$currency = new Currency((int)$params["cookie"]->id_currency);
Media::addJsDef(['currency' => $currency->sign]);
$this->context->controller->addJS(($this->_path).'views/js/baba_updqtprice.js');
} else {
return false;
}
}
}
baba_updqtprice.js
prestashop.on('updatedProduct', calculate);
function calculate (){
var qt = $("#quantity_wanted").val();
var regular_price = $(".regular-price").text();
var regular_price_rep = regular_price.toString().replace(currency, '').toString().replace(',', '.');
var regular_price_change = (regular_price_rep*qt).toFixed(2);
var currentprice = $(".current-price-value").attr("content");
var new_currentprice = (currentprice*qt).toFixed(2);
$( ".regular-price" ).replaceWith("<span class='regular-price'>" regular_price_change ' ' currency "</span>");
$( ".current-price-value" ).replaceWith("<span class='current-price-value' content='" new_currentprice "' >" new_currentprice ' ' currency "</span>");
}
Publié dans:
Aide Prestashop
Laissez un commentaire