fix bug 2
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -61,7 +62,7 @@ class ProductPriceSyncService
|
||||
|
||||
$basePrice = $display->resolveAppBasePrice();
|
||||
if ($basePrice <= 0) {
|
||||
return false;
|
||||
return $this->restoreAppProductsFromHistorical($products);
|
||||
}
|
||||
|
||||
$synced = false;
|
||||
@@ -73,6 +74,30 @@ class ProductPriceSyncService
|
||||
return $synced;
|
||||
}
|
||||
|
||||
/** provider صفر ولی use_last_price_if_zero — بازیابی از جدول prices به products.price */
|
||||
private function restoreAppProductsFromHistorical(Collection $products): bool
|
||||
{
|
||||
$historical = app(ProductDisplayPriceService::class)->resolveHistoricalBasePrice();
|
||||
if ($historical <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$synced = false;
|
||||
foreach ($products as $product) {
|
||||
if (!Product::hasUseLastPriceIfZeroColumn() || !($product->use_last_price_if_zero ?? false)) {
|
||||
continue;
|
||||
}
|
||||
if ((int) ($product->price ?? 0) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProductPriceService::syncFromReference($product, $historical, 0);
|
||||
$synced = true;
|
||||
}
|
||||
|
||||
return $synced;
|
||||
}
|
||||
|
||||
/** فید قدیمی — reading_method به شکل name (سازگاری با پروژههای قدیمی) */
|
||||
private function syncFromLegacyFeed(bool $forceRefresh = false): bool
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user