🖥️ Server: LiteSpeed
💻 System: Linux s20058.bom1.stableserver.net 5.14.0-611.55.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 19 15:19:29 EDT 2026 x86_64
👤 User: skhata (1324)
🐘 PHP: 8.4.20
🚫 Disabled: ✨ NONE
📄 helpers.php
📁 Path: /home/skhata/new.chandrapharma.com/app/helpers.php
📊 Size: 6.21 KB
🔒 Perm: 0600
📝 MIME: text/x-php
<?php
if (! function_exists('settings')) {
/**
* Read an application setting.
*
* The $key uses dot-notation: "group.key" (e.g. "loyalty.earn_rate").
* Resolution order:
* 1. config('settings.{key}') — allows Config::set() in tests to override
* 2. Setting model in DB — persistent store
* 3. $default
*
* Example:
* settings('loyalty.earn_rate', 1)
* Config::set('settings.loyalty.earn_rate', 2.0) // overrides in tests
*/
function settings(string $key, mixed $default = null): mixed
{
// 1. Check config (allows test-time overrides via Config::set)
$configVal = config('settings.' . $key);
if ($configVal !== null) {
return $configVal;
}
// 2. Parse group / key from dot-notation
$parts = explode('.', $key, 2);
$group = count($parts) === 2 ? $parts[0] : 'general';
$k = count($parts) === 2 ? $parts[1] : $key;
// 3. Read from DB via Setting model
if (class_exists(\App\Modules\CMS\Models\Setting::class)) {
return \App\Modules\CMS\Models\Setting::get($k, $default, $group);
}
return $default;
}
}
if (! function_exists('__stp_request_cached')) {
/**
* Per-request memoization for cheap-but-frequently-called Setting
* lookups — binds to the container INSTANCE rather than a plain
* `static` variable inside the caller. A `static` var lives for the
* whole PHP process, not just one request: under a long-running
* worker (Octane) that means every visitor after the first gets
* whichever value happened to be cached when the process booted,
* and in the test suite it means a Setting::set() call in one test
* is invisible to a helper() call in a later test that happens to
* run in the same process — this is the exact bug
* App\Http\ViewComposers\GlobalLayoutComposer was already fixed for
* (see its class doc comment); is_multivendor() and friends below
* had the same bug via `static $cache`, just not yet caught by a
* test that saved a Setting and then called the helper afterwards
* in the same run.
*/
function __stp_request_cached(string $key, \Closure $resolver): mixed
{
if (! app()->bound($key)) {
app()->instance($key, $resolver());
}
return app($key);
}
}
if (! function_exists('is_multivendor')) {
/**
* True when the site operates in multi-vendor mode.
* Checks the DB setting first; falls back to config/multivendor.php.
* Result is cached for the life of the request (container instance).
*/
function is_multivendor(): bool
{
return __stp_request_cached('stp.is_multivendor', function () {
$singleVendorMode = class_exists(\App\Modules\CMS\Models\Setting::class)
? (bool) \App\Modules\CMS\Models\Setting::get('single_vendor_mode', false, 'vendor')
: false;
return config('multivendor.enabled', true) && ! $singleVendorMode;
});
}
}
if (! function_exists('show_vendor_frontend')) {
/**
* True when vendor info (badges, names, store links) should be shown on the storefront.
* Requires multi-vendor mode AND the "hide vendor frontend" setting to be OFF.
*/
function show_vendor_frontend(): bool
{
return __stp_request_cached('stp.show_vendor_frontend', function () {
if (! is_multivendor()) {
return false;
}
$hide = class_exists(\App\Modules\CMS\Models\Setting::class)
? (bool) \App\Modules\CMS\Models\Setting::get('hide_vendor_frontend', false, 'vendor')
: false;
return ! $hide;
});
}
}
if (! function_exists('default_vendor_id')) {
/**
* Returns the configured default vendor ID (from DB setting or config fallback).
*/
function default_vendor_id(): int
{
return __stp_request_cached('stp.default_vendor_id', function () {
$fromDb = class_exists(\App\Modules\CMS\Models\Setting::class)
? \App\Modules\CMS\Models\Setting::get('default_vendor_id', null, 'vendor')
: null;
return (int) ($fromDb ?? config('multivendor.default_vendor_id', 1));
});
}
}
if (! function_exists('currency_symbol')) {
/**
* The symbol/prefix to display next to prices, driven by the
* General Settings > Currency setting. That setting used to be
* decorative — every price template hardcoded "Rs." directly and
* ignored it entirely. This is what makes it actually do something.
* Cached for the life of the request (container instance), same
* pattern as is_multivendor()/show_vendor_frontend() above.
*/
function currency_symbol(): string
{
return __stp_request_cached('stp.currency_symbol', function () {
$code = class_exists(\App\Modules\CMS\Models\Setting::class)
? (string) \App\Modules\CMS\Models\Setting::get('store_currency', 'NPR', 'general')
: 'NPR';
return match ($code) {
'INR' => '₹',
'USD' => '$',
'EUR' => '€',
default => 'Rs.', // NPR, and any unrecognized code
};
});
}
}
if (! function_exists('format_price')) {
/**
* Format a numeric price using the store's configured currency symbol
* (see currency_symbol() above) unless one is passed explicitly.
* e.g. format_price(1234.5) → "Rs. 1,234.50" (or "₹ 1,234.50" once
* General Settings > Currency is set to INR).
*/
function format_price(float $amount, ?string $currency = null): string
{
return ($currency ?? currency_symbol()) . ' ' . number_format($amount, 2);
}
}
if (! function_exists('format_discount')) {
/**
* Format a discount for display.
* e.g. format_discount('percent', 20) → "20% OFF"
* format_discount('flat', 200) → "Rs. 200 OFF"
*/
function format_discount(string $type, float $value): string
{
if ($type === 'percent') {
return number_format($value, 0) . '% OFF';
}
return format_price($value) . ' OFF';
}
}
✨ File Manager Magic ✨