fixed show true when price is 0

This commit is contained in:
2026-06-22 19:14:24 +03:30
parent f44cb7263b
commit 27d58e8a11
5 changed files with 161 additions and 55 deletions
+10 -24
View File
@@ -100,7 +100,7 @@ class ProductDisplayPriceService
? $this->resolveLiveBuyPriceWithFallback()
: $this->resolveStrictLiveBuyPrice();
if ($unitBuy <= 0 && app(ConfigService::class)->getBool('show_last_price', false)) {
if ($unitBuy <= 0 && $useLast) {
$unitBuy = $this->resolveHistoricalBasePrice();
}
@@ -262,25 +262,11 @@ class ProductDisplayPriceService
/** @param array<int, array<string, mixed>> $feed */
private function applyReferenceFeedPrice(Product $product, array $feed, ZaarboxPriceService $zaarbox): void
{
if (Product::hasStoredPriceColumns()) {
$stored = (int) ($product->price ?? 0) + (int) ($product->price_profit ?? 0);
if ($stored > 0) {
$product->setAttribute('price', (int) ($product->price ?? 0));
if (Schema::hasColumn($product->getTable(), 'price_profit')) {
$product->setAttribute('price_profit', (int) ($product->price_profit ?? 0));
}
return;
}
}
$useLast = $this->productUsesLastPriceIfZero($product);
$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;
$historical = $useLast ? $this->resolveHistoricalBasePrice() : 0;
$computed = $historical > 0
? ProductPriceService::adjustedTotal($historical, 0, $offset)
: 0;
@@ -291,7 +277,7 @@ class ProductDisplayPriceService
$computed = $zaarbox->computeAdjustedProductPrice($product, $row);
if ($computed <= 0) {
if ($this->productUsesLastPriceIfZero($product)) {
if ($useLast) {
$fallback = $this->resolveLastPriceFallback($product);
if ($fallback > 0) {
$product->setAttribute('price', $fallback);
@@ -455,10 +441,11 @@ class ProductDisplayPriceService
/**
* نمایش در اپ کاربر:
* • خاموش (show=false در DB) → false
* • خاموش (active=false در DB) → false
* • خارج از ساعات معامله → false
* • قیمت نمایشی بعد از enrich → true
* • قیمت صفر و show_last_price خاموش → false
* • قیمت صفر و show_last_price روشن و fallback موجود → true
* • قیمت صفر و use_last_price_if_zero خاموش → false
* • قیمت صفر و use_last_price_if_zero روشن و fallback موجود → true
*/
public function resolveCustomerShow(Product $product): bool
{
@@ -474,11 +461,10 @@ class ProductDisplayPriceService
return true;
}
if (! app(ConfigService::class)->getBool('show_last_price', false)) {
if (! $this->productUsesLastPriceIfZero($product)) {
return false;
}
return $this->resolveLastPriceFallback($product) > 0
|| $this->resolveHistoricalBasePrice() > 0;
return $this->resolveLastPriceFallback($product) > 0;
}
}