Skip to content

Commit

Permalink
Merge pull request #2 from ECodeeshop/update
Browse files Browse the repository at this point in the history
fixed twig loading issue when admin name is changed
  • Loading branch information
codeeshop-oc authored Jul 29, 2024
2 parents 413ca77 + c1bafa9 commit e142382
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ npm install
rollup -c
```

Replace Bundle generated <code>editor.bundle.js</code> file with [old file](./4.x.x.x/admin/view/javascript/)
Replace Bundle generated <code>editor.bundle.js</code> file with [old file](./upload/admin/view/javascript/)

Extension is free for use.
74 changes: 47 additions & 27 deletions upload/admin/controller/marketplace/modification.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Opencart\Admin\Controller\Extension\CesOcmod\Marketplace;

if (defined('DIR_EXTENSION')) {
Expand All @@ -22,7 +23,8 @@ class Modification extends \Opencart\System\Engine\Extension\CesOcmod\Controller
/**
* @return void
*/
public function commonMethod(): void {
public function commonMethod(): void
{
$this->load->language($this->ePathModification);

$this->load->model($this->ePathModificationModel);
Expand Down Expand Up @@ -73,7 +75,8 @@ public function commonMethod(): void {
/**
* @return void
*/
public function index(): void {
public function index(): void
{
$this->load->language($this->ePathModification);

$this->document->setTitle($this->language->get('heading_title'));
Expand All @@ -84,13 +87,15 @@ public function index(): void {
/**
* @return void
*/
public function list(): void {
public function list(): void
{
$this->load->language($this->ePathModification);

$this->response->setOutput($this->getList());
}

public function delete(): void {
public function delete(): void
{
$this->load->language($this->ePathModification);

$json = [];
Expand Down Expand Up @@ -119,7 +124,8 @@ public function delete(): void {
$this->response->setOutput(json_encode($json));
}

public function refresh($data = array()) {
public function refresh($data = array())
{
$this->load->language($this->ePathModification);

$this->document->setTitle($this->language->get('heading_title'));
Expand Down Expand Up @@ -155,7 +161,8 @@ public function refresh($data = array()) {
$this->commonMethod();
}

public function clear() {
public function clear()
{
$this->load->language($this->ePathModification);

$this->document->setTitle($this->language->get('heading_title'));
Expand Down Expand Up @@ -193,7 +200,7 @@ public function clear() {
if (is_file($file)) {
unlink($file);

// If directory use the remove directory function
// If directory use the remove directory function
} elseif (is_dir($file)) {
rmdir($file);
}
Expand Down Expand Up @@ -222,7 +229,8 @@ public function clear() {
$this->commonMethod();
}

public function enable() {
public function enable()
{
$this->load->language($this->ePathModification);

$this->document->setTitle($this->language->get('heading_title'));
Expand Down Expand Up @@ -254,7 +262,8 @@ public function enable() {
$this->commonMethod();
}

public function disable() {
public function disable()
{
$this->load->language($this->ePathModification);

$this->document->setTitle($this->language->get('heading_title'));
Expand Down Expand Up @@ -286,7 +295,8 @@ public function disable() {
$this->commonMethod();
}

public function clearlog() {
public function clearlog()
{
$this->load->language($this->ePathModification);

$this->document->setTitle($this->language->get('heading_title'));
Expand Down Expand Up @@ -323,7 +333,8 @@ public function clearlog() {
/**
* @return string
*/
protected function getList(): string {
protected function getList(): string
{
if (isset($this->request->get['sort'])) {
$sort = (string)$this->request->get['sort'];
} else {
Expand Down Expand Up @@ -459,7 +470,8 @@ protected function getList(): string {
return $this->load->view($this->ePathModification . '_list', $data);
}

protected function validate() {
protected function validate()
{
if (!$this->user->hasPermission('modify', $this->ePathModification)) {
$this->error['warning'] = $this->language->get('error_permission');
}
Expand All @@ -470,7 +482,8 @@ protected function validate() {
/**
* @return void
*/
public function form(): void {
public function form(): void
{
$this->load->language($this->ePathModification);

$this->document->setTitle($this->language->get('heading_title'));
Expand Down Expand Up @@ -543,7 +556,8 @@ public function form(): void {
/**
* @return void
*/
public function save(): void {
public function save(): void
{
$this->load->language($this->ePathModification);

$json = $data = [];
Expand Down Expand Up @@ -578,14 +592,14 @@ public function save(): void {

$this->model_extension_ces_ocmod_setting_modification->editModification($modification_id, $data);
} else {
if (!empty($data['code'])) {
// Check to see if the modification is already installed or not.
$modification_info = $this->model_extension_ces_ocmod_setting_modification->getModificationByCode($data['code']);
if (!empty($data['code'])) {
// Check to see if the modification is already installed or not.
$modification_info = $this->model_extension_ces_ocmod_setting_modification->getModificationByCode($data['code']);

if ($modification_info) {
$this->model_extension_ces_ocmod_setting_modification->deleteModification($modification_info['modification_id']);
}
}
if ($modification_info) {
$this->model_extension_ces_ocmod_setting_modification->deleteModification($modification_info['modification_id']);
}
}

// hardcoded
$data['extension_install_id'] = 0;
Expand All @@ -604,7 +618,8 @@ public function save(): void {
$this->response->setOutput(json_encode($json));
}

private function saveData($data) {
private function saveData($data)
{
// Just before files are deleted, if config settings say maintenance mode is off then turn it on
$maintenance = $this->config->get('config_maintenance');

Expand Down Expand Up @@ -646,7 +661,7 @@ private function saveData($data) {
if (is_file($file)) {
unlink($file);

// If directory use the remove directory function
// If directory use the remove directory function
} elseif (is_dir($file)) {
rmdir($file);
}
Expand Down Expand Up @@ -685,7 +700,7 @@ private function saveData($data) {
$modification = array();

foreach ($xml as $xml) {
if (empty($xml)){
if (empty($xml)) {
continue;
}

Expand Down Expand Up @@ -754,11 +769,9 @@ private function saveData($data) {

// Log
$log[] = PHP_EOL . 'FILE: ' . $key;

} else {
// Log
$log[] = PHP_EOL . 'FILE: (sub modification) ' . $key;

}

foreach ($operations as $operation) {
Expand Down Expand Up @@ -932,7 +945,7 @@ private function saveData($data) {
else {
// Log
$log[] = 'NOT FOUND - OPERATIONS ABORTED!';
break;
break;
}
}
}
Expand Down Expand Up @@ -980,5 +993,12 @@ private function saveData($data) {
// Do not return success message if refresh() was called with $data
$this->session->data['success'] = $this->language->get('text_success');

// when admin folder is changed from default admin to different
rename(DIR_MODIFICATION . 'admin/', DIR_MODIFICATION . $this->adminFolderName());
}

private function adminFolderName()
{
return str_replace([DIR_OPENCART, '/'], '', DIR_APPLICATION);
}
}
4 changes: 2 additions & 2 deletions upload/admin/controller/module/ces_ocmod.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function save(): void
$this->response->setOutput(json_encode($json));
}

public function installEvents()
public function installEvents(): void
{

$this->load->model('setting/event');
Expand All @@ -191,7 +191,7 @@ public function installEvents()
}
}

public function uninstallEvents()
public function uninstallEvents(): void
{
$this->load->model('setting/event');

Expand Down
2 changes: 1 addition & 1 deletion upload/install.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CES Ocmod",
"version": "1.0",
"version": "1.1",
"author": "CodeEshop",
"link": "https://codeeshop.com"
}
2 changes: 1 addition & 1 deletion upload/system/library/ces/cesOcmodLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait cesOcmodLib {
protected $eName = 'module_ces_ocmod';
protected $ePath = 'extension/ces_ocmod/module/ces_ocmod';
protected $ePathEvent = 'extension/ces_ocmod/event';
protected $eVersion = '1.0.0';
protected $eVersion = '1.1.0';
protected $separator = '.';

protected $ePathMarketplace = 'extension/ces_ocmod/marketplace';
Expand Down
24 changes: 24 additions & 0 deletions upload/system/modification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,29 @@
]]>
</add>
</operation>
<operation>
<search>
<![CDATA[$file = substr($file, strlen($this->root) + 1);]]>
</search>
<add position="before">
<![CDATA[
if (strpos($file, DIR_STORAGE) === false) {
$this->loader = new \Twig\Loader\FilesystemLoader('/', $this->root);
]]>
</add>
</operation>
<operation>
<search>
<![CDATA[$file = substr($file, strlen($this->root) + 1);]]>
</search>
<add position="after">
<![CDATA[
} else {
$this->loader = new \Twig\Loader\FilesystemLoader('/', DIR_STORAGE);
$file = substr($file, strlen(DIR_STORAGE));
}
]]>
</add>
</operation>
</file>
</modification>

0 comments on commit e142382

Please sign in to comment.