fix: init exception for some opencart versions

This commit is contained in:
2025-09-24 11:44:25 +03:00
parent 854dfdf7f2
commit 0cf0c43843
2 changed files with 22 additions and 10 deletions

View File

@@ -74,11 +74,20 @@ class ControllerExtensionModuleTgshop extends Controller
private array $error = []; private array $error = [];
public function index(): void public function __construct($registry)
{ {
parent::__construct($registry);
$this->load->language('extension/module/tgshop'); $this->load->language('extension/module/tgshop');
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->load->model('tool/image');
$this->load->model('catalog/product');
$this->load->model('localisation/order_status');
$this->load->model('customer/customer_group');
}
public function index(): void
{
$hasConfig = $this->config->get('module_tgshop_app_name') !== null; $hasConfig = $this->config->get('module_tgshop_app_name') !== null;
if ($hasConfig) { if ($hasConfig) {
@@ -121,7 +130,7 @@ class ControllerExtensionModuleTgshop extends Controller
foreach ($data['settings'] as $configs) { foreach ($data['settings'] as $configs) {
foreach ($configs as $key => $config) { foreach ($configs as $key => $config) {
if ($config['type'] === 'image') { if ($config['type'] === 'image') {
$this->load->model('tool/image');
if (isset($this->request->post[$key]) && is_file(DIR_IMAGE . $this->request->post[$key])) { if (isset($this->request->post[$key]) && is_file(DIR_IMAGE . $this->request->post[$key])) {
$data[$key] = $this->model_tool_image->resize($this->request->post[$key], 100, 100); $data[$key] = $this->model_tool_image->resize($this->request->post[$key], 100, 100);
} elseif ($this->config->get($key) && is_file(DIR_IMAGE . $this->config->get($key))) { } elseif ($this->config->get($key) && is_file(DIR_IMAGE . $this->config->get($key))) {
@@ -131,7 +140,7 @@ class ControllerExtensionModuleTgshop extends Controller
} }
} elseif ($config['type'] === 'products') { } elseif ($config['type'] === 'products') {
$products = $this->request->post[$key] ?? $this->config->get($key) ?? []; $products = $this->request->post[$key] ?? $this->config->get($key) ?? [];
$this->load->model('catalog/product');
$data[$key] = []; $data[$key] = [];
foreach ($products as $productId) { foreach ($products as $productId) {
$productItem = $this->model_catalog_product->getProduct($productId); $productItem = $this->model_catalog_product->getProduct($productId);
@@ -275,8 +284,6 @@ class ControllerExtensionModuleTgshop extends Controller
private function getDefaultConfig(): array private function getDefaultConfig(): array
{ {
$this->load->model('tool/image');
return [ return [
'module_tgshop_status' => 1, 'module_tgshop_status' => 1,
'module_tgshop_app_name' => $this->config->get('config_meta_title'), 'module_tgshop_app_name' => $this->config->get('config_meta_title'),
@@ -451,7 +458,6 @@ HTML,
private function getCustomerGroups(): array private function getCustomerGroups(): array
{ {
$this->load->model('customer/customer_group');
$map = []; $map = [];
foreach ($this->model_customer_customer_group->getCustomerGroups() as $customer_group) { foreach ($this->model_customer_customer_group->getCustomerGroups() as $customer_group) {
@@ -463,7 +469,6 @@ HTML,
private function getOrderStatuses() private function getOrderStatuses()
{ {
$this->load->model('localisation/order_status');
$statuses = $this->model_localisation_order_status->getOrderStatuses(); $statuses = $this->model_localisation_order_status->getOrderStatuses();
$map = []; $map = [];

View File

@@ -23,11 +23,18 @@ if (is_readable($sysLibPath . '/oc_telegram_shop.phar')) {
/** /**
* @property Config $config * @property Config $config
*/ */
class Controllerextensiontgshophandle extends Controller class ControllerExtensionTgshopHandle extends Controller
{ {
public function __construct($registry)
{
parent::__construct($registry);
$this->load->model('catalog/product');
$this->load->model('checkout/order');
}
public function index(): void public function index(): void
{ {
$this->load->model('checkout/order');
$this->session->data['language'] = $this->config->get('config_language'); $this->session->data['language'] = $this->config->get('config_language');
$app = ApplicationFactory::create([ $app = ApplicationFactory::create([
@@ -75,7 +82,7 @@ class Controllerextensiontgshophandle extends Controller
]); ]);
$app->bind(OcModelCatalogProductAdapter::class, function () { $app->bind(OcModelCatalogProductAdapter::class, function () {
$this->load->model('catalog/product');
return new OcModelCatalogProductAdapter($this->model_catalog_product); return new OcModelCatalogProductAdapter($this->model_catalog_product);
}); });