From 89d1cdbe10020f249ddce2b728d5a94094fde910 Mon Sep 17 00:00:00 2001 From: Bozhidar Slaveykov Date: Wed, 27 Oct 2021 10:48:29 +0300 Subject: [PATCH] coupon code fix bugs --- src/MicroweberPackages/Cart/CartManager.php | 17 ++++++----------- userfiles/modules/shop/coupons/functions.php | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/MicroweberPackages/Cart/CartManager.php b/src/MicroweberPackages/Cart/CartManager.php index 04940cc2d43..874e5adeb9a 100644 --- a/src/MicroweberPackages/Cart/CartManager.php +++ b/src/MicroweberPackages/Cart/CartManager.php @@ -31,17 +31,12 @@ public function __construct($app = null) } $coupon_code = $this->app->user_manager->session_get('coupon_code'); - /* $this->coupon_data = db_get("cart_coupons", array( - 'is_active' => 1, - 'coupon_code' => $coupon_code, - 'single' => true, - 'no_cache' => true - ));*/ + $this->coupon_data = coupon_get_by_code($coupon_code); } /** + * This will sum all cart items amount * @param bool $return_amount - * * @return array|false|float|int|mixed */ public function sum($return_amount = true) @@ -187,7 +182,7 @@ public function get_discount() public function get_discount_type() { - if (empty( $this->coupon_data)) { + if (empty($this->coupon_data)) { return false; } @@ -196,17 +191,17 @@ public function get_discount_type() public function get_discount_value() { - if (empty( $this->coupon_data)) { + if (empty($this->coupon_data)) { return false; } $apply_code = false; - if ($this->total() >= $this->coupon_data['total_amount']) { + if ($this->sum() >= $this->coupon_data['total_amount']) { $apply_code = true; } if ($apply_code) { - return floatval( $this->coupon_data['discount_value']); + return floatval($this->coupon_data['discount_value']); } return false; diff --git a/userfiles/modules/shop/coupons/functions.php b/userfiles/modules/shop/coupons/functions.php index 3a456059ff5..fd29cebc339 100644 --- a/userfiles/modules/shop/coupons/functions.php +++ b/userfiles/modules/shop/coupons/functions.php @@ -296,7 +296,7 @@ function coupons_delete_session() print ''; }); - +/* event_bind('mw.shop.cart.init', function ($params) { //register_component($type,$params) @@ -310,6 +310,6 @@ function coupons_delete_session() }); - +*/