From 8858cf968b55536a77faf27ca03f2f2621b72df4 Mon Sep 17 00:00:00 2001 From: adonis Date: Mon, 22 Jun 2026 19:35:20 +0330 Subject: [PATCH] fixed show true when price is 0 2 --- app/Services/ProductDisplayPriceService.php | 39 +++++++++++++++++---- app/Services/ProductPriceService.php | 17 --------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/app/Services/ProductDisplayPriceService.php b/app/Services/ProductDisplayPriceService.php index c15fb14..3f37689 100644 --- a/app/Services/ProductDisplayPriceService.php +++ b/app/Services/ProductDisplayPriceService.php @@ -73,6 +73,19 @@ class ProductDisplayPriceService continue; } + if ($product->reading_method && ! $this->productUsesLastPriceIfZero($product)) { + $product->setAttribute('reference_provider_active', false); + $this->zeroProductPrice($product); + + continue; + } + + if ($product->reading_method) { + $product->setAttribute('reference_provider_active', true); + + continue; + } + if ($this->isWeightBasedStoreProduct($product)) { $this->enrichWeightBasedPrice($product); } @@ -100,7 +113,7 @@ class ProductDisplayPriceService ? $this->resolveLiveBuyPriceWithFallback() : $this->resolveStrictLiveBuyPrice(); - if ($unitBuy <= 0 && $useLast) { + if ($unitBuy <= 0 && app(ConfigService::class)->getBool('show_last_price', false)) { $unitBuy = $this->resolveHistoricalBasePrice(); } @@ -265,6 +278,7 @@ class ProductDisplayPriceService $useLast = $this->productUsesLastPriceIfZero($product); $row = $zaarbox->findFeedRow($feed, (string) $product->reading_method); if ($row === null) { + $product->setAttribute('reference_provider_active', $useLast); $offset = ProductPriceService::offsetPercent($product); $historical = $useLast ? $this->resolveHistoricalBasePrice() : 0; $computed = $historical > 0 @@ -275,6 +289,17 @@ class ProductDisplayPriceService return; } + $normalized = $zaarbox->normalizeFeedRow($row); + $providerRaw = (int) round((float) ($normalized['price'] ?? 0) + (float) ($normalized['profit'] ?? 0)); + $providerActive = $useLast || $providerRaw > 0; + $product->setAttribute('reference_provider_active', $providerActive); + + if (! $useLast && $providerRaw <= 0) { + $this->zeroProductPrice($product); + + return; + } + $computed = $zaarbox->computeAdjustedProductPrice($product, $row); if ($computed <= 0) { if ($useLast) { @@ -441,11 +466,10 @@ class ProductDisplayPriceService /** * نمایش در اپ کاربر: - * • خاموش (active=false در DB) → false - * • خارج از ساعات معامله → false + * • خاموش (show=false در DB) → false * • قیمت نمایشی بعد از enrich → true - * • قیمت صفر و use_last_price_if_zero خاموش → false - * • قیمت صفر و use_last_price_if_zero روشن و fallback موجود → true + * • قیمت صفر و show_last_price خاموش → false + * • قیمت صفر و show_last_price روشن و fallback موجود → true */ public function resolveCustomerShow(Product $product): bool { @@ -461,10 +485,11 @@ class ProductDisplayPriceService return true; } - if (! $this->productUsesLastPriceIfZero($product)) { + if (! app(ConfigService::class)->getBool('show_last_price', false)) { return false; } - return $this->resolveLastPriceFallback($product) > 0; + return $this->resolveLastPriceFallback($product) > 0 + || $this->resolveHistoricalBasePrice() > 0; } } diff --git a/app/Services/ProductPriceService.php b/app/Services/ProductPriceService.php index 1b5b849..ea536d1 100644 --- a/app/Services/ProductPriceService.php +++ b/app/Services/ProductPriceService.php @@ -51,10 +51,6 @@ class ProductPriceService $data['price_profit'] = 0; } - if (\Illuminate\Support\Facades\Schema::hasColumn($product->getTable(), 'show')) { - $data['show'] = self::resolveShowAfterPriceSync($product, $adjustedPrice); - } - Product::where('id', $product->id)->update($data); return [ @@ -71,19 +67,6 @@ class ProductPriceService ]; } - private static function resolveShowAfterPriceSync(Product $product, int $adjustedPrice): bool - { - if (! ($product->active ?? true)) { - return false; - } - - if (! app(ConfigService::class)->isProductWithinTradingHours($product)) { - return false; - } - - return $adjustedPrice > 0; - } - /** وقتی فقط درصد در ادمین عوض می‌شود (بدون sync جدید) */ public static function reapplyOffsetPercent(Product $product, float $newOffsetPercent, ?float $oldOffsetPercent = null): void {