From a97107ac23c25cbf24ebf860d84b41d3be0d4454 Mon Sep 17 00:00:00 2001 From: Afaz Khatri Date: Wed, 7 Oct 2020 11:08:10 +0530 Subject: [PATCH 1/5] Added regular/final price to the product resource Added regular and final price to the product resource so that it is much easier to compare between them on the frontend --- packages/Webkul/API/Http/Resources/Catalog/Product.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/Webkul/API/Http/Resources/Catalog/Product.php b/packages/Webkul/API/Http/Resources/Catalog/Product.php index e81a7b872..522b42da9 100644 --- a/packages/Webkul/API/Http/Resources/Catalog/Product.php +++ b/packages/Webkul/API/Http/Resources/Catalog/Product.php @@ -56,6 +56,7 @@ class Product extends JsonResource $product->getTypeInstance()->haveSpecialPrice(), core()->currency($product->getTypeInstance()->getSpecialPrice()) ), + $product->getTypeInstance()->getProductPrices(), 'reviews' => [ 'total' => $total = $this->productReviewHelper->getTotalReviews($product), 'total_rating' => $total ? $this->productReviewHelper->getTotalRating($product) : 0, @@ -67,4 +68,4 @@ class Product extends JsonResource 'updated_at' => $this->updated_at, ]; } -} \ No newline at end of file +} From 2fbbabb604613814cd447522893da2f9a04733df Mon Sep 17 00:00:00 2001 From: Afaz Khatri Date: Thu, 8 Oct 2020 10:16:10 +0530 Subject: [PATCH 2/5] Added key prices to product resource --- packages/Webkul/API/Http/Resources/Catalog/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Webkul/API/Http/Resources/Catalog/Product.php b/packages/Webkul/API/Http/Resources/Catalog/Product.php index 522b42da9..edf0ec0f0 100644 --- a/packages/Webkul/API/Http/Resources/Catalog/Product.php +++ b/packages/Webkul/API/Http/Resources/Catalog/Product.php @@ -56,7 +56,7 @@ class Product extends JsonResource $product->getTypeInstance()->haveSpecialPrice(), core()->currency($product->getTypeInstance()->getSpecialPrice()) ), - $product->getTypeInstance()->getProductPrices(), + 'prices' => $product->getTypeInstance()->getProductPrices(), 'reviews' => [ 'total' => $total = $this->productReviewHelper->getTotalReviews($product), 'total_rating' => $total ? $this->productReviewHelper->getTotalRating($product) : 0, From 95cd8c69020f5e05efd171bb8f25a09ebecee117 Mon Sep 17 00:00:00 2001 From: Afaz Khatri Date: Fri, 9 Oct 2020 20:21:38 +0530 Subject: [PATCH 3/5] Updated the regular price key --- packages/Webkul/API/Http/Resources/Catalog/Product.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/Webkul/API/Http/Resources/Catalog/Product.php b/packages/Webkul/API/Http/Resources/Catalog/Product.php index edf0ec0f0..3414aafdd 100644 --- a/packages/Webkul/API/Http/Resources/Catalog/Product.php +++ b/packages/Webkul/API/Http/Resources/Catalog/Product.php @@ -30,6 +30,8 @@ class Product extends JsonResource public function toArray($request) { $product = $this->product ? $this->product : $this; + + $prices = $product->getTypeInstance()->getProductPrices(); return [ 'id' => $product->id, @@ -56,7 +58,8 @@ class Product extends JsonResource $product->getTypeInstance()->haveSpecialPrice(), core()->currency($product->getTypeInstance()->getSpecialPrice()) ), - 'prices' => $product->getTypeInstance()->getProductPrices(), + 'regular_price' => data_get($prices, 'regular_price.price'), + 'formatted_regular_price' => data_get($prices, 'regular_price.formated_price'), 'reviews' => [ 'total' => $total = $this->productReviewHelper->getTotalReviews($product), 'total_rating' => $total ? $this->productReviewHelper->getTotalRating($product) : 0, From 0940c1751d29e3530c3c7631b52a2019a42d3a49 Mon Sep 17 00:00:00 2001 From: Afaz Khatri Date: Fri, 9 Oct 2020 20:23:03 +0530 Subject: [PATCH 4/5] Updated formated_regular_price key --- packages/Webkul/API/Http/Resources/Catalog/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Webkul/API/Http/Resources/Catalog/Product.php b/packages/Webkul/API/Http/Resources/Catalog/Product.php index 3414aafdd..75ec94c11 100644 --- a/packages/Webkul/API/Http/Resources/Catalog/Product.php +++ b/packages/Webkul/API/Http/Resources/Catalog/Product.php @@ -59,7 +59,7 @@ class Product extends JsonResource core()->currency($product->getTypeInstance()->getSpecialPrice()) ), 'regular_price' => data_get($prices, 'regular_price.price'), - 'formatted_regular_price' => data_get($prices, 'regular_price.formated_price'), + 'formated_regular_price' => data_get($prices, 'regular_price.formated_price'), 'reviews' => [ 'total' => $total = $this->productReviewHelper->getTotalReviews($product), 'total_rating' => $total ? $this->productReviewHelper->getTotalRating($product) : 0, From 71f01ce0b2b1beed60a41a0eb29e1df0e8cddc53 Mon Sep 17 00:00:00 2001 From: Afaz Khatri Date: Sat, 10 Oct 2020 14:11:30 +0530 Subject: [PATCH 5/5] Removed unneccessary space --- packages/Webkul/API/Http/Resources/Catalog/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Webkul/API/Http/Resources/Catalog/Product.php b/packages/Webkul/API/Http/Resources/Catalog/Product.php index 75ec94c11..23f39c351 100644 --- a/packages/Webkul/API/Http/Resources/Catalog/Product.php +++ b/packages/Webkul/API/Http/Resources/Catalog/Product.php @@ -58,7 +58,7 @@ class Product extends JsonResource $product->getTypeInstance()->haveSpecialPrice(), core()->currency($product->getTypeInstance()->getSpecialPrice()) ), - 'regular_price' => data_get($prices, 'regular_price.price'), + 'regular_price' => data_get($prices, 'regular_price.price'), 'formated_regular_price' => data_get($prices, 'regular_price.formated_price'), 'reviews' => [ 'total' => $total = $this->productReviewHelper->getTotalReviews($product),