Category Page Loading Time Reduced To Half
This commit is contained in:
parent
7176e10bbc
commit
ffc7f1a8ab
|
|
@ -230,26 +230,36 @@ class ShopController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will fetch products from category.
|
||||
*
|
||||
* @param int $categoryId
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getCategoryProducts($categoryId)
|
||||
{
|
||||
$products = $this->productRepository->getAll($categoryId);
|
||||
/* fetch category details */
|
||||
$categoryDetails = $this->categoryRepository->find($categoryId);
|
||||
|
||||
$productItems = $products->items();
|
||||
$productsArray = $products->toArray();
|
||||
|
||||
if ($productItems) {
|
||||
$formattedProducts = [];
|
||||
|
||||
foreach ($productItems as $product) {
|
||||
array_push($formattedProducts, $this->velocityHelper->formatProduct($product));
|
||||
}
|
||||
|
||||
$productsArray['data'] = $formattedProducts;
|
||||
/* if category not found then return empty response */
|
||||
if (! $categoryDetails) {
|
||||
return response()->json([
|
||||
'products' => [],
|
||||
'paginationHTML' => ''
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json($response ?? [
|
||||
'products' => $productsArray,
|
||||
'paginationHTML' => $products->appends(request()->input())->links()->toHtml(),
|
||||
/* fetching products */
|
||||
$products = $this->productRepository->getAll($categoryId);
|
||||
$products->withPath($categoryDetails->slug);
|
||||
|
||||
/* sending response */
|
||||
return response()->json([
|
||||
'products' => collect($products->items())->map(function ($product) {
|
||||
return $this->velocityHelper->formatProduct($product);
|
||||
}),
|
||||
'paginationHTML' => $products->appends(request()->input())->links()->toHtml()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -49,8 +49,6 @@
|
|||
'products_and_description'
|
||||
]
|
||||
);
|
||||
|
||||
$products = $productRepository->getAll($category->id);
|
||||
@endphp
|
||||
|
||||
@section('content-wrapper')
|
||||
|
|
@ -126,9 +124,7 @@
|
|||
|
||||
{!! view_render_event('bagisto.shop.productOrCategory.index.pagination.before', ['category' => $category]) !!}
|
||||
|
||||
<div class="bottom-toolbar">
|
||||
{{ $products->appends(request()->input())->links() }}
|
||||
</div>
|
||||
<div class="bottom-toolbar" v-html="paginationHTML"></div>
|
||||
|
||||
{!! view_render_event('bagisto.shop.productOrCategory.index.pagination.after', ['category' => $category]) !!}
|
||||
</template>
|
||||
|
|
@ -166,7 +162,7 @@
|
|||
this.$http.get(`${this.$root.baseUrl}/category-products/{{ $category->id }}${window.location.search}`)
|
||||
.then(response => {
|
||||
this.isLoading = false;
|
||||
this.products = response.data.products.data;
|
||||
this.products = response.data.products;
|
||||
this.paginationHTML = response.data.paginationHTML;
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue