From 8f0548b70ca6e56312baabef456e6a4621f1a3bf Mon Sep 17 00:00:00 2001 From: Devansh Date: Mon, 25 Oct 2021 18:07:25 +0530 Subject: [PATCH 1/5] Some Indentation Done --- .../list/layered-navigation.blade.php | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 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 137ad209d..43e5beab5 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 @@ -45,7 +45,6 @@ @onFilterAdded="addFilters(attribute.code, $event)" :appliedFilterValues="appliedFilters[attribute.code]"> - @@ -70,7 +69,6 @@
  • -
    @@ -105,12 +103,13 @@ id="price_from" /> + + type="text" + disabled + name="price_to" + :value="sliderConfig.priceTo" + id="price_to">
    @@ -120,6 +119,7 @@ @endpush 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 43e5beab5..1ca5cde30 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,30 +1,17 @@ -@inject ('productRepository', 'Webkul\Product\Repositories\ProductRepository') -@inject ('attributeRepository', 'Webkul\Attribute\Repositories\AttributeRepository') @inject ('productFlatRepository', 'Webkul\Product\Repositories\ProductFlatRepository') getFilterAttributes($category); - if (isset($category)) { - $filterAttributes = $productFlatRepository->getProductsRelatedFilterableAttributes($category); - - $maxPrice = core()->convertPrice($productFlatRepository->getCategoryProductMaximumPrice($category)); - } - - if (! count($filterAttributes) > 0) { - $filterAttributes = $attributeRepository->getFilterAttributes(); - } + $maxPrice = $productFlatRepository->handleCategoryProductMaximumPrice($category); ?>
    - {!! view_render_event('bagisto.shop.products.list.layered-nagigation.before') !!} {!! view_render_event('bagisto.shop.products.list.layered-nagigation.after') !!} -
    @push('scripts') From f6e35691064494115590dc14e1bc47f54bb25eee Mon Sep 17 00:00:00 2001 From: Devansh Date: Tue, 26 Oct 2021 11:27:38 +0530 Subject: [PATCH 3/5] Attributes Ajaxified --- .../Http/Controllers/ProductController.php | 91 ++++++++++++++++--- packages/Webkul/Shop/src/Http/routes.php | 7 ++ .../list/layered-navigation.blade.php | 73 ++++++++------- .../list/layered-navigation.blade.php | 75 ++++++++------- 4 files changed, 170 insertions(+), 76 deletions(-) diff --git a/packages/Webkul/Shop/src/Http/Controllers/ProductController.php b/packages/Webkul/Shop/src/Http/Controllers/ProductController.php index 05485df1b..6d46e9427 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/ProductController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/ProductController.php @@ -3,70 +3,93 @@ namespace Webkul\Shop\Http\Controllers; use Illuminate\Support\Facades\Storage; -use Webkul\Product\Repositories\ProductRepository; +use Webkul\Category\Repositories\CategoryRepository; use Webkul\Product\Repositories\ProductAttributeValueRepository; -use Webkul\Product\Repositories\ProductDownloadableSampleRepository; use Webkul\Product\Repositories\ProductDownloadableLinkRepository; +use Webkul\Product\Repositories\ProductDownloadableSampleRepository; +use Webkul\Product\Repositories\ProductFlatRepository; +use Webkul\Product\Repositories\ProductRepository; class ProductController extends Controller { /** - * ProductRepository object + * Product repository instance. * * @var \Webkul\Product\Repositories\ProductRepository */ protected $productRepository; /** - * ProductAttributeValueRepository object + * Product flat repository instance. + * + * @var \Webkul\Product\Repositories\ProductFlatRepository + */ + protected $productFlatRepository; + + /** + * Product attribute value repository instance. * * @var \Webkul\Product\Repositories\ProductAttributeValueRepository */ protected $productAttributeValueRepository; /** - * ProductDownloadableSampleRepository object + * Product downloadable sample repository instance. * * @var \Webkul\Product\Repositories\ProductDownloadableSampleRepository */ protected $productDownloadableSampleRepository; /** - * ProductDownloadableLinkRepository object + * Product downloadable link repository instance. * * @var \Webkul\Product\Repositories\ProductDownloadableLinkRepository */ protected $productDownloadableLinkRepository; + /** + * Category repository instance. + * + * @var \Webkul\Category\Repositories\CategoryRepository + */ + protected $categoryRepository; + /** * Create a new controller instance. * * @param \Webkul\Product\Repositories\ProductRepository $productRepository - * @param \Webkul\Product\Repositories\productAttributeValueRepository $productAttributeValueRepository + * @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( ProductRepository $productRepository, + ProductFlatRepository $productFlatRepository, ProductAttributeValueRepository $productAttributeValueRepository, ProductDownloadableSampleRepository $productDownloadableSampleRepository, - ProductDownloadableLinkRepository $productDownloadableLinkRepository - ) - { + ProductDownloadableLinkRepository $productDownloadableLinkRepository, + CategoryRepository $categoryRepository + ) { $this->productRepository = $productRepository; + $this->productFlatRepository = $productFlatRepository; + $this->productAttributeValueRepository = $productAttributeValueRepository; $this->productDownloadableSampleRepository = $productDownloadableSampleRepository; $this->productDownloadableLinkRepository = $productDownloadableLinkRepository; + $this->categoryRepository = $categoryRepository; + parent::__construct(); } /** - * Download image or file + * Download image or file. * * @param int $productId * @param int $attributeId @@ -102,7 +125,7 @@ class ProductController extends Controller ? $privateDisk->download($productDownloadableLink->sample_file) : abort(404); } else { - $fileName = $name = substr($productDownloadableLink->sample_url, strrpos($productDownloadableLink->sample_url, '/') + 1); + $fileName = substr($productDownloadableLink->sample_url, strrpos($productDownloadableLink->sample_url, '/') + 1); $tempImage = tempnam(sys_get_temp_dir(), $fileName); @@ -116,7 +139,7 @@ class ProductController extends Controller if ($productDownloadableSample->type == 'file') { return Storage::download($productDownloadableSample->file); } else { - $fileName = $name = substr($productDownloadableSample->url, strrpos($productDownloadableSample->url, '/') + 1); + $fileName = substr($productDownloadableSample->url, strrpos($productDownloadableSample->url, '/') + 1); $tempImage = tempnam(sys_get_temp_dir(), $fileName); @@ -125,8 +148,48 @@ class ProductController extends Controller return response()->download($tempImage, $fileName); } } - } catch(\Exception $e) { + } catch (\Exception $e) { abort(404); } } + + /** + * Get filter attributes for product. + * + * @return \Illuminate\Http\Response + */ + public function getFilterAttributes($categoryId) + { + $category = $this->categoryRepository->find($categoryId); + + if ($category) { + return response()->json([ + 'filter_attributes' => $this->productFlatRepository->getFilterAttributes($category) + ]); + } + + return response()->json([ + 'filter_attributes' => [] + ]); + } + + /** + * Get category product maximum price. + * + * @return \Illuminate\Http\Response + */ + public function getCategoryProductMaximumPrice($categoryId) + { + $category = $this->categoryRepository->find($categoryId); + + if ($category) { + return response()->json([ + 'max_price' => $this->productFlatRepository->handleCategoryProductMaximumPrice($category) + ]); + } + + return response()->json([ + 'max_price' => 0 + ]); + } } diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php index 7822f8f6a..0a9aeb5cd 100755 --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Http/routes.php @@ -149,6 +149,13 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function 'view' => 'shop.products.index' ])->name('shop.product.file.download'); + /** + * Product related 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'); + /** * These are the routes which are used during checkout for checking the customer. * So, placed outside the cart merger middleware. 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 6ecee8c91..3447ea270 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,11 +1,3 @@ -@inject ('productFlatRepository', 'Webkul\Product\Repositories\ProductFlatRepository') - -getFilterAttributes($category); - - $maxPrice = $productFlatRepository->handleCategoryProductMaximumPrice($category); -?> -
    {!! view_render_event('bagisto.shop.products.list.layered-nagigation.before') !!} @@ -25,11 +17,11 @@
    + :attribute="attribute" + :appliedFilterValues="appliedFilters[attribute.code]" + @onFilterAdded="addFilters(attribute.code, $event)">
    @@ -38,7 +30,7 @@