Skip to content

Commit

Permalink
3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjimenez committed Jan 1, 2024
1 parent 4899344 commit 543d97d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion _lib/cms/assets/js/cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function initForms()
url = form.action;
}

if (tinyMCE) {
if (typeof tinyMCE !== 'undefined') {
tinyMCE.triggerSave();
}

Expand Down
2 changes: 1 addition & 1 deletion _lib/cms/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class cms
{
const VERSION = '3.0.2';
const VERSION = '3.1.1';

/**
* @var string
Expand Down
52 changes: 27 additions & 25 deletions _lib/core/shop.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,31 +162,7 @@ public function __construct()

global $request;
if ($request !== 'admin' && $_POST['code'] && table_exists('promo_codes')) {
//lookup discount
$select_code = sql_query("SELECT * FROM promo_codes
WHERE
code='" . escape($_POST['code']) . "' AND
(
expiry>CURDATE() OR
expiry='0000-00-00'
)
");

$errors = [];
if (!$select_code) {
$errors[] = 'code Invalid promo code';
}

//handle validation
if (count($errors)) {
//validateion failed
die(json_encode($errors));
} elseif ($_POST['validate']) {
//validation passed
die('1');
}

$_SESSION['code'] = $_POST['code'];
$this->set_promo($_POST['code']);
}

if ($_POST['update_basket']) {
Expand All @@ -208,6 +184,7 @@ public function __construct()
}
}
}

$this->update_total();
}

Expand Down Expand Up @@ -473,6 +450,31 @@ public function set_delivery($price)

$this->update_total();
}

public function set_promo($code) {
//lookup discount
$promo = sql_query("SELECT * FROM promo_codes
WHERE
code='" . escape($code) . "'
", 1);

$errors = [];
if (!$promo) {
return 'Invalid promo code';
}

if ($promo['expiry'] && strtotime($promo['expiry']) < time()) {
return 'promo has expired';
}

if ($promo['min_spend'] && strtotime($promo['expiry']) < time()) {
return 'min spend for this promo is £' . $promo['min_spend'];
}

$_SESSION['code'] = $code;

return true;
}

public function set_discount($discount)
{
Expand Down

0 comments on commit 543d97d

Please sign in to comment.