From 63d86f5def375e4f7f00ebf7578f43f48ee272d6 Mon Sep 17 00:00:00 2001 From: nikolayandreev Date: Fri, 12 Feb 2021 15:22:38 +0200 Subject: [PATCH 1/6] Update getMaximamPrice() to return product price instead of getMinimalPrice() in AbstractType. Solving issue with Simple products where price and special_price were the same amount in the REST API. --- packages/Webkul/Product/src/Type/AbstractType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Webkul/Product/src/Type/AbstractType.php b/packages/Webkul/Product/src/Type/AbstractType.php index 460dda2dd..adf2f27b4 100644 --- a/packages/Webkul/Product/src/Type/AbstractType.php +++ b/packages/Webkul/Product/src/Type/AbstractType.php @@ -536,7 +536,7 @@ abstract class AbstractType */ public function getMaximamPrice() { - return $this->getMinimalPrice(); + return $this->product->price; } /** From b3e1c63fd3d93c62aeba2eb325ded9f1d4028016 Mon Sep 17 00:00:00 2001 From: nikolayandreev Date: Mon, 15 Feb 2021 12:34:31 +0200 Subject: [PATCH 2/6] Add capability to serach via multiple categoryIds in the REST API --- .../Product/src/Repositories/ProductRepository.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/Webkul/Product/src/Repositories/ProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductRepository.php index dbbc10a50..3a686f7e7 100755 --- a/packages/Webkul/Product/src/Repositories/ProductRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductRepository.php @@ -129,11 +129,11 @@ class ProductRepository extends Repository } /** - * @param int $categoryId + * @param string $categories * * @return \Illuminate\Support\Collection */ - public function getAll($categoryId = null) + public function getAll($categories = null) { $params = request()->input(); @@ -147,7 +147,7 @@ class ProductRepository extends Repository $page = Paginator::resolveCurrentPage('page'); - $repository = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($params, $categoryId) { + $repository = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($params, $categories) { $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $locale = request()->get('locale') ?: app()->getLocale(); @@ -161,8 +161,8 @@ class ProductRepository extends Repository ->where('product_flat.locale', $locale) ->whereNotNull('product_flat.url_key'); - if ($categoryId) { - $qb->where('product_categories.category_id', $categoryId); + if ($categories) { + $qb->whereIn('product_categories.category_id', explode(',', $categories)); } if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) { From d6398da5c35295ea6ab725e0a7a7334a7bac362c Mon Sep 17 00:00:00 2001 From: nikolayandreev Date: Mon, 15 Feb 2021 12:40:47 +0200 Subject: [PATCH 3/6] Changed ProductController key for API endpoint /products?category_id to /products?categories=1,2,3 or categories=1 --- packages/Webkul/API/Http/Controllers/Shop/ProductController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Webkul/API/Http/Controllers/Shop/ProductController.php b/packages/Webkul/API/Http/Controllers/Shop/ProductController.php index 051982e51..992dc66e6 100755 --- a/packages/Webkul/API/Http/Controllers/Shop/ProductController.php +++ b/packages/Webkul/API/Http/Controllers/Shop/ProductController.php @@ -34,7 +34,7 @@ class ProductController extends Controller */ public function index() { - return ProductResource::collection($this->productRepository->getAll(request()->input('category_id'))); + return ProductResource::collection($this->productRepository->getAll(request()->input('categories'))); } /** From 0f27f5c880ff1e8b9ff001503745513b5d8d8cc2 Mon Sep 17 00:00:00 2001 From: nikolayandreev Date: Mon, 22 Feb 2021 16:38:09 +0200 Subject: [PATCH 4/6] Added back getMinimalPrice in AbstractType --- packages/Webkul/Product/src/Type/AbstractType.php | 2 +- packages/Webkul/Product/src/Type/Downloadable.php | 10 ++++++++++ packages/Webkul/Product/src/Type/Simple.php | 10 ++++++++++ packages/Webkul/Product/src/Type/Virtual.php | 10 ++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/Webkul/Product/src/Type/AbstractType.php b/packages/Webkul/Product/src/Type/AbstractType.php index adf2f27b4..460dda2dd 100644 --- a/packages/Webkul/Product/src/Type/AbstractType.php +++ b/packages/Webkul/Product/src/Type/AbstractType.php @@ -536,7 +536,7 @@ abstract class AbstractType */ public function getMaximamPrice() { - return $this->product->price; + return $this->getMinimalPrice(); } /** diff --git a/packages/Webkul/Product/src/Type/Downloadable.php b/packages/Webkul/Product/src/Type/Downloadable.php index d35b2ba69..101df5a8e 100644 --- a/packages/Webkul/Product/src/Type/Downloadable.php +++ b/packages/Webkul/Product/src/Type/Downloadable.php @@ -288,4 +288,14 @@ class Downloadable extends AbstractType return $result; } + + /** + * Get product maximam price + * + * @return float + */ + public function getMaximamPrice() + { + return $this->product->price; + } } diff --git a/packages/Webkul/Product/src/Type/Simple.php b/packages/Webkul/Product/src/Type/Simple.php index 03eb5ccf8..12c25f8cd 100644 --- a/packages/Webkul/Product/src/Type/Simple.php +++ b/packages/Webkul/Product/src/Type/Simple.php @@ -63,4 +63,14 @@ class Simple extends AbstractType return $qty <= $this->totalQuantity() ? true : $backorders; } + + /** + * Get product maximam price + * + * @return float + */ + public function getMaximamPrice() + { + return $this->product->price; + } } \ No newline at end of file diff --git a/packages/Webkul/Product/src/Type/Virtual.php b/packages/Webkul/Product/src/Type/Virtual.php index 50d5fac91..2c19a393e 100644 --- a/packages/Webkul/Product/src/Type/Virtual.php +++ b/packages/Webkul/Product/src/Type/Virtual.php @@ -71,4 +71,14 @@ class Virtual extends AbstractType { return $qty <= $this->totalQuantity() ? true : false; } + + /** + * Get product maximam price + * + * @return float + */ + public function getMaximamPrice() + { + return $this->product->price; + } } \ No newline at end of file From a3523703946fdb84ac67225c5ca575318e2faa07 Mon Sep 17 00:00:00 2001 From: nikolayandreev Date: Mon, 22 Feb 2021 16:39:19 +0200 Subject: [PATCH 5/6] Progress --- packages/Webkul/Product/src/Type/Simple.php | 2 +- packages/Webkul/Product/src/Type/Virtual.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/Webkul/Product/src/Type/Simple.php b/packages/Webkul/Product/src/Type/Simple.php index 12c25f8cd..100b2a228 100644 --- a/packages/Webkul/Product/src/Type/Simple.php +++ b/packages/Webkul/Product/src/Type/Simple.php @@ -73,4 +73,4 @@ class Simple extends AbstractType { return $this->product->price; } -} \ No newline at end of file +} diff --git a/packages/Webkul/Product/src/Type/Virtual.php b/packages/Webkul/Product/src/Type/Virtual.php index 2c19a393e..f8accd9db 100644 --- a/packages/Webkul/Product/src/Type/Virtual.php +++ b/packages/Webkul/Product/src/Type/Virtual.php @@ -81,4 +81,4 @@ class Virtual extends AbstractType { return $this->product->price; } -} \ No newline at end of file +} From 93a5ec7d56b56a970d02246b7de339b050f3bffd Mon Sep 17 00:00:00 2001 From: nikolayandreev Date: Tue, 23 Feb 2021 13:23:22 +0200 Subject: [PATCH 6/6] Revert the parameter rename, but keep new functionality --- .../API/Http/Controllers/Shop/ProductController.php | 2 +- .../Product/src/Repositories/ProductRepository.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/Webkul/API/Http/Controllers/Shop/ProductController.php b/packages/Webkul/API/Http/Controllers/Shop/ProductController.php index 992dc66e6..051982e51 100755 --- a/packages/Webkul/API/Http/Controllers/Shop/ProductController.php +++ b/packages/Webkul/API/Http/Controllers/Shop/ProductController.php @@ -34,7 +34,7 @@ class ProductController extends Controller */ public function index() { - return ProductResource::collection($this->productRepository->getAll(request()->input('categories'))); + return ProductResource::collection($this->productRepository->getAll(request()->input('category_id'))); } /** diff --git a/packages/Webkul/Product/src/Repositories/ProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductRepository.php index 3a686f7e7..4da361477 100755 --- a/packages/Webkul/Product/src/Repositories/ProductRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductRepository.php @@ -129,11 +129,11 @@ class ProductRepository extends Repository } /** - * @param string $categories + * @param string $categoryId * * @return \Illuminate\Support\Collection */ - public function getAll($categories = null) + public function getAll($categoryId = null) { $params = request()->input(); @@ -147,7 +147,7 @@ class ProductRepository extends Repository $page = Paginator::resolveCurrentPage('page'); - $repository = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($params, $categories) { + $repository = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($params, $categoryId) { $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); $locale = request()->get('locale') ?: app()->getLocale(); @@ -161,8 +161,8 @@ class ProductRepository extends Repository ->where('product_flat.locale', $locale) ->whereNotNull('product_flat.url_key'); - if ($categories) { - $qb->whereIn('product_categories.category_id', explode(',', $categories)); + if ($categoryId) { + $qb->whereIn('product_categories.category_id', explode(',', $categoryId)); } if (! core()->getConfigData('catalog.products.homepage.out_of_stock_items')) {