This commit is contained in:
2026-06-15 00:52:13 +03:30
parent b021acde56
commit 345fbcd929
2 changed files with 36 additions and 10 deletions
@@ -191,9 +191,7 @@ class ProductController extends SuperController
$products = $categoryService->sortProductsForStore($products);
if (str_contains(request()->path(), '/customer/')) {
$products->each(function (Product $product) {
$product->setAttribute('show', $this->storeProductShowForCustomer($product));
});
$this->applyCustomerShow($products);
}
return response()->json($products);
@@ -203,12 +201,7 @@ class ProductController extends SuperController
$products = Product::with(['file'])->where('active', 1)->get();
if (str_contains(request()->path(), '/customer/')) {
$displayPriceService = app(ProductDisplayPriceService::class);
$displayPriceService->warmLivePriceCache();
$displayPriceService->enrichForApi($products);
$products->each(function (Product $product) use ($displayPriceService) {
$product->setAttribute('show', $displayPriceService->resolveCustomerShow($product));
});
$this->applyCustomerShow($products);
}
if (Product::hasPriceOffsetColumn() && str_contains(request()->path(), '/customer/')) {
@@ -231,10 +224,18 @@ class ProductController extends SuperController
->first();
if ($product) {
if (str_contains(request()->path(), '/customer/')) {
$this->applyCustomerShow(collect([$product]));
}
$product->similar = Product::with(['file'])
->where('group_type', $product->group_type)
->where('id', '!=', $id)
->get();
if (str_contains(request()->path(), '/customer/')) {
$this->applyCustomerShow($product->similar);
}
} else {
return response()->json(false);
}
@@ -378,6 +379,32 @@ class ProductController extends SuperController
return false;
}
private function applyCustomerShow($products): void
{
$products = $products instanceof \Illuminate\Support\Collection
? $products
: collect($products);
if ($products->isEmpty()) {
return;
}
if (app(ConfigService::class)->isStore()) {
$products->each(function (Product $product) {
$product->setAttribute('show', $this->storeProductShowForCustomer($product));
});
return;
}
$displayPriceService = app(ProductDisplayPriceService::class);
$displayPriceService->warmLivePriceCache();
$displayPriceService->enrichForApi($products);
$products->each(function (Product $product) use ($displayPriceService) {
$product->setAttribute('show', $displayPriceService->resolveCustomerShow($product));
});
}
private function filterProductData(array $data): array
{
if (!Product::hasPriceOffsetColumn()) {
-1
View File
@@ -174,7 +174,6 @@ class ProductPriceSyncService
}
$products = Product::query()->whereNotNull('reading_method')->get();
$currentTime = now()->format('H:i:s');
$synced = false;
foreach ($products as $product) {