feat(extra-features): Update price_split to be more dynamic
Added show_currency bool as a parameter; made the span class and aria-label displaying the currency dynamic for accessibility
This commit is contained in:
@@ -275,7 +275,7 @@ class SmartyHelperFunctions
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function displayPriceSplit($price){
|
public static function displayPriceSplit($price, $show_currency = false) {
|
||||||
/* Helper to split the price into euros and cents to make it more stylish
|
/* Helper to split the price into euros and cents to make it more stylish
|
||||||
registered under public_html/modules/is_themecore/src/Hook/Smarty.php
|
registered under public_html/modules/is_themecore/src/Hook/Smarty.php
|
||||||
|
|
||||||
@@ -283,15 +283,16 @@ class SmartyHelperFunctions
|
|||||||
{price_split price=$product.price}
|
{price_split price=$product.price}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Convert to a string and only keep numbers, commas and dots
|
//Convert to a string and only keep numbers, commas and dots
|
||||||
|
$currency_name = \Context::getContext()->currency->name;
|
||||||
|
$currency_symbol = \Context::getContext()->currency->symbol;
|
||||||
$price_string = implode(',', $price);
|
$price_string = implode(',', $price);
|
||||||
$price_string = preg_replace('/[^0-9,.]/', '', $price_string);
|
$price_string = preg_replace('/[^0-9,.]/', '', $price_string);
|
||||||
|
|
||||||
// Split by comma and wrap each part in a span
|
// Split by comma and wrap each part in a span
|
||||||
$price_parts = explode(',', $price_string);
|
$price_parts = explode(',', $price_string);
|
||||||
if (count($price_parts) >= 2) {
|
if (count($price_parts) >= 2) {
|
||||||
echo '<span class="euros" aria-label="euros">' . $price_parts[0] . '</span>';
|
echo '<span class="' . htmlspecialchars($currency_name) . '" aria-label="' . htmlspecialchars($currency_name) . '">' . ($show_currency ? $currency_symbol : '') . $price_parts[0] . '</span>';
|
||||||
echo '<sup class="cents" aria-label="cents">' . $price_parts[1] . '</sup>';
|
echo '<sup class="cents" aria-label="cents">' . $price_parts[1] . '</sup>';
|
||||||
} else {
|
} else {
|
||||||
foreach ($price_parts as $part) {
|
foreach ($price_parts as $part) {
|
||||||
|
|||||||
Reference in New Issue
Block a user