Merge pull request #1405 from prashant-webkul/development

Fixed edge case conditions and a bug in application of couponable rule
This commit is contained in:
Jitendra Singh 2019-09-06 14:59:49 +05:30 committed by GitHub
commit f078762d98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -56,9 +56,9 @@ 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;
$discount = $discount <= $itemPrice * $discQuantity ? $discount : $itemPrice * $discQuantity;
$report['discount'] = $discount;

View File

@ -63,9 +63,15 @@ 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;
$discount = $discount <= $itemPrice * $discQuantity ? $discount : $itemPrice * $discQuantity;
$report['discount'] = $discount;

View File

@ -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;