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/ |
Upload File : |
<?php
namespace modules\storeVariation;
class main extends \moduleMain {
use \modules\input\traits {
\modules\input\traits::__construct as __ConstructInput;
}
use \modules\database\traits {
\modules\database\traits::__construct as __ConstructDatabase;
}
use \modules\output\traits {
\modules\output\traits::__construct as __ConstructOutput;
}
private $view;
public function __construct() {
parent::__construct(__DIR__);
$this->__ConstructInput();
$this->__ConstructDatabase();
$this->__ConstructOutput();
}
public function Activate() {
hook_add('template.store.product.COL2', [$this, '__column2'], 20); // add Price
hook_add('template.store.productgroup.PG1', [$this, '__addvariation'], 20);
hook_add('template.store.productgroup.PG2', [$this, '__addvariationbutton'], 20);
hook_add('store.product.admin', [$this, '__editmenu']);
$this->view = $GLOBALS['loader']->getView('storeclient_variation', __DIR__);
hook_add('template.product', [$this, '__getData'], 20);
hook_add('template.productgroup', [$this, '__getData_pg'], 20);
hook_add('product.tab', [$this, '__product_tabs'], 10);
hook_add('product.tab.variation', [$this, '__tab_content']);
hook_add('productgroup.save', [$this, 'ProductGroupSave']);
hook_add('product.clone', [$this, '__ProductClone']);
hook_add('product.variation', [$this, '__ProductVariation']);
hook_add('cart.display', [$this, '__AddCartContent']);
hook_add('template.store.cart.COL2', [$this, '__addCartVariation']);
hook_add('template.store.edit.COL2', [$this, '__addCartVariation']);
hook_add('template.store.edit.COL3', [$this, '__editVariationButton']);
hook_add('controller.store.variation', [$this, '__variation'], 20);
hook_add('list.store.variation', [$this, '__variationlist'], 20);
hook_add('event.change.category', [$this, '__categoryChange'] );
hook_add('filter.variation', [$this, '__filter_variation']);
hook_add('store.account.variation', [$this, '__order_variation']);
hook_add('store.tab', [$this, '__settings_tabs50'], 50); // store settings
hook_add('store.tab.variation', [$this, '__settings_variation']);
}
// add Pricing
public function __column2(&$html) {
$text = $this->view->Column2Text();
$this->view->UpdateHTML($html, 'COL2', $text);
}
public function __addvariation(&$html) {
$text = $this->view->store_variation_pg();
$this->view->UpdateHTML($html, 'PG1', $text);
}
public function __addvariationbutton(&$html) {
$text = $this->view->store_variation_button();
$this->view->UpdateHTML($html, 'PG2', $text);
}
public function __editVariationButton(&$html) {
$text = $this->view->store_variation_edit2();
$this->view->UpdateHTML($html, 'COL3', $text);
}
// add variation to a product page on the store
public function __getData(&$res) {
$model_variation = $this->LoadModel('variation_model');
$model_productvariation = $this->LoadModel('productvariation_model');
$product_id = $res['sp_id'];
$model_productvariation->ModelVariation($model_variation)
->ProductId($product_id)
->addHandlebarsProduct($res);
$res['opt_full'] = ($this->settings['singleline'] ?? 'table') ? 1 : 0;
}
public function __getData_pg(&$res) {
$model_productvariation = $this->LoadModel('productvariation_model');
$model_productvariation->GroupId($res['sc_id']);
if ($res['sc_id']) {
$model_productvariation->addHandlebars($res);
$res['showvariation'] = 1;
}
}
public function __editmenu(&$menu) {
// get current product
$product = \Product_model::GetHandle();
$productbase = '/admin/product/' . $product->RecordId();
$menu[] = [
'caption' => 'Variations',
'href' => "$productbase/edit#variation",
'hint' => 'Show and Edit Variations',
];
$menu[] = [
'caption' => 'Add Variation',
'href' => "$productbase/variation_new",
'hint' => 'New Variation',
];
}
public function __product_tabs(&$tabs, $uri) {
//** TO DO: this tab will be empty if the product does not have any variations
$node = [
'name' => 'Variation',
'icon' => '<i class="fas fa-list-ul"></i>',
'fragment' => 'variation',
'className' => '',
];
$tabs['_tab'][] = $node;
}
public function ProductGroupSave(&$result, $id, $post) {
$model_variation = $this->LoadModel('variation_model');
$model_variation->ProductGroupSave($result, $id, $post);
}
public function __tab_content(&$data, $ephemeral) {
$product_id = $ephemeral['product_id'];
$data = hook_execute('execute.internal', NULL, '/admin/product-variations/' . $product_id . '/tab-variation');
}
public function __ProductClone($param) {
$model_variation = $this->LoadModel('variation_model');
$variation_tag = $param['vargroup'];
if (empty($variation_tag)) { // assign a new variation tag, also update the source record
$variation_tag = $model_variation->getNextVariationTag();
$model_variation->setVariationTag($param['source'], $variation_tag);
$model_variation->setVariationTag($param['target'], $variation_tag);
}
$model_productvariation = $this->LoadModel('productvariation_model');
$model_productvariation->ModelVariation($model_variation)
->ProductId($param['source'])
->CloneProduct($param);
}
// return the product id of the newly selected product id
public function __ProductVariation(&$intercepted, $data) {
if ($intercepted === FALSE) {
$model_variation = $this->LoadModel('variation_model');
$model_productvariation = $this->LoadModel('productvariation_model');
$intercepted = $model_productvariation
->ModelVariation($model_variation)
->VariationGroup($data['spv'])
->locateVariation($_POST);
}
}
public function __AddCartContent(&$data, $tag = '') {
$model = $this->LoadModel('productvariation_model');
$model->AddCartContent($data, $tag);
}
public function __addCartVariation(&$html) {
$text = $this->view->cart_variation();
$this->view->UpdateHTML($html, 'COL2', $text);
}
public function __variation(&$res, $auth) {
$isPost = $this->method() == 'POST';
$variation_id = hook_execute( 'nonce.verify', FALSE, 'variation', FALSE, $auth );
if ($variation_id === FALSE) {
return $res = [
'result' => -2,
'message' => 'You do not have permission to access this function',
];
}
$model_variation = $this->LoadModel('variation_model');
$model_variation->VariationId($variation_id);
if ($isPost) {
$model_variation->saveDetails($this->post());
$variation_id = $model_variation->VariationId();
$model_variation->saveOptions($this->post());
$auth = hook_execute('nonce.create', FALSE, 'variation', $variation_id, 1800);
$this->Redirect('/admin/product-variation?auth=' . $auth);
}
$data = $model_variation->AsHandlebars2();
$res['auth'] = hook_execute('nonce.create', FALSE, 'variation', $variation_id, 1800);
$res['template'] = 'store_variation_edit';
$res = array_merge($res, $data);
}
public function __variationlist(&$res) {
$model_variation = $this->LoadModel('variation_model');
$rep = new \ReportObject;
hook_execute('variation.field.list', $rep);
$res = $model_variation->VariationList($rep, TRUE);
}
public function __categoryChange() {
$model = $this->LoadModel('productvariation_model');
$model->categoryChange();
}
public function __filter_variation(&$param) {
if (empty($param)) {
$param = [];
$param[] = [ 'key' => '', 'value' => '(select a variation)' ];
}
$model_variation = $this->LoadModel('variation_model');
$info = $model_variation->VariationList(NULL, TRUE);
$param = array_merge($param, $info);
}
public function __order_variation(&$res, $line_id, $isPost) {
$model_order = $this->LoadModel('order_model', 'store');
$row = $model_order->LoadOrderByLine($line_id); // load the order by line_id
if (!is_null($row)) {
$model_productvariation = $this->LoadModel('productvariation_model');
$product_id = $row->sod_product;
if ($isPost) {
// on save: update edited date/time
// return to order page
$product = $this->post('product');
$model_product = $this->LoadModel('product_model', 'store');
$model_product->RecordId($product);
$this->TableName('store_order_detail')
->InsertOrUpdate([
'sod_id' => $line_id,
], [
'sod_product' => $product,
'sod_description' => $model_product->AsCaption(),
]);
// update order edited date
$model_order->EditDate(time())
->Update();
// send email
$res['result'] = -9999;
$res['message'] = 'This change has been requested. Check your email for further details.';
$res['refresh-page'] = 1; // special for internal use
return;
}
// get all the products with the same variation (based on each having the same price)
$list_variations = $model_productvariation
->ProductId($product_id)
->getProductVariations();
foreach($list_variations as &$var) {
unset($var['variation'], $var['hash']);
}
// what is the name of the Variation that will change?
// generate variation change popup
$res['popup'] = [
'template' => 'storevar_color_edit',
'width' => 850,
'maxWidth' => '100%',
'modal' => TRUE,
'title' => 'Select Replacement Color',
'class' => 'variation-dialog',
'product' => $product_id,
'list_product' => $list_variations,
'ordernum' => $model_order->OrderNumber(),
'auth' => hook_execute('nonce.create', FALSE, 'line.id', $line_id, 1800),
'actions' => [
[
'action' => 'update',
'text' => 'Update Order',
]
],
];
}
}
public function __settings_tabs50(&$tabs, $uri) {
$tabs['_tab'][] = [
'name' => 'Variations',
'icon' => '<i class="fas fa-globe-americas"></i>',
'fragment' => 'variation',
'className' => '',
];
}
public function __settings_variation(&$data, $ephemeral) {
$data = hook_execute('execute.internal', NULL, '/admin/store-variation');
}
}