first commit
This commit is contained in:
25
catalog/controller/startup/api.php
Normal file
25
catalog/controller/startup/api.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Api
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Api extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return object|\Opencart\System\Engine\Action|null
|
||||
*/
|
||||
public function index(): object|null {
|
||||
if (isset($this->request->get['route'])) {
|
||||
$route = (string)$this->request->get['route'];
|
||||
} else {
|
||||
$route = '';
|
||||
}
|
||||
|
||||
if (substr($route, 0, 4) == 'api/' && $route !== 'api/account/login' && !isset($this->session->data['api_id'])) {
|
||||
return new \Opencart\System\Engine\Action('error/permission');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
22
catalog/controller/startup/application.php
Normal file
22
catalog/controller/startup/application.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Application
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Application extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
// Weight
|
||||
$this->registry->set('weight', new \Opencart\System\Library\Cart\Weight($this->registry));
|
||||
|
||||
// Length
|
||||
$this->registry->set('length', new \Opencart\System\Library\Cart\Length($this->registry));
|
||||
|
||||
// Cart
|
||||
$this->registry->set('cart', new \Opencart\System\Library\Cart\Cart($this->registry));
|
||||
}
|
||||
}
|
48
catalog/controller/startup/currency.php
Normal file
48
catalog/controller/startup/currency.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Currency
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Currency extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$code = '';
|
||||
|
||||
$this->load->model('localisation/currency');
|
||||
|
||||
$currencies = $this->model_localisation_currency->getCurrencies();
|
||||
|
||||
if (isset($this->session->data['currency'])) {
|
||||
$code = $this->session->data['currency'];
|
||||
}
|
||||
|
||||
if (isset($this->request->cookie['currency']) && !array_key_exists($code, $currencies)) {
|
||||
$code = $this->request->cookie['currency'];
|
||||
}
|
||||
|
||||
if (!array_key_exists($code, $currencies)) {
|
||||
$code = $this->config->get('config_currency');
|
||||
}
|
||||
|
||||
if (!isset($this->session->data['currency']) || $this->session->data['currency'] != $code) {
|
||||
$this->session->data['currency'] = $code;
|
||||
}
|
||||
|
||||
// Set a new currency cookie if the code does not match the current one
|
||||
if (!isset($this->request->cookie['currency']) || $this->request->cookie['currency'] != $code) {
|
||||
$option = [
|
||||
'expires' => time() + 60 * 60 * 24 * 30,
|
||||
'path' => '/',
|
||||
'SameSite' => 'Lax'
|
||||
];
|
||||
|
||||
setcookie('currency', $code, $option);
|
||||
}
|
||||
|
||||
$this->registry->set('currency', new \Opencart\System\Library\Cart\Currency($this->registry));
|
||||
}
|
||||
}
|
23
catalog/controller/startup/customer.php
Normal file
23
catalog/controller/startup/customer.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Customer
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Customer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->registry->set('customer', new \Opencart\System\Library\Cart\Customer($this->registry));
|
||||
|
||||
// Customer Group
|
||||
if (isset($this->session->data['customer'])) {
|
||||
$this->config->set('config_customer_group_id', $this->session->data['customer']['customer_group_id']);
|
||||
} elseif ($this->customer->isLogged()) {
|
||||
// Logged in customers
|
||||
$this->config->set('config_customer_group_id', $this->customer->getGroupId());
|
||||
}
|
||||
}
|
||||
}
|
77
catalog/controller/startup/error.php
Normal file
77
catalog/controller/startup/error.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Error
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Error extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->registry->set('log', new \Opencart\System\Library\Log($this->config->get('config_error_filename')));
|
||||
|
||||
set_error_handler([$this, 'error']);
|
||||
set_exception_handler([$this, 'exception']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $message
|
||||
* @param string $file
|
||||
* @param string $line
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function error(string $code, string $message, string $file, string $line): bool {
|
||||
switch ($code) {
|
||||
case E_NOTICE:
|
||||
case E_USER_NOTICE:
|
||||
$error = 'Notice';
|
||||
break;
|
||||
case E_WARNING:
|
||||
case E_USER_WARNING:
|
||||
$error = 'Warning';
|
||||
break;
|
||||
case E_ERROR:
|
||||
case E_USER_ERROR:
|
||||
$error = 'Fatal Error';
|
||||
break;
|
||||
default:
|
||||
$error = 'Unknown';
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_error_log')) {
|
||||
$this->log->write('PHP ' . $error . ': ' . $message . ' in ' . $file . ' on line ' . $line);
|
||||
}
|
||||
|
||||
if ($this->config->get('config_error_display')) {
|
||||
echo '<b>' . $error . '</b>: ' . $message . ' in <b>' . $file . '</b> on line <b>' . $line . '</b>';
|
||||
} else {
|
||||
header('Location: ' . $this->config->get('error_page'));
|
||||
exit();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable $e
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function exception(\Throwable $e): void {
|
||||
if ($this->config->get('config_error_log')) {
|
||||
$this->log->write($e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
|
||||
}
|
||||
|
||||
if ($this->config->get('config_error_display')) {
|
||||
echo '<b>' . $e->getMessage() . '</b>: in <b>' . $e->getFile() . '</b> on line <b>' . $e->getLine() . '</b>';
|
||||
} else {
|
||||
header('Location: ' . $this->config->get('error_page'));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
32
catalog/controller/startup/event.php
Normal file
32
catalog/controller/startup/event.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Event
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Event extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
// Add events from the DB
|
||||
$this->load->model('setting/event');
|
||||
|
||||
$results = $this->model_setting_event->getEvents();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$part = explode('/', $result['trigger']);
|
||||
|
||||
if ($part[0] == 'catalog') {
|
||||
array_shift($part);
|
||||
|
||||
$this->event->register(implode('/', $part), new \Opencart\System\Engine\Action($result['action']), $result['sort_order']);
|
||||
}
|
||||
|
||||
if ($part[0] == 'system') {
|
||||
$this->event->register($result['trigger'], new \Opencart\System\Engine\Action($result['action']), $result['sort_order']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
catalog/controller/startup/extension.php
Normal file
36
catalog/controller/startup/extension.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Extension
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Extension extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
// Add extension paths from the DB
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getExtensions();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$extension = str_replace(['_', '/'], ['', '\\'], ucwords($result['extension'], '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Catalog\Controller\Extension\\' . $extension, DIR_EXTENSION . $result['extension'] . '/catalog/controller/');
|
||||
$this->autoloader->register('Opencart\Catalog\Model\Extension\\' . $extension, DIR_EXTENSION . $result['extension'] . '/catalog/model/');
|
||||
$this->autoloader->register('Opencart\System\Library\Extension\\' . $extension, DIR_EXTENSION . $result['extension'] . '/system/library/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $result['extension'], DIR_EXTENSION . $result['extension'] . '/catalog/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $result['extension'], DIR_EXTENSION . $result['extension'] . '/catalog/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $result['extension'], DIR_EXTENSION . $result['extension'] . '/system/config/');
|
||||
}
|
||||
}
|
||||
}
|
79
catalog/controller/startup/language.php
Normal file
79
catalog/controller/startup/language.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static array $languages = [];
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
if (isset($this->request->get['language'])) {
|
||||
$code = (string)$this->request->get['language'];
|
||||
} else {
|
||||
$code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
self::$languages = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset(self::$languages[$code])) {
|
||||
$language_info = self::$languages[$code];
|
||||
|
||||
// If extension switch add language directory
|
||||
if ($language_info['extension']) {
|
||||
$this->language->addPath('extension/' . $language_info['extension'], DIR_EXTENSION . $language_info['extension'] . '/catalog/language/');
|
||||
}
|
||||
|
||||
// Set the config language_id key
|
||||
$this->config->set('config_language_id', $language_info['language_id']);
|
||||
$this->config->set('config_language', $language_info['code']);
|
||||
|
||||
$this->load->language('default');
|
||||
}
|
||||
}
|
||||
|
||||
// Override the language default values
|
||||
|
||||
/**
|
||||
* @param $route
|
||||
* @param $prefix
|
||||
* @param $code
|
||||
* @param $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function after(&$route, &$prefix, &$code, &$output): void {
|
||||
if (!$code) {
|
||||
$code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Use $this->language->load so it's not triggering infinite loops
|
||||
$this->language->load($route, $prefix, $code);
|
||||
|
||||
if (isset(self::$languages[$code])) {
|
||||
$language_info = self::$languages[$code];
|
||||
|
||||
$path = '';
|
||||
|
||||
if ($language_info['extension']) {
|
||||
$extension = 'extension/' . $language_info['extension'];
|
||||
|
||||
if (oc_substr($route, 0, strlen($extension)) != $extension) {
|
||||
$path = $extension . '/';
|
||||
}
|
||||
}
|
||||
|
||||
// Use $this->language->load so it's not triggering infinite loops
|
||||
$this->language->load($path . $route, $prefix, $code);
|
||||
}
|
||||
}
|
||||
}
|
36
catalog/controller/startup/maintenance.php
Normal file
36
catalog/controller/startup/maintenance.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Maintenance
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Maintenance extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return object|\Opencart\System\Engine\Action|null
|
||||
*/
|
||||
public function index(): object|null {
|
||||
if ($this->config->get('config_maintenance')) {
|
||||
// Route
|
||||
if (isset($this->request->get['route'])) {
|
||||
$route = $this->request->get['route'];
|
||||
} else {
|
||||
$route = $this->config->get('action_default');
|
||||
}
|
||||
|
||||
$ignore = [
|
||||
'common/language/language',
|
||||
'common/currency/currency'
|
||||
];
|
||||
|
||||
// Show site if logged in as admin
|
||||
$user = new \Opencart\System\Library\Cart\User($this->registry);
|
||||
|
||||
if (substr($route, 0, 3) != 'api' && !in_array($route, $ignore) && !$user->isLogged()) {
|
||||
return new \Opencart\System\Engine\Action('common/maintenance');
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
58
catalog/controller/startup/marketing.php
Normal file
58
catalog/controller/startup/marketing.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Marketing
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Marketing extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$tracking = '';
|
||||
|
||||
if (isset($this->request->get['tracking'])) {
|
||||
$tracking = (string)$this->request->get['tracking'];
|
||||
}
|
||||
|
||||
if (isset($this->request->cookie['tracking'])) {
|
||||
$tracking = (string)$this->request->cookie['tracking'];
|
||||
}
|
||||
|
||||
// Tracking Code
|
||||
if ($tracking) {
|
||||
$this->load->model('marketing/marketing');
|
||||
|
||||
$marketing_info = $this->model_marketing_marketing->getMarketingByCode($tracking);
|
||||
|
||||
if ($marketing_info) {
|
||||
$this->model_marketing_marketing->addReport($marketing_info['marketing_id'], $this->request->server['REMOTE_ADDR']);
|
||||
}
|
||||
|
||||
if ($this->config->get('config_affiliate_status')) {
|
||||
$this->load->model('account/affiliate');
|
||||
|
||||
$affiliate_info = $this->model_account_affiliate->getAffiliateByTracking($tracking);
|
||||
|
||||
if ($affiliate_info && $affiliate_info['status']) {
|
||||
$this->model_account_affiliate->addReport($affiliate_info['customer_id'], $this->request->server['REMOTE_ADDR']);
|
||||
}
|
||||
|
||||
if ($marketing_info || ($affiliate_info && $affiliate_info['status'])) {
|
||||
$this->session->data['tracking'] = $tracking;
|
||||
|
||||
if (!isset($this->request->cookie['tracking'])) {
|
||||
$option = [
|
||||
'expires' => $this->config->get('config_affiliate_expire') ? time() + (int)$this->config->get('config_affiliate_expire') : 0,
|
||||
'path' => $this->config->get('session_path'),
|
||||
'SameSite' => $this->config->get('config_session_samesite')
|
||||
];
|
||||
|
||||
setcookie('tracking', $tracking, $option);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
catalog/controller/startup/sass.php
Normal file
44
catalog/controller/startup/sass.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Sass
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Sass extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
* @throws \ScssPhp\ScssPhp\Exception\SassException
|
||||
*/
|
||||
public function index(): void {
|
||||
$files = glob(DIR_APPLICATION . 'view/stylesheet/*.scss');
|
||||
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
// Get the filename
|
||||
$filename = basename($file, '.scss');
|
||||
|
||||
$stylesheet = DIR_APPLICATION . 'view/stylesheet/' . $filename . '.css';
|
||||
|
||||
if (!is_file($stylesheet) || !$this->config->get('developer_sass')) {
|
||||
$scss = new \ScssPhp\ScssPhp\Compiler();
|
||||
$scss->setImportPaths(DIR_APPLICATION . 'view/stylesheet/');
|
||||
|
||||
$output = $scss->compileString('@import "' . $filename . '.scss"')->getCss();
|
||||
|
||||
$handle = fopen($stylesheet, 'w');
|
||||
|
||||
flock($handle, LOCK_EX);
|
||||
|
||||
fwrite($handle, $output);
|
||||
|
||||
fflush($handle);
|
||||
|
||||
flock($handle, LOCK_UN);
|
||||
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
106
catalog/controller/startup/seo_url.php
Normal file
106
catalog/controller/startup/seo_url.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class SeoUrl
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class SeoUrl extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
// Add rewrite to URL class
|
||||
if ($this->config->get('config_seo_url')) {
|
||||
$this->url->addRewrite($this);
|
||||
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
// Decode URL
|
||||
if (isset($this->request->get['_route_'])) {
|
||||
$parts = explode('/', $this->request->get['_route_']);
|
||||
|
||||
// remove any empty arrays from trailing
|
||||
if (oc_strlen(end($parts)) == 0) {
|
||||
array_pop($parts);
|
||||
}
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyword($part);
|
||||
|
||||
if ($seo_url_info) {
|
||||
$this->request->get[$seo_url_info['key']] = html_entity_decode($seo_url_info['value'], ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function rewrite(string $link): string {
|
||||
$url_info = parse_url(str_replace('&', '&', $link));
|
||||
|
||||
// Build the url
|
||||
$url = '';
|
||||
|
||||
if ($url_info['scheme']) {
|
||||
$url .= $url_info['scheme'];
|
||||
}
|
||||
|
||||
$url .= '://';
|
||||
|
||||
if ($url_info['host']) {
|
||||
$url .= $url_info['host'];
|
||||
}
|
||||
|
||||
if (isset($url_info['port'])) {
|
||||
$url .= ':' . $url_info['port'];
|
||||
}
|
||||
|
||||
parse_str($url_info['query'], $query);
|
||||
|
||||
// Start changing the URL query into a path
|
||||
$paths = [];
|
||||
|
||||
// Parse the query into its separate parts
|
||||
$parts = explode('&', $url_info['query']);
|
||||
|
||||
foreach ($parts as $part) {
|
||||
[$key, $value] = explode('=', $part);
|
||||
|
||||
$result = $this->model_design_seo_url->getSeoUrlByKeyValue((string)$key, (string)$value);
|
||||
|
||||
if ($result) {
|
||||
$paths[] = $result;
|
||||
|
||||
unset($query[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
foreach ($paths as $key => $value) {
|
||||
$sort_order[$key] = $value['sort_order'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $paths);
|
||||
|
||||
// Build the path
|
||||
$url .= str_replace('/index.php', '', $url_info['path']);
|
||||
|
||||
foreach ($paths as $result) {
|
||||
$url .= '/' . $result['keyword'];
|
||||
}
|
||||
|
||||
// Rebuild the URL query
|
||||
if ($query) {
|
||||
$url .= '?' . str_replace(['%2F'], ['/'], http_build_query($query));
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
71
catalog/controller/startup/session.php
Normal file
71
catalog/controller/startup/session.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Session
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Session extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(): void {
|
||||
$session = new \Opencart\System\Library\Session($this->config->get('session_engine'), $this->registry);
|
||||
$this->registry->set('session', $session);
|
||||
|
||||
if (isset($this->request->get['route']) && substr((string)$this->request->get['route'], 0, 4) == 'api/' && isset($this->request->get['api_token'])) {
|
||||
$this->load->model('setting/api');
|
||||
|
||||
$this->model_setting_api->cleanSessions();
|
||||
|
||||
// Make sure the IP is allowed
|
||||
$api_info = $this->model_setting_api->getApiByToken($this->request->get['api_token']);
|
||||
|
||||
if ($api_info) {
|
||||
$this->session->start($this->request->get['api_token']);
|
||||
|
||||
$this->model_setting_api->updateSession($api_info['api_session_id']);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
We are adding the session cookie outside of the session class as I believe
|
||||
PHP messed up in a big way handling sessions. Why in the hell is it so hard to
|
||||
have more than one concurrent session using cookies!
|
||||
|
||||
Is it not better to have multiple cookies when accessing parts of the system
|
||||
that requires different cookie sessions for security reasons.
|
||||
*/
|
||||
|
||||
// Update the session lifetime
|
||||
if ($this->config->get('config_session_expire')) {
|
||||
$this->config->set('session_expire', $this->config->get('config_session_expire'));
|
||||
}
|
||||
|
||||
// Update the session SameSite
|
||||
$this->config->set('session_samesite', $this->config->get('config_session_samesite'));
|
||||
|
||||
if (isset($this->request->cookie[$this->config->get('session_name')])) {
|
||||
$session_id = $this->request->cookie[$this->config->get('session_name')];
|
||||
} else {
|
||||
$session_id = '';
|
||||
}
|
||||
|
||||
$session->start($session_id);
|
||||
|
||||
$option = [
|
||||
'expires' => time() + (int)$this->config->get('config_session_expire'),
|
||||
'path' => $this->config->get('session_path'),
|
||||
'secure' => $this->request->server['HTTPS'],
|
||||
'httponly' => false,
|
||||
'SameSite' => $this->config->get('session_samesite')
|
||||
];
|
||||
|
||||
$this->response->addHeader('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
||||
|
||||
setcookie($this->config->get('session_name'), $session->getId(), $option);
|
||||
}
|
||||
}
|
66
catalog/controller/startup/setting.php
Normal file
66
catalog/controller/startup/setting.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Setting
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Setting extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$hostname = ($this->request->server['HTTPS'] ? 'https://' : 'http://') . str_replace('www.', '', $this->request->server['HTTP_HOST']) . rtrim(dirname($this->request->server['PHP_SELF']), '/.\\') . '/';
|
||||
|
||||
$store_info = $this->model_setting_store->getStoreByHostname($hostname);
|
||||
|
||||
// Store
|
||||
if (isset($this->request->get['store_id'])) {
|
||||
$this->config->set('config_store_id', (int)$this->request->get['store_id']);
|
||||
} elseif ($store_info) {
|
||||
$this->config->set('config_store_id', $store_info['store_id']);
|
||||
} else {
|
||||
$this->config->set('config_store_id', 0);
|
||||
}
|
||||
|
||||
if (!$store_info) {
|
||||
// If catalog constant is defined
|
||||
if (defined('HTTP_CATALOG')) {
|
||||
$this->config->set('config_url', HTTP_CATALOG);
|
||||
} else{
|
||||
$this->config->set('config_url', HTTP_SERVER);
|
||||
}
|
||||
}
|
||||
|
||||
// Settings
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$results = $this->model_setting_setting->getSettings($this->config->get('config_store_id'));
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (!$result['serialized']) {
|
||||
$this->config->set($result['key'], $result['value']);
|
||||
} else {
|
||||
$this->config->set($result['key'], json_decode($result['value'], true));
|
||||
}
|
||||
}
|
||||
|
||||
// Url
|
||||
$this->registry->set('url', new \Opencart\System\Library\Url($this->config->get('config_url')));
|
||||
|
||||
// Set time zone
|
||||
if ($this->config->get('config_timezone')) {
|
||||
date_default_timezone_set($this->config->get('config_timezone'));
|
||||
|
||||
// Sync PHP and DB time zones.
|
||||
$this->db->query("SET time_zone = '" . $this->db->escape(date('P')) . "'");
|
||||
}
|
||||
|
||||
// Response output compression level
|
||||
if ($this->config->get('config_compression')) {
|
||||
$this->response->setCompression((int)$this->config->get('config_compression'));
|
||||
}
|
||||
}
|
||||
}
|
24
catalog/controller/startup/startup.php
Normal file
24
catalog/controller/startup/startup.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Startup
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Startup extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
// Load startup actions
|
||||
$this->load->model('setting/startup');
|
||||
|
||||
$results = $this->model_setting_startup->getStartups();
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (substr($result['action'], 0, 8) == 'catalog/') {
|
||||
$this->load->controller(substr($result['action'], 8));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
29
catalog/controller/startup/tax.php
Normal file
29
catalog/controller/startup/tax.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Startup;
|
||||
/**
|
||||
* Class Tax
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Startup
|
||||
*/
|
||||
class Tax extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->registry->set('tax', new \Opencart\System\Library\Cart\Tax($this->registry));
|
||||
|
||||
if (isset($this->session->data['shipping_address'])) {
|
||||
$this->tax->setShippingAddress((int)$this->session->data['shipping_address']['country_id'], (int)$this->session->data['shipping_address']['zone_id']);
|
||||
} elseif ($this->config->get('config_tax_default') == 'shipping') {
|
||||
$this->tax->setShippingAddress((int)$this->config->get('config_country_id'), (int)$this->config->get('config_zone_id'));
|
||||
}
|
||||
|
||||
if (isset($this->session->data['payment_address'])) {
|
||||
$this->tax->setPaymentAddress((int)$this->session->data['payment_address']['country_id'], (int)$this->session->data['payment_address']['zone_id']);
|
||||
} elseif ($this->config->get('config_tax_default') == 'payment') {
|
||||
$this->tax->setPaymentAddress((int)$this->config->get('config_country_id'), (int)$this->config->get('config_zone_id'));
|
||||
}
|
||||
|
||||
$this->tax->setStoreAddress((int)$this->config->get('config_country_id'), (int)$this->config->get('config_zone_id'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user