new check for kashkol 3

This commit is contained in:
2026-06-12 16:55:22 +03:30
parent db27b73188
commit 8540d57abc
@@ -152,18 +152,38 @@ class ProductController extends SuperController
public function listProduct()
{
$isCustomerApi = str_contains(request()->path(), '/customer/');
$config = app(ConfigService::class);
$isStore = $config->isStore();
// ادمین: sync اختیاری از کش — کاربر: فقط enrich از کش کران (بدون HTTP / بدون UPDATE)
if (!str_contains(request()->path(), '/customer/')) {
if (! $isCustomerApi) {
app(\App\Services\ProductPriceSyncService::class)->syncAll(false);
}
// فروشگاه (قطره / کشکول): مثل ghatre — show بر اساس ساعت auto_open/auto_close
if ($isCustomerApi && $isStore) {
$this->auto_close_open();
}
$products = Product::with(['file'])->where('active', 1)->get();
if (str_contains(request()->path(), '/customer/')) {
if ($isCustomerApi) {
$displayPriceService = app(ProductDisplayPriceService::class);
$displayPriceService->enrichForApi($products);
$products->each(function (Product $product) use ($displayPriceService) {
if (!$displayPriceService->hasCustomerDisplayPrice($product)) {
$showLastPrice = $config->getBool('show_last_price', false);
$products->each(function (Product $product) use ($displayPriceService, $isStore, $showLastPrice) {
if ($isStore) {
// فقط وقتی قیمت صفر است و fallback آخرین قیمت هم خاموش است
if (! $displayPriceService->hasCustomerDisplayPrice($product) && ! $showLastPrice) {
$product->setAttribute('show', false);
}
return;
}
if (! $displayPriceService->hasCustomerDisplayPrice($product)) {
$product->setAttribute('show', false);
}
});