zarbox added
This commit is contained in:
@@ -3,11 +3,12 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Cnt;
|
||||
use App\Models\Product;
|
||||
use App\Models\Setting;
|
||||
|
||||
class ConfigService
|
||||
{
|
||||
public const PRICE_PROVIDERS = ['montzar', 'etehadie', 'taban_gohar', 'main_product'];
|
||||
public const PRICE_PROVIDERS = ['montzar', 'etehadie', 'taban_gohar', 'main_product', 'zaarbox'];
|
||||
|
||||
public function Config($name)
|
||||
{
|
||||
@@ -82,18 +83,35 @@ class ConfigService
|
||||
}
|
||||
|
||||
/**
|
||||
* شناسه محصول آبشده پیشفرض: اول settings، بعد جدول const.
|
||||
* شناسه محصول آبشده: اول settings، بعد const.
|
||||
* مقدار settings میتواند id عددی (مثل 13) یا reading_method (مثل estjt_...) باشد.
|
||||
*/
|
||||
public function mainProductId(): ?int
|
||||
{
|
||||
$fromSettings = $this->getString('main_product', '');
|
||||
if ($fromSettings !== '' && is_numeric($fromSettings)) {
|
||||
return (int) $fromSettings;
|
||||
}
|
||||
$product = $this->mainProduct();
|
||||
|
||||
$fromConst = Cnt::where('key', 'main_product')->value('value');
|
||||
if ($fromConst !== null && $fromConst !== '' && is_numeric($fromConst)) {
|
||||
return (int) $fromConst;
|
||||
return $product?->id;
|
||||
}
|
||||
|
||||
public function mainProduct(): ?Product
|
||||
{
|
||||
foreach ([$this->getString('main_product', ''), (string) (Cnt::where('key', 'main_product')->value('value') ?? '')] as $raw) {
|
||||
$raw = trim($raw);
|
||||
if ($raw === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_numeric($raw)) {
|
||||
$product = Product::find((int) $raw);
|
||||
if ($product) {
|
||||
return $product;
|
||||
}
|
||||
}
|
||||
|
||||
$byMethod = Product::where('reading_method', $raw)->first();
|
||||
if ($byMethod) {
|
||||
return $byMethod;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -122,6 +140,11 @@ class ConfigService
|
||||
return $this->priceProvider() === 'main_product';
|
||||
}
|
||||
|
||||
public function usesZaarboxPricing(): bool
|
||||
{
|
||||
return $this->priceProvider() === 'zaarbox';
|
||||
}
|
||||
|
||||
public function UpdateConfig($name, $value)
|
||||
{
|
||||
return Setting::updateOrCreate(
|
||||
|
||||
Reference in New Issue
Block a user