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/kjvdictionary_store/modules/store/ |
Upload File : |
<?php
namespace modules\store;
use \Pelago\Emogrifier\CssInliner;
/*
uses /usr/local/bin/weasyprint to create pdf:
pip3 install weasyprint
pip3 install --force-reinstall -v "pydyf==0.10.0"
*/
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;
}
use \modules\config\traits {
\modules\config\traits::__construct as __ConstructConfig;
}
private $level;
private $user_id;
private $view;
public function __construct() {
parent::__construct(__DIR__);
$this->__ConstructConfig();
$this->__ConstructInput();
$this->__ConstructDatabase();
$this->__ConstructOutput();
$this->level = isset($_SESSION['current_user']) ? $_SESSION['current_user']['u_level'] : 0;
$this->user_id = isset($_SESSION['current_user']) ? (int) $_SESSION['current_user']['u_id'] : 0;
$temp = $_SESSION['unverified'] ?? 0;
if (!$this->user_id && $temp) $this->user_id = $temp;
}
public function Activate() {
hook_add('uri', [$this, '__homepage'], 1);
hook_add('html.prepare', [$this, '__head']);
hook_add('html.head', [$this, '__meta'], 10);
hook_add('template.store.product.COL1', [$this, '__column1'], 10); // add About
hook_add('template.store.product.COL2', [$this, '__column2'], 10); // add Price
hook_add('template.store.product.COL2', [$this, '__addcart'], 90); // Add to Cart (also maybe add Edit links)
hook_add('template.store.fulfill.COL1', [$this, '__column1_fulfill']); // provide order-processing actions - eg packing slip
hook_add('template.store.cart.COL4', [$this, '__column4']); // Proceed to Checkout
hook_add('product.tab', [$this, '__product_tabs'], 1); // essential product deets
hook_add('product.tab.general', [$this, '__tab_content']);
hook_add('product.tab.stock', [$this, '__tab_content_stock']);
hook_add('product.tab.feature', [$this, '__tab_content_feature']);
hook_add('product.overlay', [$this, '__product_overlay']);
hook_add('store.currency', [$this, '__getCurrency'], 1);
hook_add('order.json.full', [$this, '__order_json']); // return the json for the full checkout page, open at first non-readonly tab
hook_add('order.json.delivery', [$this, '__order_json_delivery']); // return the json for the delivery panel on checkout page
hook_add('order.json.freight', [$this, '__order_json_freight']);
hook_add('order.update', [$this, '__order_update']); // add an address to an order, or a user_id, or status
hook_add('order.update.account', [$this, '__order_update_account']);
hook_add('order.update.delivery', [$this, '__order_update_delivery']);
hook_add('order.update.freight', [$this, '__order_update_freight']);
hook_add('order.update.confirm', [$this, '__order_update_confirm'], 10); // confirm the order - check terms accepted. should be first
hook_add('order.update.confirm', [$this, '__order_update_confirm2'], 90); // send out email, change order status etc. should be last
hook_add('order.list', [$this, '__order_list'], 10); // create a list of recent orders
hook_add('cart.update', [$this, '__updatecart'], 60); // duplicate customization, if specified
hook_add('menu.admin', [$this, '__admin_menu'], 1);
hook_add('menu.menu2', [$this, '__carticon'], 70);
hook_add('account.address.list', [$this, '__account_address_list']);
hook_add('account.address.set-default', [$this, '__account_address_setdefault']);
hook_add('logout', [$this, '__logout'], 99); // clear out session/cart
hook_add('url.key.select', [$this, '__module_select'], 10);
hook_add('url.key.expand', [$this, '__key']); // go to product/category/page or url
hook_add('register.packingslip', [$this, '__packingslip_register'], 1); // the default packing slip
hook_add('register.packingslip', [$this, '__packingslip_register2'], 1); // generic blue theme
hook_add('cart.display', [$this, '__AddCartContent']);
hook_add('fulfillment.tab', [$this, '__fulfillment_tabs'], 1); // must be priority 1
hook_add('fulfillment.tab.new', [$this, '__fulfillment_new']);
hook_add('fulfillment.tab.transit', [$this, '__fulfillment_transit']);
hook_add('fulfillment.tab.complete', [$this, '__fulfillment_complete']);
hook_add('store.tab', [$this, '__settings_tabs'], 1); // must be priority 1
hook_add('store.tab', [$this, '__settings_tabs30'], 30); // category
hook_add('store.tab', [$this, '__settings_tabs60'], 60); // manufacturers
hook_add('store.tab.category', [$this, '__settings_category']);
hook_add('store.tab.manufacturer', [$this, '__settings_manufacturer']);
hook_add('product.list', [$this, 'listActiveProducts']);
hook_add('output.errordetail', [$this, '__snafu']);
$this->view = $GLOBALS['loader']->getView('storeclient_view', __DIR__);
hook_add('output.sitemap', [$this, '__sitemap']);
$this->link('/home/sitemap-store.xml', [$this, '__sitemap_store']);
$event = new \Schedule();
$event ->hourly(55)
->execute([$this, 'crontab_cleanup']);
hook_add('cron', $event);
}
public function __AddCartContent(&$data, $tag = '') {
if ($tag == 'edit') {
foreach($data['cart'] as &$item) {
$item['auth'] = hook_execute('nonce.create', FALSE, 'line.id', $item['id'], 3600);
}
}
}
// clear out cart
public function __logout() {
unset($_SESSION['store_cart'], $_SESSION['order'], $_SESSION['freight'], $_SESSION['confirmation'], $_SESSION['store_changed'], $_SESSION['unverified'], $_SESSION['unverified_addr']);
}
// intercept home page
public function __homepage(&$uri, $__INPUT, $__OUTPUT) {
$myuri = $uri;
if (($p = strpos($myuri, '?')) !== FALSE) {
$param = substr($myuri, $p);
$myuri = substr($myuri, 0, $p);
} else {
$param = '';
}
$elements = explode('/', trim($myuri, '/'));
$action = $elements[1] ?? '';
$record_id = $elements[2] ?? '#';
if (is_numeric($record_id)) {
switch($action) {
case 'p':
$uri = '/store/product/' . $elements[0] . '/'. $record_id;
break;
case 'c':
$uri = '/store/category/' . $elements[0] . '/' . $record_id;
break;
}
}
if (substr($elements[0] ?? '', 0, 1) == '!') {
$sku = strtolower(substr($elements[0], 1));
$uri = '/store/sku/' . $sku;
} elseif ($myuri == '/' ) { // && $this->level > 0
$temp = $this->getHomePage($uri);
if ($temp === FALSE) { // if still missing - "no products set up" error page
// $this->Redirect('/store/snafu/1');
}
if ($temp !== FALSE) {
$uri = hook_execute('url.key.expand', $temp); // expand short key to full uri
if ($uri != '' && $uri != '/' && substr($uri, 0, 7) != '/store/' && substr($uri, 0, 7) != '/pages/') $this->Redirect($uri);
}
}
}
private function getHomePage($uri) {
$temp = hook_execute('url.store.homepage', ''); // get page from submodule
if ($temp == '') {
$temp = $this->settings['homepage']; // if missing get store homepage
}
if (substr($temp, 0, 2) == 'x:') { // first product, or snafu page
$model = $this->LoadModel('product_model');
$temp = $model->getFirstProductPage();
if ($temp === FALSE) { // if still missing - "no products set up" error page
$this->Redirect('/store/snafu/1');
} else {
$uri = hook_execute('url.key.expand', $temp);
}
}
return ($temp == '') ? FALSE : hook_execute('url.key.expand', $temp);
}
// rewrite a special page to a uri
public function __key(&$key) {
if (preg_match('~^(.*?)\:(\d+)$~', $key, $match)) {
switch($match[1]) {
case 'prod':
$model = $this->LoadModel('product_model');
$model->RecordId($match[2]);
$key = $model->uri();
// header('Content-type: text/plain');
// header("Location: $uri", TRUE, 302);
//exit;
break;
case 'cat':
$model = $this->LoadModel('productgroup_model');
$model->RecordId($match[2]);
$key = $model->uri();
break;
}
}
}
public function __product_tabs(&$tabs, $uri) {
$product = \Product_model::GetHandle();
$node = [
'name' => 'General',
'icon' => '<i class="fas fa-globe"></i>',
'fragment' => 'general',
'className' => '',
];
$tabs['_tab'][] = $node;
$node = [
'name' => 'Stock',
'icon' => '<i class="fas fa-globe"></i>',
'fragment' => 'stock',
'className' => '',
];
$tabs['_tab'][] = $node;
$node = [
'name' => 'Feature',
'icon' => '<i class="fas fa-star-of-life"></i>',
'fragment' => 'feature',
'className' => '',
];
$tabs['_tab'][] = $node;
$tabs['product_id'] = $product->RecordId();
}
public function __head(&$modulemain) {
$base = $modulemain->StaticUriModule(__DIR__);
$modulemain->IncludeFile($base . '/splide.min.css');
$modulemain->IncludeFile($base . '/splide.min.js')
->depends('jquery');
// $modulemain->IncludeFile($base . '/imageViewer.min.js', 'imageview');
$modulemain->IncludeFile($base . '/imageViewer.js', 'imageview');
$modulemain->IncludeFile($base . '/store.js')
->depends('imageview');
$modulemain->IncludeFile($base . '/store.css');
}
// add About
public function __column1(&$html) {
$text = $this->view->Column1Text();
$this->view->UpdateHTML($html, 'COL1', $text);
}
// add Pricing
public function __column2(&$html) {
$text = $this->view->Column2Text();
$this->view->UpdateHTML($html, 'COL2', $text);
}
// add packing slip
public function __column1_fulfill(&$html) {
$text = $this->view->Column1Text_fulfill();
$this->view->UpdateHTML($html, 'COL1', $text);
}
// add "Proceed to Checkout"
public function __column4(&$html) {
$text = $this->view->Column4Text_checkout();
$this->view->UpdateHTML($html, 'COL4', $text);
}
public function __addcart(&$html) {
// get current product
$product = \Product_model::GetHandle();
$productbase = '/admin/product/' . $product->RecordId();
$text = $this->view->Column2AddToCart();
$this->view->UpdateHTML($html, 'COL2', $text);
if ($this->level >= 10) {
$menu = [];
$menu[] = [
'caption' => 'Edit',
'href' => "$productbase/edit#general",
'hint' => 'Edit this Item',
];
$menu = hook_execute('store.product.admin', $menu);
$text = $this->view->AsMenu($menu);
$this->view->UpdateHTML($html, 'COL2', $text);
}
}
public function __tab_content(&$data, $ephemeral) {
$product_id = $ephemeral['product_id'];
$data = hook_execute('execute.internal', NULL, '/admin/product/' . $product_id . '/tab-general');
}
public function __tab_content_stock(&$data, $ephemeral) {
$product_id = $ephemeral['product_id'];
$data = hook_execute('execute.internal', NULL, '/admin/product/' . $product_id . '/tab-stock');
}
public function __tab_content_feature(&$data, $ephemeral) {
$product_id = $ephemeral['product_id'];
$data = hook_execute('execute.internal', NULL, '/admin/product/' . $product_id . '/tab-feature');
}
public function __account_address_list(&$res, $user_id) {
$model_address = $this->LoadModel('address_model');
$model_address->UserId($user_id);
$res = $model_address->asHandleBars();
// add current default address
$res['blah'] = $this->settings['default_address'] ?? '';
}
public function __account_address_setdefault(&$res, $user_id, $default) {
$changed_items = ['default_address' => $default];
hook_execute('config.set', $changed_items, 'store');
$res = [
'result' => -9999,
'message' => 'default address set',
];
}
public function __admin_menu(&$menu) {
$menu[] = [
'caption' => 'Products',
'href' => '/admin/product',
'hint' => 'Product Maintenance',
'icon' => '<i class="fas fa-tags"></i>',
's' => 0
];
$menu[] = [
'caption' => 'Order Fulfillment',
'href' => '/admin/fulfillment#new',
'hint' => 'Process Orders',
'icon' => '<i class="fas fa-receipt"></i>',
's' => 0
];
$menu[] = [
'caption' => 'Store Maintenance',
'href' => '/admin/store',
'hint' => 'Various Store Settings',
'icon' => '<i class="fas fa-cash-register"></i>',
's' => 0
];
}
public function __carticon(&$menu) {
// how many items in the cart?
$model_cart = $this->LoadModel('cart_model');
$icon = $model_cart->generateCartIcon();
$menu[] = [
'caption' => 'Cart',
'href' => '/store/cart',
's' => 0,
'icon' => $icon,
'hint' => 'View Shopping Cart'
];
// checkout icon
$icon = $model_cart->generateCheckoutIcon();
$menu[] = [
'caption' => 'Checkout',
'href' => '/store/checkout',
's' => 0,
'icon' => $icon,
];
}
// add current product details - upc, sku, etc
public function __product_overlay(&$items) {
$model_product = $this->LoadModel('product_model');
$model_product->productOverlay($items);
}
public function __order_update(&$param) {
$model_order = $this->LoadModel('order_model');
$model_address = $this->LoadModel('address_model');
$model_order->ModelAddress($model_address)
->OrderId($param->order_id)
->updateOrder($param);
}
public function __order_json(&$res, $order_id, $u_id) {
$model_order = $this->LoadModel('order_model');
$model_address = $this->LoadModel('address_model');
$model_cart = $this->LoadModel('cart_model');
$model_order->ModelAddress($model_address)
->OrderId($order_id);
$res['template'] = 'store_checkout';
$res['list_country'] = hook_execute('geoip.list', NULL);
if (!$this->level) {
// generate login buttons
$bounce = $this->request_uri();
$res['list_login'] = $model_cart->getLoginHandlers($bounce);
$model_order->updateOrderAccount($res, 0, '', ''); // get deets from order record
} else {
$model_user = $this->LoadModel('user_model', 'pkpCore');
[ $name, $email, $postcode, $country ] = $model_user->getUserInfo($u_id);
$model_order->updateOrderAccount($res, $u_id, $name, $email);
}
$data = $model_address->AsHandleBars();
$res = array_merge($res, $data);
$data = $model_cart->AsHandleBars_Checkout();
$res = array_merge($res, $data);
$data = $model_order->AsHandleBars(TRUE);
$res = array_merge($res, $data);
if (empty($res['default'])) $res['default'] = $settings['default_address'] ?? '';
$data = $model_order->AsHandleBars_Freight([ 'freight' => $res['freight'] ]);
$res = array_merge($res, $data);
}
public function __order_json_delivery(&$res, $order_id) {
$model_order = $this->LoadModel('order_model');
$model_address = $this->LoadModel('address_model');
$model_cart = $this->LoadModel('cart_model');
$model_order->ModelAddress($model_address)
->OrderId($order_id);
$temp_id = $_SESSION['unverified'] ?? 0;
$temp_addr = $_SESSION['unverified_addr'] ?? FALSE;
if ($temp_id && $temp_addr) {
$model_address->UserId($temp_id);
$data = $model_address->asJson($temp_addr);
$data['single'] = 1;
} else {
$data = $model_address->AsHandleBars();
}
$data['html'][] = [
'field' => 'panel_delivery',
'template' => 'store_panel',
];
$res = array_merge($res, $data);
$res['list_country'] = hook_execute('geoip.list', NULL); // country list required when only a single address is being displayed
$res['default'] = $model_order->Delivery();
}
public function __order_json_freight(&$res, $order_id) {
$model_order = $this->LoadModel('order_model');
$model_address = $this->LoadModel('address_model');
$model_order->ModelAddress($model_address)
->OrderId($order_id);
$data = $model_order->AsHandleBars_Freight();
$data['html'][] = [
'field' => 'panel_freight',
'template' => 'store_panel_freight',
];
$res = array_merge($res, $data);
}
// get list of verified sources based on email
function _userByEmail($email) {
$rows = $this->Query('select us_source, us_user_id from users_source')
->Where('verified=1')
->Where('email=%s', $email)
->Get();
foreach($rows as $row) {
switch($row->us_source) {
case 'internal':
return [$row->us_user_id, 'An account with this email address already exists. Please log in first.'];
case 'google':
return [$row->us_user_id, 'An account with this email address already exists. Please sign in with Google first.'];
case 'paypal':
return [$row->us_user_id, 'An account with this email address already exists. Please log in using Paypal first.'];
default:
return [$row->us_user_id, 'An account with this email address already exists.'];
}
}
return [0, ''];
}
public function __order_update_account(&$res, $order_id, $post, &$settings) {
if (empty($post['ro_account'])) {
$name = trim($post['ac_name']);
$email = trim($post['ac_email']);
if ($name == '' || $email == '') {
$res['result'] = 51068;
$res['message'] = 'Please enter your Name and Email address.';
return;
}
$data = hook_execute('email.validate', [], $email);
if (count($data)) {
$message = array_shift($data);
// hilight email field
$res['result'] = 51069;
$res['message'] = $message;
return;
}
// look up account number by email, make sure it is the same account
//$this->user_id
$info = $this->_userByEmail(strtolower($email));
$user_id = isset($_SESSION['current_user']) ? (int) $_SESSION['current_user']['u_id'] : 0;
$temp = $_SESSION['unverified'] ?? 0;
if (!$user_id && $temp) $user_id = $temp;
if ($info[1] != '' && $user_id != $info[0]) {
$res['result'] = 51070;
$res['message'] = $info;
return;
}
// save the name and email in the order
$model_order = $this->LoadModel('order_model');
$model_order->OrderId($order_id)
->setUserInfo($this->user_id, $name, $email);
}
}
public function __order_update_delivery(&$res, $order_id, $post, &$settings) {
if (empty($post['ro_address'])) {
$model_order = $this->LoadModel('order_model');
$model_address = $this->LoadModel('address_model');
$model_order->ModelAddress($model_address)
->OrderId($order_id);
$single = !empty($post['type']);
if ($single) {
if (!$this->user_id) {
$this->user_id = $model_order->AssignToTempUser();
$model_address->UserId($this->user_id);
$model_order->UserId($this->user_id)
->Update();
}
$guid = $model_address->onBlur($post);
if (is_string($guid)) {
$default = !empty($post['default']);
if ($default) {
// update user setting
$settings['default_address'] = $guid;
$changed_items = ['default_address' => $guid];
hook_execute('config.set', $changed_items, 'store');
}
$details = $model_address->asJson($guid); // save the single address in the database
$model_order->updateOrderDelivery($details);
$temp_id = $_SESSION['unverified'] ?? 0;
if ($temp_id) $_SESSION['unverified_addr'] = $guid;
// update the Delivery Tab
$data = [
'html' => [
'field' => 'panel_delivery',
'template' => 'store_panel',
],
'default' => $settings['default_address'] ?? '',
];
$res = array_merge($res, $data);
} else {
$res = array_merge($res, $guid); // required fields missing
}
$data = $model_address->AsHandleBars();
$res = array_merge($res, $data);
if (empty($_POST['nexttab'])) $_POST['nexttab'] = 'freight';
} else { // select from a list
$guid = $post['address'] ?? '';
if ($guid != '') {
$details = $model_address->asJson($guid);
$model_order->updateOrderDelivery($details);
}
}
}
}
public function __order_update_freight(&$res, $order_id, $post, &$settings) {
$freight = $post['freight'] ?? '';
$model_order = $this->LoadModel('order_model');
$model_order ->OrderId($order_id)
->updateOrderFreight($freight);
}
public function __order_update_confirm(&$res, $order_id, $post, &$settings) {
$agree = empty($post['o_terms']) ? 0 : 1;
if (!$agree) {
$res['result'] = 51067;
$res['message'] = 'You must agree to our Terms and Conditions';
return;
}
}
public function __order_update_confirm2(&$res, $order_id, $post, &$settings) {
$model_order = $this->LoadModel('order_model');
$model_address = $this->LoadModel('address_model');
$ordernum = $model_order->ModelAddress($model_address)
->HostName($this->hostname(TRUE))
->OrderId($order_id)
->orderConfirm();
if ($ordernum == '') {
$this->Redirect('/store/snafu/5'); // error processing order
}
// this will be moved to the newsletter module
$signup = !empty($post['o_newsletter']);
// signup for newsletter
// clear session cookie
unset($_SESSION['store_cart'], $_SESSION['order'], $_SESSION['freight'], $_SESSION['store_changed']);
$auth = hook_execute('nonce.create', FALSE, 'store.u', $this->user_id, 86400);
$_SESSION['confirmation'] = $auth;
session_write_close();
// redirect to confirmation page
$res['redirect'] = '/store/confirmation/' . $ordernum;
}
public function __order_list(&$data, $user_id = 0, $daycount = 30) {
if ($user_id) {
$model_product = $this->LoadModel('product_model');
$model_order = $this->LoadModel('order_model');
$model_address = $this->LoadModel('address_model');
$model_tracking = $this->LoadModel('tracking_model');
$data = $model_order->ModelAddress($model_address)
->UserId($user_id)
->getUserOrders($daycount);
$model_tracking->mergeTracking($data);
}
}
final function test($ordernum = '') { // nnn-nnnnnnnn
// die("\nFeature disabled");
header('Content-type: text/html; charset=utf-8');
// generate packing slip
$ordernum = '016-02105256';
// $ordernum = '016-07753200';
$model_order = $this->LoadModel('order_model');
$model_order->OrderNumber($ordernum)
->HostName($this->hostname(TRUE));
$specified_template = $this->settings['packingslip'] ?? '';
$specified_template = '2c9f809b76bf46cf179062924a2e0852';
$html = $model_order->generateFinalPackingSlip($specified_template);
die($html);
/*
// process the order
// https://theyoungdesigners.com/~/store/test/008-26329823
header('Content-type: text/plain');
$model_order = $this->LoadModel('order_model');
$model_address = $this->LoadModel('address_model');
$model_order->ModelAddress($model_address);
// ->rebuild_orders();
if ($ordernum != '') {
$model_order->OrderNumber($ordernum)
->HostName($this->hostname(TRUE));
$model_order->orderConfirm(TRUE);
}
die("\nDone");
*/
}
public function __module_select(&$param, $default = '') {
if (is_null($param)) $param = [];
if (!count($param)) {
if ($default == '') $default = '(please select store homepage)';
$param[] = [
'key' => '',
'value' => $default,
];
}
// add products
$param[] = [
'key' => 'x:0',
'value' => '(display first product, or error page if none)', // this is default/test page
];
$model = $this->LoadModel('product_model');
$items = $model->generateSelect();
$param = array_merge($param, $items);
// add categories
$model = $this->LoadModel('productgroup_model');
$items = $model->generateSelect();
$param = array_merge($param, $items);
}
// this will take the settings from the old product and update the new product
public function __updatecart($param) {
$newguid = $param->guid ?? '';
if ($param->custom && $newguid != '') { // custom = oldguid
$row = $this->Query('select * from `store_order_custom`')
->Where('soc_guid=%s', $param->custom)
->First();
$this->TableName('store_order_custom')
->InsertOrUpdate([
'soc_guid' => $newguid,
],[
'soc_type' => $row->soc_type,
'soc_content' => $row->soc_content,
]);
}
}
final function crontab_cleanup() {
$inCron = hook_execute('crontab.running', FALSE);
$cutoff = time() - 43200;
$this->Query('delete from `store_order_custom`')
->Where('soc_order=%d', 0)
->Where('soc_modified<%s', gmdate('Y-m-d H:i', $cutoff))
->Get();
$sql = <<<BLOCK
SELECT so_order FROM `store_order`
left join store_order_detail on so_order=sod_order
BLOCK;
$rows = $this->Query($sql)
->Where('sod_id is null')
->Where('so_status = %s', 'draft')
->Where('so_date < %d', $cutoff)
->Get();
$orders = [];
foreach($rows as $row) {
$orders[] = $row->so_order;
}
$this->Query('delete from `store_order`')
->WhereIn('so_order', $orders)
->Get();
if ($inCron) return;
die("\nDone\n");
}
// used in html to pdf
final function packingslip($ordernum, $action = '') {
$model_order = $this->LoadModel('order_model');
$model_order->OrderNumber($ordernum)
->HostName($this->hostname(TRUE));
if ($action == 'view') {
$order_id = hook_execute( 'nonce.verify', FALSE, 'pslip', FALSE, $this->param('auth', '') );
if ($order_id !== FALSE) {
$model_order->OrderId($order_id);
$model_order->downloadPackingSlip();
}
exit;
}
header('Content-type: text/html; charset=utf-8');
$model_order = $this->LoadModel('order_model');
$model_order->OrderNumber($ordernum)
->HostName($this->hostname(TRUE));
$specified_template = $this->settings['packingslip'] ?? '';
$html = $model_order->generateFinalPackingSlip($specified_template);
die($html);
}
public function __packingslip_register() {
$node = new \StdClass;
$node->title = 'Generic Packing Slip';
$node->entrypoint = [$this, '__packingslip'];
return $node;
}
public function __packingslip_register2() {
$node = new \StdClass;
$node->title = 'Generic Packing Slip (Blue)';
$node->entrypoint = [$this, '__packingslip2'];
return $node;
}
// default packing skip - return just the html template
public function __packingslip(&$data) {
$this->__head($this); // include our store css
$html = $this->view->store_packingslip(); // full handlebars html,
return $html;
}
// default packing skip - return just the html template
public function __packingslip2(&$data) {
$this->_preparePackingSlipData($data);
$html = $this->view->store_packingslip_blue();
return $html;
}
private function _preparePackingSlipData(&$data) {
$result = [];
$total_qty = 0;
foreach($data['cart'] as $entry) {
$result[] = ['sku' => $entry['sku'], 'desc' => $entry['desc'], 'qty' => $entry['quantity']];
$total_qty += $entry['quantity'];
// show variations
$variation = $entry['variation'] ?? '';
if ($variation != '') {
$result[] = ['sku' => "\xC2\xA0", 'html' => $variation, 'qty' => "\xC2\xA0"];
}
}
while(count($result) < 20) {
$result[] = ['sku' => "\xC2\xA0", 'desc' => "\xC2\xA0", 'qty' => "\xC2\xA0"];
}
$data['tableline'] = $result;
$data['total_qty'] = $total_qty;
}
public function __fulfillment_tabs(&$tabs, $uri) {
if (($p = strpos($uri, '?')) !== FALSE) $uri = substr($uri, 0, $p);
// $website_id = preg_match('~([0-9a-f]{32})~', $uri, $match) ? $match[1] : '';
$tabs['_tab'][] = [
'name' => 'New Orders',
'icon' => '<i class="fas fa-globe-americas"></i>',
'fragment' => 'new',
'className' => '',
];
$tabs['_tab'][] = [
'name' => 'In Transit',
'icon' => '<i class="fas fa-globe-americas"></i>',
'fragment' => 'transit',
'className' => '',
];
$tabs['_tab'][] = [
'name' => 'Completed',
'icon' => '<i class="fas fa-globe-americas"></i>',
'fragment' => 'complete',
'className' => '',
];
$tabs['uri'] = $uri;
}
public function __settings_tabs(&$tabs, $uri) {
if (($p = strpos($uri, '?')) !== FALSE) $uri = substr($uri, 0, $p);
$tabs['uri'] = $uri;
}
public function __settings_tabs30(&$tabs, $uri) {
$tabs['_tab'][] = [
'name' => 'Product Group',
'icon' => '<i class="fas fa-globe-americas"></i>',
'fragment' => 'category',
'className' => '',
];
}
public function __settings_tabs60(&$tabs, $uri) {
$tabs['_tab'][] = [
'name' => 'Manufacturers',
'icon' => '<i class="fas fa-globe-americas"></i>',
'fragment' => 'manufacturer',
'className' => '',
];
}
public function __fulfillment_new(&$data, $ephemeral) {
$data = hook_execute('execute.internal', NULL, '/admin/fulfill-new');
}
public function __fulfillment_transit(&$data, $ephemeral) {
$data = hook_execute('execute.internal', NULL, '/admin/fulfill-transit');
}
public function __fulfillment_complete(&$data, $ephemeral) {
$data = hook_execute('execute.internal', NULL, '/admin/fulfill-complete');
}
public function __settings_category(&$data, $ephemeral) {
$data = hook_execute('execute.internal', NULL, '/admin/store-category');
}
public function __settings_manufacturer(&$data, $ephemeral) {
$data = hook_execute('execute.internal', NULL, '/admin/store-manufacturer');
}
protected function getCompany() {
$settings = $this->SettingGet('config.module_info', NULL);
return $settings['companyname'] ?? 'Acme Corporation';
}
public function __meta(&$html) {
$host = $this->hostname(TRUE);
$company = $this->getCompany();
// get hostname and store name
$model_product = $this->LoadModel('product_model');
$html .= $model_product->OpenGraph($host, $company);
}
public function __getCurrency(&$res) {
$res = $this->settings['currency'] ?? '';
if ($res == '') $res = 'USD';
}
public function __snafu(&$data, $http_status) {
if ($http_status->status() == 5) {
$data['message'] = 'Processing Error';
$data['desc'] = 'We are sorry, we failed to process your order.';
}
}
public function __sitemap(&$maps) {
$maps[] = '/home/sitemap-store.xml';
}
public function listActiveProducts(&$data) {
$model_product = $this->LoadModel('product_model');
$x = $model_product->listActiveProducts();
$data = array_merge($data, $x);
}
public function __sitemap_store() {
// enabled products
$dt = date('c');
$url = $this->Hostname(TRUE);
$model_product = $this->LoadModel('product_model');
$text = '';
$data = $model_product->listActiveProducts();
foreach($data as $item) {
$text .= <<<BLOCK
<url>
<loc>{$url}{$item['uri']}</loc>
<lastmod>$dt</lastmod>
</url>
BLOCK;
}
header('Content-type: application/xml; charset=UTF-8');
echo <<<BLOCK
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{$text}</urlset>
BLOCK;
exit;
}
}