fixed show true when price is 0 2

This commit is contained in:
2026-06-22 19:35:20 +03:30
parent 27d58e8a11
commit 8858cf968b
2 changed files with 32 additions and 24 deletions
+32 -7
View File
@@ -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;
}
}
-17
View File
@@ -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
{