Fixed edge case conditions and a bug in application of couponable rule
This commit is contained in:
parent
d2e843648d
commit
c9cd73b67e
|
|
@ -56,9 +56,11 @@ class FixedAmount extends Action
|
|||
$report['item_id'] = $item->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;
|
||||
|
||||
|
|
|
|||
|
|
@ -63,9 +63,17 @@ class PercentOfProduct extends Action
|
|||
$report['item_id'] = $item->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;
|
||||
|
||||
|
|
|
|||
|
|
@ -58,16 +58,16 @@ abstract class Discount
|
|||
*/
|
||||
public function getApplicableRules($code = null)
|
||||
{
|
||||
$rules = collect();
|
||||
|
||||
if ($code != null) {
|
||||
$rules = $this->cartRule->findWhere([
|
||||
$eligibleRules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 1,
|
||||
'status' => 1
|
||||
]);
|
||||
|
||||
foreach($rules as $rule) {
|
||||
foreach($eligibleRules as $rule) {
|
||||
if ($rule->coupons->code == $code) {
|
||||
$rules = collect();
|
||||
|
||||
$rules->push($rule);
|
||||
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue