fix bug
This commit is contained in:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user