Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Bozhidar Slaveykov committed Oct 26, 2021
1 parent 047dd93 commit af99004
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
30 changes: 25 additions & 5 deletions src/MicroweberPackages/Cart/CartManager.php
Expand Up @@ -20,6 +20,7 @@ class CartManager extends Crud
public $app;

public $table = 'cart';
public $coupon_data = false;

public function __construct($app = null)
{
Expand All @@ -28,6 +29,14 @@ public function __construct($app = null)
} else {
$this->app = mw();
}

$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
));*/
}

/**
Expand Down Expand Up @@ -178,18 +187,29 @@ public function get_discount()

public function get_discount_type()
{
return $this->app->user_manager->session_get('discount_type');
if (empty( $this->coupon_data)) {
return false;
}

return $this->coupon_data['discount_type'];
}

public function get_discount_value()
{
$discount_value = $this->app->user_manager->session_get('discount_value');

if (empty($discount_value)) {
if (empty( $this->coupon_data)) {
return false;
}

return floatval($discount_value);
$apply_code = false;
if ($this->total() >= $this->coupon_data['total_amount']) {
$apply_code = true;
}

if ($apply_code) {
return floatval( $this->coupon_data['discount_value']);
}

return false;
}

public function get_discount_text()
Expand Down
4 changes: 3 additions & 1 deletion userfiles/modules/shop/coupons/functions.php
Expand Up @@ -238,12 +238,14 @@ function coupon_get_by_code($coupon_code)
{
$table = "cart_coupons";

return db_get($table, array(
$get = db_get($table, array(
'is_active' => 1,
'coupon_code' => $coupon_code,
'single' => true,
'no_cache' => true
));

return $get;
}

api_expose('coupon_delete');
Expand Down

0 comments on commit af99004

Please sign in to comment.