Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-mw committed Feb 19, 2022
1 parent a41f0fd commit 263e4e0
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions userfiles/modules/shop/coupons/src/CouponClass.php
Expand Up @@ -27,15 +27,15 @@ public function __construct($app = null)
$this->app = mw();
}
}

public static function log($coupon_code, $customer_email) {
$customer_ip = $_SERVER['SERVER_ADDR'];

$customer_ip = user_ip();

coupon_log_customer($coupon_code, $customer_email, $customer_ip);

coupons_delete_session();

}

/**
Expand All @@ -51,41 +51,41 @@ public static function calculate_new_price($coupon_code, $total_amount, $custome
$newPrice = 0.00;
$coupon = coupon_get_by_code($coupon_code);
$checkLog = coupon_log_get_by_code_and_customer_id($coupon_code, $customer_id);

if ($checkLog['uses_count'] > $coupon['uses_per_customer']) {
return $total_amount;
}

if (! empty($coupon) && $total_amount >= $coupon['total_amount']) {

if ($coupon['discount_type'] == 'percentage' or $coupon['discount_type'] == 'precentage') {

// Discount with precentage
$newPrice = $total_amount - ($total_amount * ($coupon['discount_value'] / 100));
} else if ($coupon['discount_type'] == 'fixed_amount') {

// Discount with amount
$newPrice = $total_amount - $coupon['discount_value'];
}
} else {
return $total_amount;
}

return $newPrice;
}

public static function calculate_total_price($total_amount, $discount_value, $discount_type)
{
if ($discount_type == 'percentage' or $discount_type == 'precentage') {

// Discount with precentage
$newPrice = $total_amount - ($total_amount * ($discount_value / 100));
} else if ($discount_type == 'fixed_amount') {

// Discount with amount
$newPrice = $total_amount - $discount_value;
}

return $newPrice;
}
}
}

0 comments on commit 263e4e0

Please sign in to comment.