From cf5cc40acb076f92bcdcc4a23d1c293943e72a00 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Thu, 22 Aug 2019 16:03:08 +0530 Subject: [PATCH] Normalized cart action rules --- .../Discount/src/Actions/Cart/FixedAmount.php | 8 +++++++- .../src/Actions/Cart/PercentOfProduct.php | 8 +++++++- .../src/Actions/Cart/WholeCartToPercent.php | 16 ++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/Webkul/Discount/src/Actions/Cart/FixedAmount.php b/packages/Webkul/Discount/src/Actions/Cart/FixedAmount.php index 515c65096..a8a76352c 100644 --- a/packages/Webkul/Discount/src/Actions/Cart/FixedAmount.php +++ b/packages/Webkul/Discount/src/Actions/Cart/FixedAmount.php @@ -92,7 +92,13 @@ class FixedAmount extends Action $report['item_id'] = $item->id; $report['product_id'] = $item->child ? $item->child->product_id : $item->product_id; - $report['discount'] = $discount; + + if ($discount <= $itemPrice) { + $report['discount'] = $discount; + } else { + $report['discount'] = $itemPrice; + } + $report['formatted_discount'] = core()->currency($discount); $impact->push($report); diff --git a/packages/Webkul/Discount/src/Actions/Cart/PercentOfProduct.php b/packages/Webkul/Discount/src/Actions/Cart/PercentOfProduct.php index 74c9fa10c..1ad74a6c8 100644 --- a/packages/Webkul/Discount/src/Actions/Cart/PercentOfProduct.php +++ b/packages/Webkul/Discount/src/Actions/Cart/PercentOfProduct.php @@ -100,7 +100,13 @@ class PercentOfProduct extends Action $report['item_id'] = $item->id; $report['product_id'] = $item->child ? $item->child->product_id : $item->product_id; - $report['discount'] = $discount; + + if ($discount <= $itemPrice) { + $report['discount'] = $discount; + } else { + $report['discount'] = $itemPrice; + } + $report['formatted_discount'] = core()->currency($discount); $impact->push($report); diff --git a/packages/Webkul/Discount/src/Actions/Cart/WholeCartToPercent.php b/packages/Webkul/Discount/src/Actions/Cart/WholeCartToPercent.php index 40b764d8b..60037f191 100644 --- a/packages/Webkul/Discount/src/Actions/Cart/WholeCartToPercent.php +++ b/packages/Webkul/Discount/src/Actions/Cart/WholeCartToPercent.php @@ -54,7 +54,13 @@ class WholeCartToPercent extends Action $report['item_id'] = $item->id; $report['product_id'] = $item->child ? $item->child->product_id : $item->product_id; - $report['discount'] = $discount; + + if ($discount <= $itemPrice) { + $report['discount'] = $discount; + } else { + $report['discount'] = $itemPrice; + } + $report['formatted_discount'] = core()->currency(round($discount, 4)); $impact->push($report); @@ -77,7 +83,13 @@ class WholeCartToPercent extends Action $report['item_id'] = $item->id; $report['product_id'] = $item->child ? $item->child->product_id : $item->product_id; - $report['discount'] = $discount; + + if ($discount <= $itemPrice) { + $report['discount'] = $discount; + } else { + $report['discount'] = $itemPrice; + } + $report['formatted_discount'] = core()->currency(round($discount, 4)); $impact->push($report);