first commit
This commit is contained in:
51
class/smarty_plugins/modifier.format_price.php
Normal file
51
class/smarty_plugins/modifier.format_price.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {format_price} function plugin.
|
||||
*
|
||||
* @param int|array $price integer or array containing price
|
||||
* @param string $params String describing
|
||||
* parameters and default values:
|
||||
* "withVat" => true,
|
||||
* "ceil" => "default",
|
||||
* "format" => true,
|
||||
* "printcurrency" => true,
|
||||
* "printdealerdiscount" => false,
|
||||
* "dealerdiscount" => true,
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
function smarty_modifier_format_price($price, $params = '')
|
||||
{
|
||||
if ($price instanceof \KupShop\KupShopBundle\Wrapper\PriceWrapper) {
|
||||
$price = $price->getObject();
|
||||
}
|
||||
|
||||
// TODO remove: Fix float formated using czech locale
|
||||
if (is_string($price) && strpos($price, ',') !== false) {
|
||||
$price = str_replace(',', '.', $price);
|
||||
}
|
||||
|
||||
$cond = [];
|
||||
$part = preg_split('/;|,/', $params);
|
||||
for ($i = 0; $i < count($part); $i++) {
|
||||
$pair = explode('=', $part[$i]);
|
||||
if ($pair[0] == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($pair[1] == 'true' || $pair[1] == 'yes') {
|
||||
$cond[$pair[0]] = true;
|
||||
} elseif ($pair[1] == 'false' || $pair[1] == 'no') {
|
||||
$cond[$pair[0]] = false;
|
||||
} else {
|
||||
$cond[$pair[0]] = (string) $pair[1];
|
||||
}
|
||||
}
|
||||
|
||||
return printPrice($price, $cond);
|
||||
}
|
||||
Reference in New Issue
Block a user