Last active
May 29, 2024 20:48
-
-
Save Sentinel-7/a5ffea63ef8a7fb0b6ac30c1a7a877c2 to your computer and use it in GitHub Desktop.
плагин на округление цены в ms2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
switch($modx->event->name) { | |
case 'msOnGetProductPrice': | |
$returned_values = & $modx->event->returnedValues; | |
$values = $modx->event->params['data']; | |
$returned_values['price'] = ceil($values['price']/100)*100; // округляем в большу сторону | |
break; | |
case 'msOnGetProductFields': // событие не влияющее на цену для old_price | |
$returned_values = & $modx->event->returnedValues; | |
$values = $modx->event->params['data']; | |
if ($values['old_price'] > 0) { | |
$returned_values['old_price'] = ceil($values['old_price']/100)*100; | |
} | |
// $modx->log(1,'returned_price - ' . $returned_values['price'] ); | |
// $modx->log(1,'values_price - ' . $values['price'] ); | |
// $modx->log(1,'returned_old_price - ' . $returned_values['old_price'] ); //60 | |
// $modx->log(1,'values_old_price - ' . $values['old_price'] ); //30 | |
break; | |
} | |
// модификатор fenom | |
<?php | |
switch ($modx->event->name) { | |
case 'pdoToolsOnFenomInit': | |
$fenom->addModifier('priceformat', function ($price) { | |
$price = str_replace(' ','',$price); | |
return round($price, -2); | |
}); | |
break; | |
} | |
// вывод {$value | priceformat} | |
// js for ms2 | |
miniShop2.Utils.formatPrice = function (price) { | |
price = Math.ceil(price) | |
var pf = miniShop2Config.price_format; | |
price = this.number_format(price, pf[0], pf[1], pf[2]); | |
if (miniShop2Config.price_format_no_zeros && pf[0] > 0) { | |
price = price.replace(/(0+)$/, ''); | |
price = price.replace(/[^0-9]$/, ''); | |
} | |
return price; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment