diff --git a/packages/Webkul/Shop/src/Http/Controllers/ProductController.php b/packages/Webkul/Shop/src/Http/Controllers/ProductController.php index 6d46e9427..b9372082f 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/ProductController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/ProductController.php @@ -3,6 +3,7 @@ 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; @@ -158,18 +159,20 @@ class ProductController extends Controller * * @return \Illuminate\Http\Response */ - public function getFilterAttributes($categoryId) + public function getFilterAttributes($categoryId = null, AttributeRepository $attributeRepository) { - $category = $this->categoryRepository->find($categoryId); + $filterAttributes = []; - if ($category) { - return response()->json([ - 'filter_attributes' => $this->productFlatRepository->getFilterAttributes($category) - ]); + if ($category = $this->categoryRepository->find($categoryId)) { + $filterAttributes = $this->productFlatRepository->getFilterAttributes($category); + } + + if (! count($filterAttributes) > 0) { + $filterAttributes = $attributeRepository->getFilterAttributes(); } return response()->json([ - 'filter_attributes' => [] + 'filter_attributes' => $filterAttributes, ]); } @@ -178,18 +181,16 @@ class ProductController extends Controller * * @return \Illuminate\Http\Response */ - public function getCategoryProductMaximumPrice($categoryId) + public function getCategoryProductMaximumPrice($categoryId = null) { - $category = $this->categoryRepository->find($categoryId); + $maxPrice = 0; - if ($category) { - return response()->json([ - 'max_price' => $this->productFlatRepository->handleCategoryProductMaximumPrice($category) - ]); + if ($category = $this->categoryRepository->find($categoryId)) { + $maxPrice = $this->productFlatRepository->handleCategoryProductMaximumPrice($category); } return response()->json([ - 'max_price' => 0 + '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 3447ea270..44bb9670b 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 @@ -1,7 +1,10 @@
{!! view_render_event('bagisto.shop.products.list.layered-nagigation.before') !!} - + + {!! view_render_event('bagisto.shop.products.list.layered-nagigation.after') !!}
@@ -21,6 +24,7 @@ :index="index" :attribute="attribute" :appliedFilterValues="appliedFilters[attribute.code]" + :max-price-src="maxPriceSrc" @onFilterAdded="addFilters(attribute.code, $event)"> @@ -46,7 +50,12 @@
  1. - + @@ -74,11 +83,16 @@ Vue.component('layered-navigation', { template: '#layered-navigation-template', + props: [ + 'attributeSrc', + 'maxPriceSrc', + ], + data: function() { return { appliedFilters: {}, attributes: [], - } + }; }, created: function () { @@ -90,7 +104,7 @@ methods: { setFilterAttributes: function () { axios - .get('{{ route('admin.catalog.products.get-filter-attributes', $category->id) }}') + .get(this.attributeSrc) .then((response) => { this.attributes = response.data.filter_attributes; }); @@ -111,7 +125,7 @@ delete this.appliedFilters[attributeCode]; } - this.applyFilter() + this.applyFilter(); }, applyFilter: function () { @@ -119,7 +133,7 @@ for(key in this.appliedFilters) { if (key != 'page') { - params.push(key + '=' + this.appliedFilters[key].join(',')) + params.push(key + '=' + this.appliedFilters[key].join(',')); } } @@ -131,7 +145,12 @@ Vue.component('filter-attribute-item', { template: '#filter-attribute-item-template', - props: ['index', 'attribute', 'appliedFilterValues'], + props: [ + 'index', + 'attribute', + 'appliedFilterValues', + 'maxPriceSrc', + ], data: function() { return { @@ -170,7 +189,7 @@ methods: { setMaxPrice: function () { axios - .get('{{ route('admin.catalog.products.get-category-product-maximum-price', $category->id) }}') + .get(this.maxPriceSrc) .then((response) => { let maxPrice = response.data.max_price; @@ -179,13 +198,13 @@ }, addFilter: function (e) { - this.$emit('onFilterAdded', this.appliedFilters) + this.$emit('onFilterAdded', this.appliedFilters); }, priceRangeUpdated: function (value) { this.appliedFilters = value; - this.$emit('onFilterAdded', this.appliedFilters) + this.$emit('onFilterAdded', this.appliedFilters); }, clearFilters: function () { @@ -195,7 +214,7 @@ this.appliedFilters = []; - this.$emit('onFilterAdded', this.appliedFilters) + this.$emit('onFilterAdded', this.appliedFilters); } } }); diff --git a/packages/Webkul/Shop/src/Routes/store-front-routes.php b/packages/Webkul/Shop/src/Routes/store-front-routes.php index 7e6e93172..369f24361 100644 --- a/packages/Webkul/Shop/src/Routes/store-front-routes.php +++ b/packages/Webkul/Shop/src/Routes/store-front-routes.php @@ -29,8 +29,8 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function */ Route::fallback(\Webkul\Shop\Http\Controllers\ProductsCategoriesProxyController::class . '@index') ->defaults('_config', [ - 'product_view' => 'shop::products.view', - 'category_view' => 'shop::products.index' + 'product_view' => 'shop::products.view', + 'category_view' => 'shop::products.index', ]) ->name('shop.productOrCategory.index'); }); @@ -39,14 +39,14 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function * Store front home. */ Route::get('/', [HomeController::class, 'index'])->defaults('_config', [ - 'view' => 'shop::home.index' + 'view' => 'shop::home.index', ])->name('shop.home.index'); /** * Store front search. */ Route::get('/search', [SearchController::class, 'index'])->defaults('_config', [ - 'view' => 'shop::search.search' + 'view' => 'shop::search.search', ])->name('shop.search.index'); Route::post('/upload-search-image', [HomeController::class, 'upload'])->name('shop.image.search.upload'); @@ -62,24 +62,24 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function * Product and categories routes. */ Route::get('/reviews/{slug}', [ReviewController::class, 'show'])->defaults('_config', [ - 'view' => 'shop::products.reviews.index' + 'view' => 'shop::products.reviews.index', ])->name('shop.reviews.index'); Route::get('/product/{slug}/review', [ReviewController::class, 'create'])->defaults('_config', [ - 'view' => 'shop::products.reviews.create' + 'view' => 'shop::products.reviews.create', ])->name('shop.reviews.create'); Route::post('/product/{slug}/review', [ReviewController::class, 'store'])->defaults('_config', [ - 'redirect' => 'shop.home.index' + 'redirect' => 'shop.home.index', ])->name('shop.reviews.store'); Route::get('/downloadable/download-sample/{type}/{id}', [ProductController::class, 'downloadSample'])->name('shop.downloadable.download_sample'); Route::get('/product/{id}/{attribute_id}', [ProductController::class, 'download'])->defaults('_config', [ - 'view' => 'shop.products.index' + '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('products/get-filter-attributes/{categoryId?}', [ProductController::class, 'getFilterAttributes'])->name('admin.catalog.products.get-filter-attributes'); - Route::get('products/get-category-product-maximum-price/{categoryId}', [ProductController::class, 'getCategoryProductMaximumPrice'])->name('admin.catalog.products.get-category-product-maximum-price'); + Route::get('products/get-category-product-maximum-price/{categoryId?}', [ProductController::class, 'getCategoryProductMaximumPrice'])->name('admin.catalog.products.get-category-product-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 23c4514ae..49e7a0a77 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 @@ -1,7 +1,10 @@
    {!! view_render_event('bagisto.shop.products.list.layered-nagigation.before') !!} - + + {!! view_render_event('bagisto.shop.products.list.layered-nagigation.after') !!}
    @@ -22,6 +25,7 @@ :index="index" :attribute="attribute" :appliedFilterValues="appliedFilters[attribute.code]" + :max-price-src="maxPriceSrc" @onFilterAdded="addFilters(attribute.code, $event)"> @@ -99,6 +103,11 @@ Vue.component('layered-navigation', { template: '#layered-navigation-template', + props: [ + 'attributeSrc', + 'maxPriceSrc', + ], + data: function() { return { appliedFilters: {}, @@ -115,7 +124,7 @@ methods: { setFilterAttributes: function () { axios - .get('{{ route('admin.catalog.products.get-filter-attributes', $category->id) }}') + .get(this.attributeSrc) .then((response) => { this.attributes = response.data.filter_attributes; }); @@ -144,7 +153,7 @@ for (key in this.appliedFilters) { if (key != 'page') { - params.push(key + '=' + this.appliedFilters[key].join(',')) + params.push(key + '=' + this.appliedFilters[key].join(',')); } } @@ -161,6 +170,7 @@ 'attribute', 'addFilters', 'appliedFilterValues', + 'maxPriceSrc', ], data: function() { @@ -204,21 +214,21 @@ methods: { setMaxPrice: function () { axios - .get('{{ route('admin.catalog.products.get-category-product-maximum-price', $category->id) }}') + .get(this.maxPriceSrc) .then((response) => { let maxPrice = response.data.max_price; this.sliderConfig.max = maxPrice ? ((parseInt(maxPrice) !== 0 || maxPrice) ? parseInt(maxPrice) : 500) : 500; }); }, - + addFilter: function (e) { - this.$emit('onFilterAdded', this.appliedFilters) + this.$emit('onFilterAdded', this.appliedFilters); }, priceRangeUpdated: function (value) { this.appliedFilters = value; - this.$emit('onFilterAdded', this.appliedFilters) + this.$emit('onFilterAdded', this.appliedFilters); }, clearFilters: function () { @@ -228,7 +238,7 @@ this.appliedFilters = []; - this.$emit('onFilterAdded', this.appliedFilters) + this.$emit('onFilterAdded', this.appliedFilters); }, optionClicked: function (id, {target}) { @@ -255,4 +265,4 @@ } }); -@endpush \ No newline at end of file +@endpush