ghatre changes

This commit is contained in:
2026-06-29 18:22:41 +03:30
parent bedbea0ff1
commit 686562622d
2 changed files with 31 additions and 15 deletions
@@ -186,22 +186,13 @@ class ProductController extends SuperController
public function listProduct()
{
if (app(ConfigService::class)->isStore()) {
app(ProductPriceSyncService::class)->syncStorePrices(true);
// اپ مشتری: فقط DB — sync با HTTP فقط cron/admin (جلوگیری از pending طولانی list)
if (! $this->isCustomerApiRequest()) {
app(ProductPriceSyncService::class)->syncStorePrices(true);
$this->auto_close_open();
}
$products = Product::with(['file'])->where('active', 1)->get();
$categoryService = app(CategoryService::class);
$products = $categoryService->filterProductsByVisibleCategories($products);
$products = $categoryService->sortProductsForStore($products);
if ($this->isCustomerApiRequest()) {
$this->applyCustomerShow($products);
}
return response()->json($products);
return response()->json($this->customerStoreProductListPayload());
}
// آبشده خانگی — کران قیمت را آپدیت می‌کند؛ list فقط از DB می‌خواند
@@ -224,8 +215,10 @@ class ProductController extends SuperController
public function ProductById($id)
{
app(ProductPriceSyncService::class)->syncStorePrices(true);
$this->auto_close_open();
if (! $this->isCustomerApiRequest()) {
app(ProductPriceSyncService::class)->syncStorePrices(true);
$this->auto_close_open();
}
$product = Product::with(['file'])
->where('id', $id)
->first();
@@ -532,7 +525,26 @@ class ProductController extends SuperController
private function isCustomerApiRequest(): bool
{
return str_starts_with(request()->path(), 'customer/');
$path = trim((string) request()->path(), '/');
return str_starts_with($path, 'customer/')
|| str_contains($path, '/customer/');
}
/**
* لیست محصولات فروشگاه برای اپ/SSE — فقط DB، بدون sync خارجی.
*
* @return array<int, mixed>
*/
public function customerStoreProductListPayload(): array
{
$products = Product::with(['file'])->where('active', 1)->get();
$categoryService = app(CategoryService::class);
$products = $categoryService->filterProductsByVisibleCategories($products);
$products = $categoryService->sortProductsForStore($products);
$this->applyCustomerShow($products);
return $products->values()->all();
}
private function applyCustomerShow($products): void