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() public function listProduct()
{ {
if (app(ConfigService::class)->isStore()) { if (app(ConfigService::class)->isStore()) {
app(ProductPriceSyncService::class)->syncStorePrices(true); // اپ مشتری: فقط DB — sync با HTTP فقط cron/admin (جلوگیری از pending طولانی list)
if (! $this->isCustomerApiRequest()) { if (! $this->isCustomerApiRequest()) {
app(ProductPriceSyncService::class)->syncStorePrices(true);
$this->auto_close_open(); $this->auto_close_open();
} }
$products = Product::with(['file'])->where('active', 1)->get(); return response()->json($this->customerStoreProductListPayload());
$categoryService = app(CategoryService::class);
$products = $categoryService->filterProductsByVisibleCategories($products);
$products = $categoryService->sortProductsForStore($products);
if ($this->isCustomerApiRequest()) {
$this->applyCustomerShow($products);
}
return response()->json($products);
} }
// آبشده خانگی — کران قیمت را آپدیت می‌کند؛ list فقط از DB می‌خواند // آبشده خانگی — کران قیمت را آپدیت می‌کند؛ list فقط از DB می‌خواند
@@ -224,8 +215,10 @@ class ProductController extends SuperController
public function ProductById($id) public function ProductById($id)
{ {
app(ProductPriceSyncService::class)->syncStorePrices(true); if (! $this->isCustomerApiRequest()) {
$this->auto_close_open(); app(ProductPriceSyncService::class)->syncStorePrices(true);
$this->auto_close_open();
}
$product = Product::with(['file']) $product = Product::with(['file'])
->where('id', $id) ->where('id', $id)
->first(); ->first();
@@ -532,7 +525,26 @@ class ProductController extends SuperController
private function isCustomerApiRequest(): bool 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 private function applyCustomerShow($products): void
+4
View File
@@ -196,6 +196,10 @@ class PriceBroadcastService
*/ */
private function buildProductListPayload(): ?array private function buildProductListPayload(): ?array
{ {
if (app(ConfigService::class)->isStore()) {
return app(ProductController::class)->customerStoreProductListPayload();
}
$request = Request::create('/customer/product/list', 'GET'); $request = Request::create('/customer/product/list', 'GET');
app()->instance('request', $request); app()->instance('request', $request);