This commit is contained in:
2026-06-12 19:49:53 +03:30
parent 11fb7272cb
commit 98e1fe969c
6 changed files with 310 additions and 9 deletions
+28 -1
View File
@@ -36,8 +36,20 @@ class ProductDisplayPriceService
/**
* پر کردن price روی مدل‌ها برای پاسخ JSON — بدون UPDATE دیتابیس
*/
/** پر کردن کش مظنه اگر خالی باشد (قبل از enrich لیست مشتری) */
public function warmLivePriceCache(): void
{
if (! is_array(Cache::get(self::LIVE_PRICE_CACHE_KEY))) {
$this->resolveFallbackPayload();
}
}
public function enrichForApi(Collection|iterable $products): void
{
if (app(ConfigService::class)->isStore()) {
return;
}
$collection = collect($products);
$zaarbox = app(ZaarboxPriceService::class);
$zaarboxFeed = $zaarbox->getCachedPriceListOnly();
@@ -88,10 +100,15 @@ class ProductDisplayPriceService
? $this->resolveLiveBuyPriceWithFallback()
: $this->resolveStrictLiveBuyPrice();
if ($unitBuy <= 0 && ! $useLast && app(ConfigService::class)->getBool('show_last_price', false)) {
if ($unitBuy <= 0 && app(ConfigService::class)->getBool('show_last_price', false)) {
$unitBuy = $this->resolveHistoricalBasePrice();
}
$offset = ProductPriceService::offsetPercent($product);
if ($unitBuy > 0 && $offset != 0.0) {
$unitBuy = ProductPriceService::adjustedTotal($unitBuy, 0, $offset);
}
$this->applyPriceOrFallback($product, $unitBuy, $useLast);
}
@@ -247,6 +264,16 @@ class ProductDisplayPriceService
{
$row = $zaarbox->findFeedRow($feed, (string) $product->reading_method);
if ($row === null) {
$useLast = $this->productUsesLastPriceIfZero($product);
$offset = ProductPriceService::offsetPercent($product);
$historical = app(ConfigService::class)->getBool('show_last_price', false)
? $this->resolveHistoricalBasePrice()
: 0;
$computed = $historical > 0
? ProductPriceService::adjustedTotal($historical, 0, $offset)
: 0;
$this->applyPriceOrFallback($product, $computed, $useLast);
return;
}