2026-02-02 15:47:55 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Helpers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use App\Models\SellUnit;
|
|
|
|
|
use \Illuminate\Support\Str;
|
|
|
|
|
|
|
|
|
|
class BladeDirectivesHelper
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Format specific value.
|
|
|
|
|
* Used for blade directive @fmt_currency_without_auth.
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2026-02-05 16:45:01 +01:00
|
|
|
public static function formatPriceValue($value): string
|
2026-02-02 15:47:55 +01:00
|
|
|
{
|
|
|
|
|
if (is_float($value)) {
|
|
|
|
|
return sprintf('%s €', number_format($value, 2, ',', ' '));
|
|
|
|
|
}
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the formated value only if authorized.
|
|
|
|
|
* Used for blade directive @fmt_currency and @fmt_currency_without_ttc.
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function formatCurrency($value): string
|
|
|
|
|
{
|
|
|
|
|
if (!self::shouldShowPrices()) {
|
|
|
|
|
return '-.--';
|
|
|
|
|
}
|
|
|
|
|
return self::formatPriceValue($value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if prices must be shown or not.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2026-02-05 16:45:01 +01:00
|
|
|
public static function shouldShowPrices(): bool
|
2026-02-02 15:47:55 +01:00
|
|
|
{
|
|
|
|
|
return (config('bosettings.show_prices_authenticated') === "authenticated" && Auth::guard('customer')->check())
|
|
|
|
|
|| config('bosettings.show_prices_guest') == "guest";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format the sales unit according to configuration.
|
|
|
|
|
* Used for blade directive @fmt_sellunit.
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $expression
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function formatSellUnit($expression): string
|
|
|
|
|
{
|
|
|
|
|
if (config('bosettings.sell_unit_management') == "strict") {
|
|
|
|
|
return !empty($expression) ? sprintf('/ %s', SellUnit::make($expression)->label) : '';
|
|
|
|
|
}
|
|
|
|
|
return !empty($expression) ? sprintf('/ %s', $expression) : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract a title produced according to the theme configuration.
|
|
|
|
|
* Used for blade directive @excerpt_product_title.
|
|
|
|
|
*
|
|
|
|
|
* @param string $expression
|
|
|
|
|
* @param int|null $limit
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function excerptTitle(string $expression, $limit = null): string
|
|
|
|
|
{
|
|
|
|
|
$limit = $limit ?? config('theme.max_product_title_length');
|
|
|
|
|
return Str::limit($expression, $limit);
|
|
|
|
|
}
|
|
|
|
|
}
|