Fixed edge case conditions and a bug in application of couponable rule

This commit is contained in:
Prashant Singh 2019-09-06 13:38:05 +05:30
parent d2e843648d
commit c9cd73b67e
3 changed files with 18 additions and 8 deletions

View File

@ -56,9 +56,11 @@ class FixedAmount extends Action
$report['item_id'] = $item->id; $report['item_id'] = $item->id;
$report['product_id'] = $item->child ? $item->child->product_id : $item->product_id; $report['product_id'] = $item->child ? $item->child->product_id : $item->product_id;
$discount = round($itemPrice * $discQuantity, 4); $discount = round($itemPrice * $discQuantity, 4) * $discQuantity;
$discount = $discount <= $itemPrice ? $discount : $itemPrice; if ($rule->action_type == 'fixed_amount') {
$discount = $discount <= $itemPrice ? $discount : $itemPrice;
}
$report['discount'] = $discount; $report['discount'] = $discount;

View File

@ -63,9 +63,17 @@ class PercentOfProduct extends Action
$report['item_id'] = $item->id; $report['item_id'] = $item->id;
$report['product_id'] = $item->child ? $item->child->product_id : $item->product_id; $report['product_id'] = $item->child ? $item->child->product_id : $item->product_id;
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4); if ($rule->disc_amount > 100) {
$discount_amount = 100;
} else {
$discount_amount = 100;
}
$discount = $discount <= $itemPrice ? $discount : $itemPrice; $discount = round(($itemPrice * $discount_amount) / 100, 4) * $discQuantity;
if ($rule->action_type == 'percent_of_product') {
$discount = $discount <= $itemPrice ? $discount : $itemPrice;
}
$report['discount'] = $discount; $report['discount'] = $discount;

View File

@ -58,16 +58,16 @@ abstract class Discount
*/ */
public function getApplicableRules($code = null) public function getApplicableRules($code = null)
{ {
$rules = collect();
if ($code != null) { if ($code != null) {
$rules = $this->cartRule->findWhere([ $eligibleRules = $this->cartRule->findWhere([
'use_coupon' => 1, 'use_coupon' => 1,
'status' => 1 'status' => 1
]); ]);
foreach($rules as $rule) { foreach($eligibleRules as $rule) {
if ($rule->coupons->code == $code) { if ($rule->coupons->code == $code) {
$rules = collect();
$rules->push($rule); $rules->push($rule);
break; break;