fix bug 3

This commit is contained in:
2026-06-11 21:48:18 +03:30
parent e8ebdcb44f
commit 779a67a23e
+30 -6
View File
@@ -42,18 +42,16 @@ class ProductDisplayPriceService
$zaarbox = app(ZaarboxPriceService::class);
$zaarboxFeed = $zaarbox->getCachedPriceListOnly();
$baseAppPrice = 0;
if ($collection->contains(fn ($p) => $p instanceof Product && $this->usesAppPrice($p))) {
$baseAppPrice = $this->resolveAppBasePrice();
}
foreach ($collection as $product) {
if (!$product instanceof Product) {
continue;
}
if ($this->usesAppPrice($product)) {
$this->applyAppPrice($product, $baseAppPrice);
$base = $this->productUsesLastPriceIfZero($product)
? $this->resolveAppBasePrice()
: $this->resolveStrictLiveAppBasePrice();
$this->applyAppPrice($product, $base);
continue;
}
@@ -156,6 +154,28 @@ class ProductDisplayPriceService
return (int) $last->price;
}
private function zeroProductPrice(Product $product): void
{
$product->setAttribute('price', 0);
if (Schema::hasColumn($product->getTable(), 'price_profit')) {
$product->setAttribute('price_profit', 0);
}
}
/**
* فقط قیمت زنده (کش /api/price/last) — بدون montzar_live_price قدیمی settings.
* وقتی use_last_price_if_zero خاموش است.
*/
public function resolveStrictLiveAppBasePrice(): int
{
$cached = Cache::get(self::LIVE_PRICE_CACHE_KEY);
if (!is_array($cached)) {
return 0;
}
return $this->extractBaseFromPayload($cached);
}
/** @param array<int, array<string, mixed>> $feed */
private function applyReferenceFeedPrice(Product $product, array $feed, ZaarboxPriceService $zaarbox): void
{
@@ -173,7 +193,11 @@ class ProductDisplayPriceService
if (Schema::hasColumn($product->getTable(), 'price_profit')) {
$product->setAttribute('price_profit', 0);
}
} else {
$this->zeroProductPrice($product);
}
} else {
$this->zeroProductPrice($product);
}
return;