From 4832b09ae972fdcffc9771b55f86afaa28569f49 Mon Sep 17 00:00:00 2001 From: jitendra Date: Wed, 14 Sep 2022 17:35:54 +0530 Subject: [PATCH 1/4] Improved code for category page --- .../Http/Controllers/CategoryController.php | 43 ++++++++++++++++- .../Http/Controllers/ProductController.php | 47 +------------------ .../list/layered-navigation.blade.php | 4 +- .../Shop/src/Routes/store-front-routes.php | 5 +- .../list/layered-navigation.blade.php | 4 +- 5 files changed, 50 insertions(+), 53 deletions(-) diff --git a/packages/Webkul/Shop/src/Http/Controllers/CategoryController.php b/packages/Webkul/Shop/src/Http/Controllers/CategoryController.php index 168c5657a..cbb6c689e 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/CategoryController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CategoryController.php @@ -2,7 +2,9 @@ namespace Webkul\Shop\Http\Controllers; +use Webkul\Attribute\Repositories\AttributeRepository; use Webkul\Category\Repositories\CategoryRepository; +use Webkul\Product\Repositories\ProductFlatRepository; class CategoryController extends Controller { @@ -10,10 +12,49 @@ class CategoryController extends Controller * Create a new controller instance. * * @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository + * @param \Webkul\Product\Repositories\ProductFlatRepository $productFlatRepository * @return void */ - public function __construct(protected CategoryRepository $categoryRepository) + public function __construct( + protected CategoryRepository $categoryRepository, + protected ProductFlatRepository $productFlatRepository + + ) { parent::__construct(); } + + /** + * Get filter attributes for product. + * + * @return \Illuminate\Http\Response + */ + public function getFilterAttributes($categoryId = null, AttributeRepository $attributeRepository) + { + $category = $this->categoryRepository->findOrFail($categoryId); + + if (empty($filterAttributes = $category->filterableAttributes)) { + $filterAttributes = $attributeRepository->getFilterAttributes(); + } + + return response()->json([ + 'filter_attributes' => $filterAttributes, + ]); + } + + /** + * Get category product maximum price. + * + * @return \Illuminate\Http\Response + */ + public function getCategoryProductMaximumPrice($categoryId = null) + { + $category = $this->categoryRepository->findOrFail($categoryId); + + $maxPrice = $this->productFlatRepository->handleCategoryProductMaximumPrice($category); + + return response()->json([ + 'max_price' => $maxPrice, + ]); + } } diff --git a/packages/Webkul/Shop/src/Http/Controllers/ProductController.php b/packages/Webkul/Shop/src/Http/Controllers/ProductController.php index 41b419477..2ad14209c 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/ProductController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/ProductController.php @@ -4,33 +4,24 @@ namespace Webkul\Shop\Http\Controllers; use Illuminate\Support\Facades\Storage; use Webkul\Attribute\Repositories\AttributeRepository; -use Webkul\Category\Repositories\CategoryRepository; use Webkul\Product\Repositories\ProductAttributeValueRepository; use Webkul\Product\Repositories\ProductDownloadableLinkRepository; use Webkul\Product\Repositories\ProductDownloadableSampleRepository; -use Webkul\Product\Repositories\ProductFlatRepository; -use Webkul\Product\Repositories\ProductRepository; class ProductController extends Controller { /** * Create a new controller instance. * - * @param \Webkul\Product\Repositories\ProductRepository $productRepository - * @param \Webkul\Product\Repositories\ProductFlatRepository $productFlatRepository * @param \Webkul\Product\Repositories\ProductAttributeValueRepository $productAttributeValueRepository * @param \Webkul\Product\Repositories\ProductDownloadableSampleRepository $productDownloadableSampleRepository * @param \Webkul\Product\Repositories\ProductDownloadableLinkRepository $productDownloadableLinkRepository - * @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository * @return void */ public function __construct( - protected ProductRepository $productRepository, - protected ProductFlatRepository $productFlatRepository, protected ProductAttributeValueRepository $productAttributeValueRepository, protected ProductDownloadableSampleRepository $productDownloadableSampleRepository, - protected ProductDownloadableLinkRepository $productDownloadableLinkRepository, - protected CategoryRepository $categoryRepository + protected ProductDownloadableLinkRepository $productDownloadableLinkRepository ) { parent::__construct(); @@ -100,40 +91,4 @@ class ProductController extends Controller abort(404); } } - - /** - * Get filter attributes for product. - * - * @return \Illuminate\Http\Response - */ - public function getFilterAttributes($categoryId = null, AttributeRepository $attributeRepository) - { - $category = $this->categoryRepository->findOrFail($categoryId); - - if (empty($filterAttributes = $category->filterableAttributes)) { - $filterAttributes = $attributeRepository->getFilterAttributes(); - } - - return response()->json([ - 'filter_attributes' => $filterAttributes, - ]); - } - - /** - * Get category product maximum price. - * - * @return \Illuminate\Http\Response - */ - public function getCategoryProductMaximumPrice($categoryId = null) - { - $maxPrice = 0; - - if ($category = $this->categoryRepository->find($categoryId)) { - $maxPrice = $this->productFlatRepository->handleCategoryProductMaximumPrice($category); - } - - return response()->json([ - 'max_price' => $maxPrice, - ]); - } } diff --git a/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php b/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php index 44bb9670b..6cdb0e6e0 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php @@ -2,8 +2,8 @@ {!! view_render_event('bagisto.shop.products.list.layered-nagigation.before') !!} + attribute-src="{{ route('catalog.categories.filterable-attributes', $category->id ?? null) }}" + max-price-src="{{ route('catalog.categories.maximum-price', $category->id ?? null) }}"> {!! view_render_event('bagisto.shop.products.list.layered-nagigation.after') !!} diff --git a/packages/Webkul/Shop/src/Routes/store-front-routes.php b/packages/Webkul/Shop/src/Routes/store-front-routes.php index 369f24361..8bd0b8690 100644 --- a/packages/Webkul/Shop/src/Routes/store-front-routes.php +++ b/packages/Webkul/Shop/src/Routes/store-front-routes.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; use Webkul\CMS\Http\Controllers\Shop\PagePresenterController; use Webkul\Shop\Http\Controllers\HomeController; use Webkul\Shop\Http\Controllers\ProductController; +use Webkul\Shop\Http\Controllers\CategoryController; use Webkul\Shop\Http\Controllers\ReviewController; use Webkul\Shop\Http\Controllers\SearchController; use Webkul\Shop\Http\Controllers\SubscriptionController; @@ -79,7 +80,7 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function 'view' => 'shop.products.index', ])->name('shop.product.file.download'); - Route::get('products/get-filter-attributes/{categoryId?}', [ProductController::class, 'getFilterAttributes'])->name('admin.catalog.products.get-filter-attributes'); + Route::get('categories/filterable-attributes/{categoryId?}', [CategoryController::class, 'getFilterAttributes'])->name('catalog.categories.filterable-attributes'); - Route::get('products/get-category-product-maximum-price/{categoryId?}', [ProductController::class, 'getCategoryProductMaximumPrice'])->name('admin.catalog.products.get-category-product-maximum-price'); + Route::get('categories/maximum-price/{categoryId?}', [CategoryController::class, 'getCategoryProductMaximumPrice'])->name('catalog.categories.maximum-price'); }); diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php index 1de0cd3ec..a360196ed 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php @@ -2,8 +2,8 @@ {!! view_render_event('bagisto.shop.products.list.layered-nagigation.before') !!} + attribute-src="{{ route('catalog.categories.filterable-attributes', $category->id ?? null) }}" + max-price-src="{{ route('catalog.categories.maximum-price', $category->id ?? null) }}"> {!! view_render_event('bagisto.shop.products.list.layered-nagigation.after') !!} From 1e7409c2559a5c94961381dd13aae7fc792dccb8 Mon Sep 17 00:00:00 2001 From: jitendra Date: Wed, 14 Sep 2022 17:37:40 +0530 Subject: [PATCH 2/4] Fixed duplicate ajax request for category max-price --- .../products/list/layered-navigation.blade.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php index a360196ed..4cec23dbb 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php @@ -176,18 +176,25 @@ data: function() { return { active: false, + appliedFilters: [], + sliderConfig: { max: 500, + value: [0, 0], + processStyle: { "backgroundColor": "#FF6472" }, + tooltipStyle: { "borderColor": "#FF6472", "backgroundColor": "#FF6472", }, + priceTo: 0, + priceFrom: 0, } } @@ -213,17 +220,16 @@ methods: { setMaxPrice: function () { + if (this.attribute['code'] != 'price') { + return; + } + axios .get(this.maxPriceSrc) .then((response) => { let maxPrice = response.data.max_price; this.sliderConfig.max = maxPrice ? ((parseInt(maxPrice) !== 0 || maxPrice) ? parseInt(maxPrice) : 500) : 500; - - if (! this.appliedFilterValues) { - this.sliderConfig.value = [0, this.sliderConfig.max]; - this.sliderConfig.priceTo = this.sliderConfig.max; - } }); }, From b0570b0f00e7d7cc2569bb427a618aa218bebf39 Mon Sep 17 00:00:00 2001 From: jitendra Date: Wed, 14 Sep 2022 17:38:31 +0530 Subject: [PATCH 3/4] Added changes to the Shop package --- .../views/products/list/layered-navigation.blade.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php b/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php index 6cdb0e6e0..cd1e0d192 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php @@ -155,13 +155,18 @@ data: function() { return { appliedFilters: [], + active: false, + sliderConfig: { value: [0, 0], + max: 500, + processStyle: { "backgroundColor": "#FF6472" }, + tooltipStyle: { "backgroundColor": "#FF6472", "borderColor": "#FF6472" @@ -188,6 +193,10 @@ methods: { setMaxPrice: function () { + if (this.attribute['code'] != 'price') { + return; + } + axios .get(this.maxPriceSrc) .then((response) => { From 439c1ece44c82a044f932c0931660de41a818efb Mon Sep 17 00:00:00 2001 From: jitendra Date: Wed, 14 Sep 2022 17:52:25 +0530 Subject: [PATCH 4/4] Added removed code again --- .../views/products/list/layered-navigation.blade.php | 6 +++++- .../views/shop/products/list/layered-navigation.blade.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php b/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php index cd1e0d192..c70477897 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/list/layered-navigation.blade.php @@ -201,8 +201,12 @@ .get(this.maxPriceSrc) .then((response) => { let maxPrice = response.data.max_price; - this.sliderConfig.max = maxPrice ? ((parseInt(maxPrice) !== 0 || maxPrice) ? parseInt(maxPrice) : 500) : 500; + + if (! this.appliedFilterValues) { + this.sliderConfig.value = [0, this.sliderConfig.max]; + this.sliderConfig.priceTo = this.sliderConfig.max; + } }); }, diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php index 4cec23dbb..b6dd2927b 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/layered-navigation.blade.php @@ -228,8 +228,12 @@ .get(this.maxPriceSrc) .then((response) => { let maxPrice = response.data.max_price; - this.sliderConfig.max = maxPrice ? ((parseInt(maxPrice) !== 0 || maxPrice) ? parseInt(maxPrice) : 500) : 500; + + if (! this.appliedFilterValues) { + this.sliderConfig.value = [0, this.sliderConfig.max]; + this.sliderConfig.priceTo = this.sliderConfig.max; + } }); },