fixed show true when price is 0 2
This commit is contained in:
@@ -73,6 +73,19 @@ class ProductDisplayPriceService
|
|||||||
continue;
|
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)) {
|
if ($this->isWeightBasedStoreProduct($product)) {
|
||||||
$this->enrichWeightBasedPrice($product);
|
$this->enrichWeightBasedPrice($product);
|
||||||
}
|
}
|
||||||
@@ -100,7 +113,7 @@ class ProductDisplayPriceService
|
|||||||
? $this->resolveLiveBuyPriceWithFallback()
|
? $this->resolveLiveBuyPriceWithFallback()
|
||||||
: $this->resolveStrictLiveBuyPrice();
|
: $this->resolveStrictLiveBuyPrice();
|
||||||
|
|
||||||
if ($unitBuy <= 0 && $useLast) {
|
if ($unitBuy <= 0 && app(ConfigService::class)->getBool('show_last_price', false)) {
|
||||||
$unitBuy = $this->resolveHistoricalBasePrice();
|
$unitBuy = $this->resolveHistoricalBasePrice();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,6 +278,7 @@ class ProductDisplayPriceService
|
|||||||
$useLast = $this->productUsesLastPriceIfZero($product);
|
$useLast = $this->productUsesLastPriceIfZero($product);
|
||||||
$row = $zaarbox->findFeedRow($feed, (string) $product->reading_method);
|
$row = $zaarbox->findFeedRow($feed, (string) $product->reading_method);
|
||||||
if ($row === null) {
|
if ($row === null) {
|
||||||
|
$product->setAttribute('reference_provider_active', $useLast);
|
||||||
$offset = ProductPriceService::offsetPercent($product);
|
$offset = ProductPriceService::offsetPercent($product);
|
||||||
$historical = $useLast ? $this->resolveHistoricalBasePrice() : 0;
|
$historical = $useLast ? $this->resolveHistoricalBasePrice() : 0;
|
||||||
$computed = $historical > 0
|
$computed = $historical > 0
|
||||||
@@ -275,6 +289,17 @@ class ProductDisplayPriceService
|
|||||||
return;
|
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);
|
$computed = $zaarbox->computeAdjustedProductPrice($product, $row);
|
||||||
if ($computed <= 0) {
|
if ($computed <= 0) {
|
||||||
if ($useLast) {
|
if ($useLast) {
|
||||||
@@ -441,11 +466,10 @@ class ProductDisplayPriceService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* نمایش در اپ کاربر:
|
* نمایش در اپ کاربر:
|
||||||
* • خاموش (active=false در DB) → false
|
* • خاموش (show=false در DB) → false
|
||||||
* • خارج از ساعات معامله → false
|
|
||||||
* • قیمت نمایشی بعد از enrich → true
|
* • قیمت نمایشی بعد از enrich → true
|
||||||
* • قیمت صفر و use_last_price_if_zero خاموش → false
|
* • قیمت صفر و show_last_price خاموش → false
|
||||||
* • قیمت صفر و use_last_price_if_zero روشن و fallback موجود → true
|
* • قیمت صفر و show_last_price روشن و fallback موجود → true
|
||||||
*/
|
*/
|
||||||
public function resolveCustomerShow(Product $product): bool
|
public function resolveCustomerShow(Product $product): bool
|
||||||
{
|
{
|
||||||
@@ -461,10 +485,11 @@ class ProductDisplayPriceService
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->productUsesLastPriceIfZero($product)) {
|
if (! app(ConfigService::class)->getBool('show_last_price', false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->resolveLastPriceFallback($product) > 0;
|
return $this->resolveLastPriceFallback($product) > 0
|
||||||
|
|| $this->resolveHistoricalBasePrice() > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,10 +51,6 @@ class ProductPriceService
|
|||||||
$data['price_profit'] = 0;
|
$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);
|
Product::where('id', $product->id)->update($data);
|
||||||
|
|
||||||
return [
|
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 جدید) */
|
/** وقتی فقط درصد در ادمین عوض میشود (بدون sync جدید) */
|
||||||
public static function reapplyOffsetPercent(Product $product, float $newOffsetPercent, ?float $oldOffsetPercent = null): void
|
public static function reapplyOffsetPercent(Product $product, float $newOffsetPercent, ?float $oldOffsetPercent = null): void
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user