Opencart module_id not appending in admin link - opencart

I am developing a Opencart module (Version 4.0.0.0).
Created the module with height and status. Installed the same in the Opencart application. But the problem is when I tried to save the value to the db, it is creating a new row inside "oc_module" table. While checking I just found that "module_id" is not appending the URL from the module listing page's edit button.
The testimonial module link looks like
http://localhost/op4/admin/index.php?route=extension/testimonials/module/testimonials&user_token=2e7a4d8fad2e1c4339e9c01bc83d707a
extensions --> testimonial --> admin --> controller --> module --> testimonials.php
<?php
namespace Opencart\Admin\Controller\Extension\Testimonials\Module;
class Testimonials extends \Opencart\System\Engine\Controller {
public function index(): void {
$this->load->language('extension/testimonials/module/testimonials');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/setting');
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module')
];
if (!isset($this->request->get['module_id'])) {
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/testimonials/module/testimonials', 'user_token=' . $this->session->data['user_token'])
];
} else {
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/testimonials/module/testimonials', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'])
];
}
if (!isset($this->request->get['module_id'])) {
$data['save'] = $this->url->link('extension/testimonials/module/testimonials|save', 'user_token=' . $this->session->data['user_token']);
} else {
$data['save'] = $this->url->link('extension/testimonials/module/testimonials|save', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']);
}
$data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module');
if (isset($this->request->get['module_id'])) {
$this->load->model('setting/module');
$module_info = $this->model_setting_module->getModule($this->request->get['module_id']);
print_r($module_info);
}
if (isset($module_info['name'])) {
$data['name'] = $module_info['name'];
} else {
$data['name'] = '';
}
if (isset($module_info['height'])) {
$data['height'] = $module_info['height'];
} else {
$data['height'] = 200;
}
if (isset($module_info['status'])) {
$data['status'] = $module_info['status'];
} else {
$data['status'] = '';
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/testimonials/module/testimonials', $data));
}
public function save(): void {
$this->load->language('extension/testimonials/module/testimonials');
$json = [];
if (!$this->user->hasPermission('modify', 'extension/testimonials/module/testimonials')) {
$json['error']['warning'] = $this->language->get('error_permission');
}
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) {
$json['error']['name'] = $this->language->get('error_name');
}
if (!$this->request->post['height']) {
$json['error']['height'] = $this->language->get('error_height');
}
if (!$json) {
$this->load->model('setting/module');
if (!isset($this->request->get['module_id'])) {
$this->model_setting_module->addModule('module_testimonials', $this->request->post);
} else {
$this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

You have error in your save function.
You need to change: $this->model_setting_module->addModule('module_testimonials', $this->request->post);
to:
$this->model_setting_module->addModule('testimonials.testimonials', $this->request->post);

Related

Rewrite controller file of opencart 2.3 extension to opencart 3.X (twig)

I need your help in how can I change this controller code of opencart 2.3 extension to be compatible for opencart 3.X,
I have changed the tpl files in admin/view/template/extension/payment/ to twig with their parameters
also I changed the 'token=' to user_token in the controller
file path
admin/controller/extension/payment/
<?php
class ControllerExtensionPaymentIcredit extends Controller {
private $error = array();
public function install()
{
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "iCredit` (
`id_icredit` int(1) NOT NULL AUTO_INCREMENT,
`enabled` varchar(255),
`PaymentMethodDescription` varchar(500) CHARACTER SET utf8,
`title` varchar(255) CHARACTER SET utf8,
`testmode` varchar(1),
`testtoken` varchar(255),
`grouptoken` varchar(500),
`maxpayment` varchar(255),
`creditpayment` varchar(500),
`windowtype` varchar(255),
`height` int(10),
`width` int(10),
`hideitemlist` varchar(1),
`createtoken` varchar(1),
`invoicelang` varchar(500),
`exemptvat` varchar(255),
`redirecturl` varchar(500),
`ipn` varchar(500),
`sortorder` varchar(500),
`date_added` datetime,
PRIMARY KEY (`id_icredit`)
)");
}
public function uninstall()
{
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "iCredit");
}
public function index()
{ // Default function
$this->install();
$this->load->language('extension/payment/icredit'); // Loading the language file of helloworld
$this->document->setTitle($this->language->get('heading_title')); // Set the title of the page to the heading title in the Language file i.e., Hello World
$this->load->model('setting/setting');
$this->load->model('extension/payment/icredit'); // Load the Setting Model (All of the OpenCart Module & General Settings are saved using this Model )
//fwrite($file,$this->validate()." -- validate\r\n");
//fwrite($file,print_r($_POST,TRUE)." -- post\r\n");
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate())
{
if ($this->request->post['icredit_id'] == "")
{
$this->model_setting_setting->editSetting('icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->addicreditsettings($this->request->post);
}
else
{
$this->model_setting_setting->editSetting('icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->editicreditsettings($this->request->post);
}
$this->session->data['success'] = $this->language->get('text_success'); // To display the success text on data save=
if($check == 1)
{
$this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'], 'SSL')); // Redirect to the Module Listing
}
}
/*Assign the language data for parsing it to view*/
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_content_top'] = $this->language->get('text_content_top');
$data['text_content_bottom'] = $this->language->get('text_content_bottom');
$data['text_column_left'] = $this->language->get('text_column_left');
$data['text_column_right'] = $this->language->get('text_column_right');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_paymentdescription'] = $this->language->get('text_paymentdescription');
$data['text_title'] = $this->language->get('text_title');
$data['text_testmode'] = $this->language->get('text_testmode');
$data['text_testgrouptoken'] = $this->language->get('text_testgrouptoken');
$data['text_prodgrouptoken'] = $this->language->get('text_prodgrouptoken');
$data['text_maxpayment'] = $this->language->get('text_maxpayment');
$data['text_creditpayment'] = $this->language->get('text_creditpayment');
$data['text_windowselecttype'] = $this->language->get('text_windowselecttype');
$data['text_optionredirect'] = $this->language->get('text_optionredirect');
$data['text_optionpopup'] = $this->language->get('text_optionpopup');
$data['text_optioniframe'] = $this->language->get('text_optioniframe');
$data['text_height'] = $this->language->get('text_height');
$data['text_width'] = $this->language->get('text_width');
$data['text_hideitemlist'] = $this->language->get('text_hideitemlist');
$data['text_createtoken'] = $this->language->get('text_createtoken');
$data['text_invoicelang'] = $this->language->get('text_invoicelang');
$data['text_english'] = $this->language->get('text_english');
$data['text_hebrew'] = $this->language->get('text_hebrew');
$data['text_billing'] = $this->language->get('text_billing');
$data['text_shipping'] = $this->language->get('text_shipping');
$data['text_billingshipping'] = $this->language->get('text_billingshipping');
$data['text_exemptvat'] = $this->language->get('text_exemptvat');
$data['text_chargevat'] = $this->language->get('text_chargevat');
$data['text_exempt'] = $this->language->get('text_exempt');
$data['text_billing'] = $this->language->get('text_billing');
$data['text_shipping'] = $this->language->get('text_shipping');
$data['text_billingshipping'] = $this->language->get('text_billingshipping');
$data['text_redirecturl'] = $this->language->get('text_redirecturl');
$data['text_sortorder'] = $this->language->get('text_sortorder');
$data['text_ipn'] = $this->language->get('text_ipn');
$data['text_yes'] = $this->language->get('text_yes');
$data['text_no'] = $this->language->get('text_no');
$data['entry_code'] = $this->language->get('entry_code');
$data['entry_layout'] = $this->language->get('entry_layout');
$data['entry_position'] = $this->language->get('entry_position');
$data['entry_status'] = $this->language->get('entry_status');
$data['entry_sort_order'] = $this->language->get('entry_sort_order');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
$data['button_add_module'] = $this->language->get('button_add_module');
$data['button_remove'] = $this->language->get('button_remove');
$data['entry_order_status'] = $this->language->get('entry_order_status');
$data['pending_order_status'] = $this->language->get('pending_order_status');
$data['processing_order_status'] = $this->language->get('processing_order_status');
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
// return warning if any*/
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['description'])) {
$data['description'] = $this->error['description'];
} else {
$data['description'] = '';
}
/* Making of Breadcrumbs to be displayed on site*/
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/payment/icredit', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
/* End Breadcrumb Block*/
$data['action'] = $this->url->link('extension/payment/icredit', 'token=' . $this->session->data['token'], 'SSL'); // URL to be directed when the save button is pressed
$data['cancel'] = $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'); // URL to be redirected when cancel button is pressed
/* This block checks, if the hello world text field is set it parses it to view otherwise get the default hello world text field from the database and parse it*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['PaymentMethodDescription'] = $this->request->post['PaymentMethodDescription'];
} else {
$data['PaymentMethodDescription'] = $this->config->get('PaymentMethodDescription');
}
if (isset($this->request->post['icredit_complete_order_status_id'])) {
$data['icredit_complete_order_status_id'] = $this->request->post['icredit_complete_order_status_id'];
} else {
$data['icredit_complete_order_status_id'] = $this->config->get('icredit_complete_order_status_id');
}
if (isset($this->request->post['icredit_pending_order_status_id'])) {
$data['icredit_pending_order_status_id'] = $this->request->post['icredit_pending_order_status_id'];
} else {
$data['icredit_pending_order_status_id'] = $this->config->get('icredit_pending_order_status_id');
}
if (isset($this->request->post['icredit_processing_order_status_id'])) {
$data['icredit_processing_order_status_id'] = $this->request->post['icredit_processing_order_status_id'];
} else {
$data['icredit_processing_order_status_id'] = $this->config->get('icredit_processing_order_status_id');
}
/* End Block*/
$data['modules'] = array();
/* This block parses the Module Settings such as Layout, Position,Status & Order Status to the view*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['modules'] = $this->request->post['PaymentMethodDescription'];
} elseif ($this->config->get('PaymentMethodDescription')) {
$data['modules'] = $this->config->get('PaymentMethodDescription');
}
/* End Block*/
$this->load->model('design/layout'); // Loading the Design Layout Models
$data['layouts'] = $this->model_design_layout->getLayouts(); // Getting all the Layouts available on system
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$getsettings = $this->model_extension_payment_icredit->addGeticreditsettings();
$data['editdata']=array();
if(isset($getsettings))
{
$data['editdata']['icredit_id'] = $getsettings['id_icredit'];
$data['editdata']['enabled'] = $getsettings['enabled'];
$data['editdata']['PaymentMethodDescription'] = $getsettings['PaymentMethodDescription'];
$data['editdata']['title'] = $getsettings['title'];
$data['editdata']['testmode'] = $getsettings['testmode'];
$data['editdata']['testtoken'] = $getsettings['testtoken'];
$data['editdata']['grouptoken'] = $getsettings['grouptoken'];
$data['editdata']['maxpayment'] = $getsettings['maxpayment'];
$data['editdata']['creditpayment'] = $getsettings['creditpayment'];
$data['editdata']['windowtype'] = $getsettings['windowtype'];
$data['editdata']['height'] = $getsettings['height'];
$data['editdata']['width'] = $getsettings['width'];
$data['editdata']['hideitemlist'] = $getsettings['hideitemlist'];
$data['editdata']['createtoken'] = $getsettings['createtoken'];
$data['editdata']['invoicelang'] = $getsettings['invoicelang'];
$data['editdata']['exemptvat'] = $getsettings['exemptvat'];
$data['editdata']['redirecturl'] = $getsettings['redirecturl'];
$data['editdata']['ipn'] = $getsettings['ipn'];
$data['editdata']['sortorder'] = $getsettings['sortorder'];
}
$data['editdata'] = $data['editdata'];
$this->response->setoutput($this->load->view('extension/payment/icredit.tpl', $data));
}
protected function validate() {
/* Block to check the user permission to manipulate the module*/
if (!$this->user->hasPermission('modify', 'extension/payment/icredit')) {
$this->error['warning'] = $this->language->get('error_permission');
}
/* End Block*/
/* Block to check if the helloworld_text_field is properly set to save into database, otherwise the error is returned*/
/*
if (!$this->request->post['PaymentMethodDescription']) {
$this->error['description'] = $this->language->get('error_description');
}
*/
/* End Block*/
/* if (!$this->request->post['redirecturl']) {
$this->error['redirecturl'] = $this->language->get('error_redirecturl');
}*/
return !$this->error;
}
/* End Validation Function*/
}
?>
Your controller file should look like this:
<?php
class ControllerExtensionPaymentIcredit extends Controller {
private $error = array();
public function install()
{
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "iCredit` (
`id_icredit` int(1) NOT NULL AUTO_INCREMENT,
`enabled` varchar(255),
`PaymentMethodDescription` varchar(500) CHARACTER SET utf8,
`title` varchar(255) CHARACTER SET utf8,
`testmode` varchar(1),
`testtoken` varchar(255),
`grouptoken` varchar(500),
`maxpayment` varchar(255),
`creditpayment` varchar(500),
`windowtype` varchar(255),
`height` int(10),
`width` int(10),
`hideitemlist` varchar(1),
`createtoken` varchar(1),
`invoicelang` varchar(500),
`exemptvat` varchar(255),
`redirecturl` varchar(500),
`ipn` varchar(500),
`sortorder` varchar(500),
`date_added` datetime,
PRIMARY KEY (`id_icredit`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; ");
}
public function uninstall()
{
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "iCredit");
}
public function index()
{ // Default function
$this->install();
$this->load->language('extension/payment/icredit'); // Loading the language file of helloworld
$this->document->setTitle($this->language->get('heading_title')); // Set the title of the page to the heading title in the Language file i.e., Hello World
$this->load->model('setting/setting');
$this->load->model('extension/payment/icredit'); // Load the Setting Model (All of the OpenCart Module & General Settings are saved using this Model )
//fwrite($file,$this->validate()." -- validate\r\n");
//fwrite($file,print_r($_POST,TRUE)." -- post\r\n");
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate())
{
if ($this->request->post['icredit_id'] == "")
{
$this->model_setting_setting->editSetting('payment_icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->addicreditsettings($this->request->post);
}
else
{
$this->model_setting_setting->editSetting('payment_icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->editicreditsettings($this->request->post);
}
$this->session->data['success'] = $this->language->get('text_success'); // To display the success text on data save=
if($check == 1)
{
$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); // Redirect to the Module Listing
}
}
/*Assign the language data for parsing it to view*/
$data['heading_title'] = $this->language->get('heading_title');
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
// return warning if any*/
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['description'])) {
$data['description'] = $this->error['description'];
} else {
$data['description'] = '';
}
/* Making of Breadcrumbs to be displayed on site*/
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/payment/icredit', 'user_token=' . $this->session->data['user_token'], true)
);
$data['action'] = $this->url->link('extension/payment/icredit', 'user_token=' . $this->session->data['user_token'], true);
$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true);
/* This block checks, if the hello world text field is set it parses it to view otherwise get the default hello world text field from the database and parse it*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['PaymentMethodDescription'] = $this->request->post['PaymentMethodDescription'];
} else {
$data['PaymentMethodDescription'] = $this->config->get('PaymentMethodDescription');
}
if (isset($this->request->post['payment_icredit_complete_order_status_id'])) {
$data['payment_icredit_complete_order_status_id'] = $this->request->post['payment_icredit_complete_order_status_id'];
} else {
$data['payment_icredit_complete_order_status_id'] = $this->config->get('payment_icredit_complete_order_status_id');
}
if (isset($this->request->post['payment_icredit_pending_order_status_id'])) {
$data['payment_icredit_pending_order_status_id'] = $this->request->post['payment_icredit_pending_order_status_id'];
} else {
$data['payment_icredit_pending_order_status_id'] = $this->config->get('payment_icredit_pending_order_status_id');
}
if (isset($this->request->post['payment_icredit_processing_order_status_id'])) {
$data['payment_icredit_processing_order_status_id'] = $this->request->post['payment_icredit_processing_order_status_id'];
} else {
$data['payment_icredit_processing_order_status_id'] = $this->config->get('payment_icredit_processing_order_status_id');
}
/* End Block*/
$data['modules'] = array();
/* This block parses the Module Settings such as Layout, Position,Status & Order Status to the view*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['modules'] = $this->request->post['PaymentMethodDescription'];
} elseif ($this->config->get('PaymentMethodDescription')) {
$data['modules'] = $this->config->get('PaymentMethodDescription');
}
/* End Block*/
$this->load->model('design/layout'); // Loading the Design Layout Models
$data['layouts'] = $this->model_design_layout->getLayouts(); // Getting all the Layouts available on system
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$getsettings = $this->model_extension_payment_icredit->addGeticreditsettings();
$data['editdata']=array();
if(isset($getsettings))
{
$data['editdata']['icredit_id'] = $getsettings['id_icredit'];
$data['editdata']['enabled'] = $getsettings['enabled'];
$data['editdata']['PaymentMethodDescription'] = $getsettings['PaymentMethodDescription'];
$data['editdata']['title'] = $getsettings['title'];
$data['editdata']['testmode'] = $getsettings['testmode'];
$data['editdata']['testtoken'] = $getsettings['testtoken'];
$data['editdata']['grouptoken'] = $getsettings['grouptoken'];
$data['editdata']['maxpayment'] = $getsettings['maxpayment'];
$data['editdata']['creditpayment'] = $getsettings['creditpayment'];
$data['editdata']['windowtype'] = $getsettings['windowtype'];
$data['editdata']['height'] = $getsettings['height'];
$data['editdata']['width'] = $getsettings['width'];
$data['editdata']['hideitemlist'] = $getsettings['hideitemlist'];
$data['editdata']['createtoken'] = $getsettings['createtoken'];
$data['editdata']['invoicelang'] = $getsettings['invoicelang'];
$data['editdata']['exemptvat'] = $getsettings['exemptvat'];
$data['editdata']['redirecturl'] = $getsettings['redirecturl'];
$data['editdata']['ipn'] = $getsettings['ipn'];
$data['editdata']['sortorder'] = $getsettings['sortorder'];
}
$data['editdata'] = $data['editdata'];
$this->response->setoutput($this->load->view('extension/payment/icredit.twig', $data));
}
protected function validate() {
/* Block to check the user permission to manipulate the module*/
if (!$this->user->hasPermission('modify', 'extension/payment/icredit')) {
$this->error['warning'] = $this->language->get('error_permission');
}
/* End Block*/
/* Block to check if the helloworld_text_field is properly set to save into database, otherwise the error is returned*/
/*
if (!$this->request->post['PaymentMethodDescription']) {
$this->error['description'] = $this->language->get('error_description');
}
*/
/* End Block*/
/* if (!$this->request->post['redirecturl']) {
$this->error['redirecturl'] = $this->language->get('error_redirecturl');
}*/
return !$this->error;
}
/* End Validation Function*/
}
I'm not sure it is will works because i do not see another files.
In your twig file you must find this strings:
icredit_complete_order_status_id
icredit_pending_order_status_id
icredit_processing_order_status_id
and replace with:
payment_icredit_complete_order_status_id
payment_icredit_pending_order_status_id
payment_icredit_processing_order_status_id

laravel-filemanager, Sort by time default

I need load files order by "time DESC" when the iframe of laravel-filemanager is called.
Is posible? I read the code and see that we cant order by time DESC and the code dont have options to configure a default "sort_type"
https://github.com/UniSharp/laravel-filemanager
this is not good idea but it's work for me
i am change the code in vendor/unisharp/laravel-filemanager/public/js/script.js
var sort_type = 'alphabetic';
to
var sort_type = 'time';
if you want to sort date in desc order. change the code in
vendor/unisharp/laravel-filemanager/src/Controllers/ItemsController.php
public function getItems()
{
$currentPage = self::getCurrentPageFromRequest();
$perPage = $this->helper->getPaginationPerPage();
$items = array_merge($this->lfm->folders(), $this->lfm->files());
return [
'items' => array_map(function ($item) {
return $item->fill()->attributes;
}, array_slice($items, ($currentPage - 1) * $perPage, $perPage)),
'paginator' => [
'current_page' => $currentPage,
'total' => count($items),
'per_page' => $perPage,
],
'display' => $this->helper->getDisplayMode(),
'working_dir' => $this->lfm->path('working_dir'),
];
}
with
use Illuminate\Http\Request;
public function getItems(Request $request)
{
$currentPage = self::getCurrentPageFromRequest();
$perPage = $this->helper->getPaginationPerPage();
$files = $this->lfm->files();
if($request->sort_type=='time'){
$files = array_reverse($files);
}
$items = array_merge($this->lfm->folders(), $files);
return [
'items' => array_map(function ($item) {
return $item->fill()->attributes;
}, array_slice($items, ($currentPage - 1) * $perPage, $perPage)),
'paginator' => [
'current_page' => $currentPage,
'total' => count($items),
'per_page' => $perPage,
],
'display' => $this->helper->getDisplayMode(),
'working_dir' => $this->lfm->path('working_dir'),
];
}
i'm change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php
and it's worked
public function sortFilesAndDirectories($arr_items, $sort_type)
{
if ($sort_type == 'time') {
$key_to_sort = 'updated';
} elseif ($sort_type == 'alphabetic') {
$key_to_sort = 'name';
} else {
$key_to_sort = 'updated';
}
return strcmp($a->{$key_to_sort}, $b->{$key_to_sort});
});
return $arr_items;
}
with
public function sortFilesAndDirectories($arr_items, $sort_type)
{
if ($sort_type == 'time') {
$key_to_sort = 'updated';
} elseif ($sort_type == 'alphabetic') {
$key_to_sort = 'name';
} else {
$key_to_sort = 'updated';
}
uasort($arr_items, function ($a, $b) use ($key_to_sort) {
if ( $a->$key_to_sort == $a->$key_to_sort )
return 0;
else if ( $a->$key_to_sort > $a->$key_to_sort)
return -1;
else
return 1;
});
return $arr_items;
}
LFM 1.8:
Also, you can use this method, if you don't want to change the LFM Src code.
First use this command to generate views :
php artisan vendor:publish --tag=lfm_view
Find this file:
ROOT/resources/views/vendor/laravel-filemanager/grid-view.blade.php
and change the cod according the follow:
#if((sizeof($files) > 0) || (sizeof($directories) > 0))
<div class="row">
<!-- -----------------------------------Begin of added block -->
<?php
$file_temp = [];
if($files != null){
foreach ($files as $key => $value) {
$file_temp[$value['updated']] = $value;
}
krsort($file_temp);
$file_temp1 = [];
$i = 0;
foreach ($file_temp as $key => $value) {
$file_temp1[$i] = $value;
$i+=1;
}
$files = $file_temp1;
}
?>
<!-- ---------------------------------------End of added block -->
#foreach($items as $item)
....
...
As you can see, the <?php ?> code block was added.You can use krsort() or ksort() as you want for descending or ascending.
In 2.3 I did next steps
php artisan vendor:publish --tag=lfm_view
Then you can find file
ROOT/resources/views/vendor/laravel-filemanager/grid-view.blade.php
And after incuding
<script>{!! \File::get(base_path('vendor/unisharp/laravel-filemanager/public/js/script.js')) !!}</script>
I added one line of js
sort_type = 'time';
But files sorts from the oldest to the newest. Thast's why I redefined routes and ItemsController

OpenCart order tracking without login

i'm using opencart 1.5.6.3, i'm trying to display a page with 2 field. 1 field will be use for Email and another field for Order ID. So client can see their order status directly without login.
thanks in advance.
After so much try, I got solution.
Add new file to
catalog> controller> account> guest.php
<?php class ControllerAccountGuest extends Controller {
private $error = array();
public function index() {
$this->language->load('account/guest');
$this->document->setTitle($this->language->get('heading_title'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_email'] = $this->language->get('entry_email');
$this->data['entry_ip'] = $this->language->get('entry_ip');
$this->data['entry_order_id'] = $this->language->get('entry_order_id');
$this->data['text_err'] = $this->language->get('text_err');
$this->data['text_ip'] = $this->language->get('text_ip');
$this->data['text_order_id'] = $this->language->get('text_order_id');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['action'] = $this->url->link('account/guest/info', '', 'SSL');
$this->data['continue'] = $this->url->link('account/guest', '', 'SSL');
if (isset($this->request->get['email'])) {
$this->data['email'] = $this->request->get['email'];
} else {
$this->data['email'] = '';
}
if (isset($this->request->get['ip'])) {
$this->data['ip'] = $this->request->get['ip'];
} else {
$this->data['ip'] = '';
}
if (isset($this->request->get['order_id'])) {
$this->data['order_id'] = $this->request->get['order_id'];
} else {
$this->data['order_id'] = '';
}
// Nacteni chybovych hlaseni
$err = array(
'email' => false,
'ip' => false,
'order_id' => false,
);
if (isset($this->request->get['err'])) {
$err_temp = explode('|', $this->request->get['err']);
foreach ($err_temp as $value) {
$err[$value] = true;
} // foreach
}
$this->data['err'] = $err;
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/guest_login.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/guest_login.tpl';
} else {
$this->template = 'default/template/account/guest_login.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
public function info() {
$err = false;
$url = '';
if ( isset($this->request->post['email']) AND strlen($this->request->post['email']) > 4 ) {
$email = $this->request->post['email'];
$url .= '&email=' . $this->request->post['email'];
} else {
$email = '';
$err = ( $err ? $err . '|' . 'email' : 'email' );
}
/*
if (isset($this->request->post['ip'])) {
$ip = $this->request->post['ip'];
$url .= '&ip=' . $this->request->post['ip'];
} else {
$ip = '0';
$err = ( $err ? $err . '|' . 'ip' : 'ip' );
}
*/
if ( isset($this->request->post['order_id']) AND is_numeric($this->request->post['order_id']) ) {
$order_id = $this->request->post['order_id'];
$url .= '&order_id=' . $this->request->post['order_id'];
} else {
$order_id = '0';
$err = ( $err ? $err . '|' . 'order_id' : 'order_id' );
}
if ($err) {
$url .= '&err=' . $err;
$this->redirect($this->url->link('account/guest', 'token=' . $this->session->data['token'] . $url, 'SSL'));
}
$this->language->load('account/guest_history');
$this->load->model('account/guest');
//$order_info = $this->model_account_guest->getOrder($order_id, $email, $ip);
$order_info = $this->model_account_guest->getOrder($order_id, $email);
if ($order_info) {
$this->document->setTitle($this->language->get('text_order'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('text_order');
$this->data['text_order_detail'] = $this->language->get('text_order_detail');
$this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
$this->data['text_order_id'] = $this->language->get('text_order_id');
$this->data['text_date_added'] = $this->language->get('text_date_added');
$this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
$this->data['text_shipping_address'] = $this->language->get('text_shipping_address');
$this->data['text_payment_method'] = $this->language->get('text_payment_method');
$this->data['text_payment_address'] = $this->language->get('text_payment_address');
$this->data['text_history'] = $this->language->get('text_history');
$this->data['text_comment'] = $this->language->get('text_comment');
$this->data['text_action'] = $this->language->get('text_action');
$this->data['text_selected'] = $this->language->get('text_selected');
$this->data['text_reorder'] = $this->language->get('text_reorder');
$this->data['text_return'] = $this->language->get('text_return');
$this->data['column_name'] = $this->language->get('column_name');
$this->data['column_model'] = $this->language->get('column_model');
$this->data['column_quantity'] = $this->language->get('column_quantity');
$this->data['column_price'] = $this->language->get('column_price');
$this->data['column_total'] = $this->language->get('column_total');
$this->data['column_date_added'] = $this->language->get('column_date_added');
$this->data['column_status'] = $this->language->get('column_status');
$this->data['column_comment'] = $this->language->get('column_comment');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['action'] = $this->url->link('account/order/info', 'order_id=' . $order_id , 'SSL');
if ($order_info['invoice_no']) {
$this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
} else {
$this->data['invoice_no'] = '';
}
$this->data['order_id'] = $order_id ;
$this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
if ($order_info['shipping_address_format']) {
$format = $order_info['shipping_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country' => $order_info['shipping_country']
);
$this->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
$this->data['shipping_method'] = $order_info['shipping_method'];
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
'zone' => $order_info['payment_zone'],
'zone_code' => $order_info['payment_zone_code'],
'country' => $order_info['payment_country']
);
$this->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
$this->data['payment_method'] = $order_info['payment_method'];
$this->data['products'] = array();
$products = $this->model_account_guest->getOrderProducts($order_id );
foreach ($products as $product) {
$option_data = array();
$options = $this->model_account_guest->getOrderOptions($order_id , $product['order_product_id']);
foreach ($options as $option) {
if ($option['type'] != 'file') {
$option_data[] = array(
'name' => $option['name'],
'value' => (strlen($option['value']) > 20 ? substr($option['value'], 0, 20) . '..' : $option['value']),
);
} else {
$filename = substr($option['value'], 0, strrpos($option['value'], '.'));
$option_data[] = array(
'name' => $option['name'],
'value' => (strlen($filename) > 20 ? substr($filename, 0, 20) . '..' : $filename)
);
}
} // foreach
$this->data['products'][] = array(
'order_product_id' => $product['order_product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'price' => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']),
'total' => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value']),
'selected' => isset($this->request->post['selected']) && in_array($result['order_product_id'], $this->request->post['selected'])
);
}
$this->data['totals'] = $this->model_account_guest->getOrderTotals($order_id );
$this->data['comment'] = $order_info['comment'];
$this->data['histories'] = array();
$results = $this->model_account_guest->getOrderHistories($order_id );
foreach ($results as $result) {
$this->data['histories'][] = array(
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'status' => $result['status'],
'comment' => nl2br($result['comment'])
);
} // foreach
$this->data['continue'] = $this->url->link('account/order', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/guest_history.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/guest_history.tpl';
} else {
$this->template = 'default/template/account/guest_history.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
} else {
$this->document->setTitle($this->language->get('text_order'));
$this->data['heading_title'] = $this->language->get('text_order');
$this->data['text_error'] = $this->language->get('text_error');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['continue'] = $this->url->link('account/order', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
} else {
$this->template = 'default/template/error/not_found.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}} // info
private function validate() {
if (!isset($this->request->post['selected']) || !isset($this->request->post['action']) || !$this->request->post['action']) {
$this->error['warning'] = $this->language->get('error_warning');
}
if (!$this->error) {
return true;
} else {
return false;
}
} // validate } ?>
Add another new file to catalog> model> account> guest.php
<?php class ModelAccountGuest extends Model { //public function getOrder($order_id, $email, $ip) { public function getOrder($order_id, $email) {
$order_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "order`
WHERE order_id = '" . (int)$order_id . "'
AND email = '" . $this->db->escape($email) . "'
AND order_status_id > '0'
"); // AND ip = '" . $this->db->escape($ip) . "'
if ($order_query->num_rows) {
$country_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "country`
WHERE country_id = '" . (int)$order_query->row['shipping_country_id'] . "'
");
if ($country_query->num_rows) {
$shipping_iso_code_2 = $country_query->row['iso_code_2'];
$shipping_iso_code_3 = $country_query->row['iso_code_3'];
} else {
$shipping_iso_code_2 = '';
$shipping_iso_code_3 = '';
}
$zone_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "zone`
WHERE zone_id = '" . (int)$order_query->row['shipping_zone_id'] . "'
");
if ($zone_query->num_rows) {
$shipping_zone_code = $zone_query->row['code'];
} else {
$shipping_zone_code = '';
}
$country_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "country`
WHERE country_id = '" . (int)$order_query->row['payment_country_id'] . "'
");
if ($country_query->num_rows) {
$payment_iso_code_2 = $country_query->row['iso_code_2'];
$payment_iso_code_3 = $country_query->row['iso_code_3'];
} else {
$payment_iso_code_2 = '';
$payment_iso_code_3 = '';
}
$zone_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "zone`
WHERE zone_id = '" . (int)$order_query->row['payment_zone_id'] . "'
");
if ($zone_query->num_rows) {
$payment_zone_code = $zone_query->row['code'];
} else {
$payment_zone_code = '';
}
return array(
'order_id' => $order_query->row['order_id'],
'invoice_no' => $order_query->row['invoice_no'],
'invoice_prefix' => $order_query->row['invoice_prefix'],
'store_id' => $order_query->row['store_id'],
'store_name' => $order_query->row['store_name'],
'store_url' => $order_query->row['store_url'],
'customer_id' => $order_query->row['customer_id'],
'firstname' => $order_query->row['firstname'],
'lastname' => $order_query->row['lastname'],
'telephone' => $order_query->row['telephone'],
'fax' => $order_query->row['fax'],
'email' => $order_query->row['email'],
'shipping_firstname' => $order_query->row['shipping_firstname'],
'shipping_lastname' => $order_query->row['shipping_lastname'],
'shipping_company' => $order_query->row['shipping_company'],
'shipping_address_1' => $order_query->row['shipping_address_1'],
'shipping_address_2' => $order_query->row['shipping_address_2'],
'shipping_postcode' => $order_query->row['shipping_postcode'],
'shipping_city' => $order_query->row['shipping_city'],
'shipping_zone_id' => $order_query->row['shipping_zone_id'],
'shipping_zone' => $order_query->row['shipping_zone'],
'shipping_zone_code' => $shipping_zone_code,
'shipping_country_id' => $order_query->row['shipping_country_id'],
'shipping_country' => $order_query->row['shipping_country'],
'shipping_iso_code_2' => $shipping_iso_code_2,
'shipping_iso_code_3' => $shipping_iso_code_3,
'shipping_address_format' => $order_query->row['shipping_address_format'],
'shipping_method' => $order_query->row['shipping_method'],
'payment_firstname' => $order_query->row['payment_firstname'],
'payment_lastname' => $order_query->row['payment_lastname'],
'payment_company' => $order_query->row['payment_company'],
'payment_address_1' => $order_query->row['payment_address_1'],
'payment_address_2' => $order_query->row['payment_address_2'],
'payment_postcode' => $order_query->row['payment_postcode'],
'payment_city' => $order_query->row['payment_city'],
'payment_zone_id' => $order_query->row['payment_zone_id'],
'payment_zone' => $order_query->row['payment_zone'],
'payment_zone_code' => $payment_zone_code,
'payment_country_id' => $order_query->row['payment_country_id'],
'payment_country' => $order_query->row['payment_country'],
'payment_iso_code_2' => $payment_iso_code_2,
'payment_iso_code_3' => $payment_iso_code_3,
'payment_address_format' => $order_query->row['payment_address_format'],
'payment_method' => $order_query->row['payment_method'],
'comment' => $order_query->row['comment'],
'total' => $order_query->row['total'],
'order_status_id' => $order_query->row['order_status_id'],
'language_id' => $order_query->row['language_id'],
'currency_id' => $order_query->row['currency_id'],
'currency_code' => $order_query->row['currency_code'],
'currency_value' => $order_query->row['currency_value'],
'date_modified' => $order_query->row['date_modified'],
'date_added' => $order_query->row['date_added'],
'ip' => $order_query->row['ip']
);
} else {
return false;
}
} // getOrder
public function getOrderProducts($order_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_product
WHERE order_id = '" . (int)$order_id . "'
");
return $query->rows;
} // getOrderProducts
public function getOrderOptions($order_id, $order_product_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_option
WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'
");
return $query->rows;
} // getOrderOptions
public function getOrderTotals($order_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_total
WHERE order_id = '" . (int)$order_id . "'
ORDER BY sort_order
");
return $query->rows;
} // getOrderTotals
public function getOrderHistories($order_id) {
$query = $this->db->query("
SELECT date_added, os.name AS status, oh.comment, oh.notify
FROM " . DB_PREFIX . "order_history oh
LEFT JOIN " . DB_PREFIX . "order_status os ON oh.order_status_id = os.order_status_id
WHERE oh.order_id = '" . (int)$order_id . "'
AND os.language_id = '" . (int)$this->config->get('config_language_id') . "'
ORDER BY oh.date_added
"); // AND oh.notify = '1'
return $query->rows;
} // getOrderHistories
public function getOrderDownloads($order_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_download
WHERE order_id = '" . (int)$order_id . "'
ORDER BY name
");
return $query->rows;
} // getOrderDownloads
public function getTotalOrders() {
$query = $this->db->query("
SELECT COUNT(*) AS total
FROM `" . DB_PREFIX . "order`
WHERE customer_id = '" . (int)$this->customer->getId() . "' AND order_status_id > '0'
");
return $query->row['total'];
} // getTotalOrders
public function getTotalOrderProductsByOrderId($order_id) {
$query = $this->db->query("
SELECT COUNT(*) AS total
FROM " . DB_PREFIX . "order_product
WHERE order_id = '" . (int)$order_id . "'
");
return $query->row['total'];
} // getTotalOrderProductsByOrderId } // class ?>
Now add language file to catalog> language> english> account>
<?php // Heading $_['heading_title'] = 'Order Tracking'; // Text $_['text_account'] = 'Account'; // Entry $_['entry_email'] = 'E-Mail Address:'; $_['entry_ip'] = 'IP Address:'; $_['entry_order_id'] = 'Order Number:'; $_['text_err'] = '<span style="color:red;"> <<< </span>'; $_['text_ip'] = 'eg. 123.345.456.678 - Find this on you order email in the \'Order Details\' section:'; $_['text_order_id'] = 'eg. 123 - Find this on you order email in the \'Order Details\' section:'; // Error $_['error_login'] = 'Warning: No match for E-Mail Address and/or Order Number.'; ?>
Now add tlp file to catalog> view> theme> default> template> account> guest_login.tlp with form action and submit button then add this java script:
<script type="text/javascript"><!-- $('#login input').keydown(function(e) {
if (e.keyCode == 13) {
$('#login').submit();
} }); //--></script>
Now add another file to show result. Catalog> view> theme> default> template> account> guest_history.tlp
Checked in OpenCart 1.5.6.3 with custom theme.

cart gets empty after adding a product and moving to checkout or cart in opencart

Im having a very strange problem. When i add a product to my shopping cart on top header it shows the cart details/products. But when i click on the cart or checkout it says my cart is empty. So each time when i add the product and move to checkout or cart it automatically becomes empty.
I have tried the site on firefox, chrome and in different PCs but still the same problem. But the weird part is when i run firebug and move to the console to see the calls, the site works perfectly. But when i close firebug and refresh the page or move the cart becomes empty again.
Can someone tell me what might the problem be?
Im using Opencart 1.5.4
Checkout controller function
public function index() {
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$this->redirect($this->url->link('checkout/cart'));
}
// Validate minimum quantity requirments.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$this->redirect($this->url->link('checkout/cart'));
}
}
$this->language->load('checkout/checkout');
$this->document->setTitle($this->language->get('heading_title'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_cart'),
'href' => $this->url->link('checkout/cart'),
'separator' => $this->language->get('text_separator')
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('checkout/checkout', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_checkout_option'] = $this->language->get('text_checkout_option');
$this->data['text_checkout_account'] = $this->language->get('text_checkout_account');
$this->data['text_checkout_payment_address'] = $this->language->get('text_checkout_payment_address');
$this->data['text_checkout_shipping_address'] = $this->language->get('text_checkout_shipping_address');
$this->data['text_checkout_shipping_method'] = $this->language->get('text_checkout_shipping_method');
$this->data['text_checkout_payment_method'] = $this->language->get('text_checkout_payment_method');
$this->data['text_checkout_confirm'] = $this->language->get('text_checkout_confirm');
$this->data['text_modify'] = $this->language->get('text_modify');
$this->data['logged'] = $this->customer->isLogged();
$this->data['shipping_required'] = $this->cart->hasShipping();
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/checkout.tpl')) {
$this->template = $this->config->get('config_template') . '/template/checkout/checkout.tpl';
} else {
$this->template = 'default/template/checkout/checkout.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
cart controller
public function index() {
$this->language->load('checkout/cart');
if (!isset($this->session->data['vouchers'])) {
$this->session->data['vouchers'] = array();
}
// Update
if (!empty($this->request->post['quantity'])) {
foreach ($this->request->post['quantity'] as $key => $value) {
$this->cart->update($key, $value);
}
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['reward']);
$this->redirect($this->url->link('checkout/cart'));
}
// Remove
if (isset($this->request->get['remove'])) {
$this->cart->remove($this->request->get['remove']);
unset($this->session->data['vouchers'][$this->request->get['remove']]);
$this->session->data['success'] = $this->language->get('text_remove');
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['reward']);
$this->redirect($this->url->link('checkout/cart'));
}
// Coupon
if (isset($this->request->post['coupon']) && $this->validateCoupon()) {
$this->session->data['coupon'] = $this->request->post['coupon'];
$this->session->data['success'] = $this->language->get('text_coupon');
$this->redirect($this->url->link('checkout/cart'));
}
// Voucher
if (isset($this->request->post['voucher']) && $this->validateVoucher()) {
$this->session->data['voucher'] = $this->request->post['voucher'];
$this->session->data['success'] = $this->language->get('text_voucher');
$this->redirect($this->url->link('checkout/cart'));
}
// Reward
if (isset($this->request->post['reward']) && $this->validateReward()) {
$this->session->data['reward'] = abs($this->request->post['reward']);
$this->session->data['success'] = $this->language->get('text_reward');
$this->redirect($this->url->link('checkout/cart'));
}
// Shipping
if (isset($this->request->post['shipping_method']) && $this->validateShipping()) {
$shipping = explode('.', $this->request->post['shipping_method']);
$this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
$this->session->data['success'] = $this->language->get('text_shipping');
$this->redirect($this->url->link('checkout/cart'));
}
$this->document->setTitle($this->language->get('heading_title'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'href' => $this->url->link('common/home'),
'text' => $this->language->get('text_home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'href' => $this->url->link('checkout/cart'),
'text' => $this->language->get('heading_title'),
'separator' => $this->language->get('text_separator')
);
if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) {
$points = $this->customer->getRewardPoints();
$points_total = 0;
foreach ($this->cart->getProducts() as $product) {
if ($product['points']) {
$points_total += $product['points'];
}
}
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_next'] = $this->language->get('text_next');
$this->data['text_next_choice'] = $this->language->get('text_next_choice');
$this->data['text_use_coupon'] = $this->language->get('text_use_coupon');
$this->data['text_use_voucher'] = $this->language->get('text_use_voucher');
$this->data['text_use_reward'] = sprintf($this->language->get('text_use_reward'), $points);
$this->data['text_shipping_estimate'] = $this->language->get('text_shipping_estimate');
$this->data['text_shipping_detail'] = $this->language->get('text_shipping_detail');
$this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
$this->data['text_select'] = $this->language->get('text_select');
$this->data['text_none'] = $this->language->get('text_none');
$this->data['column_image'] = $this->language->get('column_image');
$this->data['column_name'] = $this->language->get('column_name');
$this->data['column_model'] = $this->language->get('column_model');
$this->data['column_quantity'] = $this->language->get('column_quantity');
$this->data['column_price'] = $this->language->get('column_price');
$this->data['column_total'] = $this->language->get('column_total');
$this->data['entry_coupon'] = $this->language->get('entry_coupon');
$this->data['entry_voucher'] = $this->language->get('entry_voucher');
$this->data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total);
$this->data['entry_country'] = $this->language->get('entry_country');
$this->data['entry_zone'] = $this->language->get('entry_zone');
$this->data['entry_postcode'] = $this->language->get('entry_postcode');
$this->data['button_update'] = $this->language->get('button_update');
$this->data['button_remove'] = $this->language->get('button_remove');
$this->data['button_coupon'] = $this->language->get('button_coupon');
$this->data['button_voucher'] = $this->language->get('button_voucher');
$this->data['button_reward'] = $this->language->get('button_reward');
$this->data['button_quote'] = $this->language->get('button_quote');
$this->data['button_shipping'] = $this->language->get('button_shipping');
$this->data['button_shopping'] = $this->language->get('button_shopping');
$this->data['button_checkout'] = $this->language->get('button_checkout');
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} elseif (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) {
$this->data['error_warning'] = $this->language->get('error_stock');
} else {
$this->data['error_warning'] = '';
}
if ($this->config->get('config_customer_price') && !$this->customer->isLogged()) {
$this->data['attention'] = sprintf($this->language->get('text_login'), $this->url->link('account/login'), $this->url->link('account/register'));
} else {
$this->data['attention'] = '';
}
if (isset($this->session->data['success'])) {
$this->data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$this->data['success'] = '';
}
$this->data['action'] = $this->url->link('checkout/cart');
if ($this->config->get('config_cart_weight')) {
$this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point'));
} else {
$this->data['weight'] = '';
}
$this->load->model('tool/image');
$this->data['products'] = array();
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$this->data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']);
}
if ($product['image']) {
$image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
} else {
$image = '';
}
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['option_value'];
} else {
$filename = $this->encryption->decrypt($option['option_value']);
$value = utf8_substr($filename, 0, utf8_strrpos($filename, '.'));
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
);
}
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']);
} else {
$total = false;
}
$this->data['products'][] = array(
'key' => $product['key'],
'thumb' => $image,
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'stock' => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')),
'reward' => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
'price' => $price,
'total' => $total,
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']),
'remove' => $this->url->link('checkout/cart', 'remove=' . $product['key'])
);
}
// Gift Voucher
$this->data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$this->data['vouchers'][] = array(
'key' => $key,
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount']),
'remove' => $this->url->link('checkout/cart', 'remove=' . $key)
);
}
}
if (isset($this->request->post['next'])) {
$this->data['next'] = $this->request->post['next'];
} else {
$this->data['next'] = '';
}
$this->data['coupon_status'] = $this->config->get('coupon_status');
if (isset($this->request->post['coupon'])) {
$this->data['coupon'] = $this->request->post['coupon'];
} elseif (isset($this->session->data['coupon'])) {
$this->data['coupon'] = $this->session->data['coupon'];
} else {
$this->data['coupon'] = '';
}
$this->data['voucher_status'] = $this->config->get('voucher_status');
if (isset($this->request->post['voucher'])) {
$this->data['voucher'] = $this->request->post['voucher'];
} elseif (isset($this->session->data['voucher'])) {
$this->data['voucher'] = $this->session->data['voucher'];
} else {
$this->data['voucher'] = '';
}
$this->data['reward_status'] = ($points && $points_total && $this->config->get('reward_status'));
if (isset($this->request->post['reward'])) {
$this->data['reward'] = $this->request->post['reward'];
} elseif (isset($this->session->data['reward'])) {
$this->data['reward'] = $this->session->data['reward'];
} else {
$this->data['reward'] = '';
}
$this->data['shipping_status'] = $this->config->get('shipping_status') && $this->config->get('shipping_estimator') && $this->cart->hasShipping();
if (isset($this->request->post['country_id'])) {
$this->data['country_id'] = $this->request->post['country_id'];
} elseif (isset($this->session->data['shipping_country_id'])) {
$this->data['country_id'] = $this->session->data['shipping_country_id'];
} else {
$this->data['country_id'] = $this->config->get('config_country_id');
}
$this->load->model('localisation/country');
$this->data['countries'] = $this->model_localisation_country->getCountries();
if (isset($this->request->post['zone_id'])) {
$this->data['zone_id'] = $this->request->post['zone_id'];
} elseif (isset($this->session->data['shipping_zone_id'])) {
$this->data['zone_id'] = $this->session->data['shipping_zone_id'];
} else {
$this->data['zone_id'] = '';
}
if (isset($this->request->post['postcode'])) {
$this->data['postcode'] = $this->request->post['postcode'];
} elseif (isset($this->session->data['shipping_postcode'])) {
$this->data['postcode'] = $this->session->data['shipping_postcode'];
} else {
$this->data['postcode'] = '';
}
if (isset($this->request->post['shipping_method'])) {
$this->data['shipping_method'] = $this->request->post['shipping_method'];
} elseif (isset($this->session->data['shipping_method'])) {
$this->data['shipping_method'] = $this->session->data['shipping_method']['code'];
} else {
$this->data['shipping_method'] = '';
}
// Totals
$this->load->model('setting/extension');
$total_data = array();
$total = 0;
$taxes = $this->cart->getTaxes();
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$sort_order = array();
$results = $this->model_setting_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get($result['code'] . '_status')) {
$this->load->model('total/' . $result['code']);
$this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
}
$sort_order = array();
foreach ($total_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $total_data);
}
}
$this->data['totals'] = $total_data;
$this->data['continue'] = $this->url->link('common/home');
$this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/cart.tpl')) {
$this->template = $this->config->get('config_template') . '/template/checkout/cart.tpl';
} else {
$this->template = 'default/template/checkout/cart.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_bottom',
'common/content_top',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
} else {
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_error'] = $this->language->get('text_empty');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['continue'] = $this->url->link('common/home');
unset($this->session->data['success']);
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
} else {
$this->template = 'default/template/error/not_found.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
}
session library
class Session {
public $data = array();
public function __construct() {
if (!session_id()) {
ini_set('session.use_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
session_set_cookie_params(0, '/');
session_start();
}
$this->data =& $_SESSION;
}
function getId() {
return session_id();
}
}
It's extremely hard to say, where's the root of the problem. If you have any 3rd party extensions (VQMods), they can change original OpenCart code. In this case you should look in cached files, not original ones. That's for the start.

Opencart Info Page

OK, I have been searching for quite some time, and this has me baffled.
I'm trying to add an ad that will pull up more info in the main content section.
If you look at http://teachingforapples.com/ , you'll see 2 links below the orange ad on the left. The only difference between those links is the information ID. However, they behave very differently. The one that says 'about' opens inside the main content area, but the one that says 'referral' opens full window.
There's nothing in the document content that would change this behavior.
The links are made exactly the same in the code except for the ID #.
The generated code shows the same kind of link, neither one has a target attrib.
I can't find anything in any of the modules that has logic code that looks at the doc id #.
So, I started looking at the database. I looked at all the information tables, but don't see anything different between the 2 pages.
Can someone point me in the right direction please? I feel that it must be something simple, but I just can't find it.
Thanks
P.S. the Information module is NOT installed.
Here's the information.php file.
<?php
class ControllerInformationInformation extends Controller {
public function index() {
$this->language->load('information/information');
$this->load->model('catalog/information');
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
if (isset($this->request->get['information_id'])) {
$information_id = (int)$this->request->get['information_id'];
} else {
$information_id = 0;
}
$information_info = $this->model_catalog_information->getInformation($information_id);
if ($information_info) {
$this->document->setTitle($information_info['title']);
$this->data['breadcrumbs'][] = array(
'text' => $information_info['title'],
'href' => $this->url->link('information/information', 'information_id=' . $information_id),
'separator' => $this->language->get('text_separator')
);
$this->data['info_id'] = $information_id;
$this->data['heading_title'] = $information_info['title'];
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['description'] = html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8');
$this->data['continue'] = $this->url->link('common/home');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/information.tpl')) {
$this->template = $this->config->get('config_template') . '/template/information/information.tpl';
} else {
$this->template = 'default/template/information/information.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
} else {
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_error'),
'href' => $this->url->link('information/information', 'information_id=' . $information_id),
'separator' => $this->language->get('text_separator')
);
$this->document->setTitle($this->language->get('text_error'));
$this->data['heading_title'] = $this->language->get('text_error');
$this->data['text_error'] = $this->language->get('text_error');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['continue'] = $this->url->link('common/home');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
} else {
$this->template = 'default/template/error/not_found.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
}
public function info() {
$this->load->model('catalog/information');
if (isset($this->request->get['information_id'])) {
$information_id = (int)$this->request->get['information_id'];
} else {
$information_id = 0;
}
$information_info = $this->model_catalog_information->getInformation($information_id);
if ($information_info) {
$output = '<html dir="ltr" lang="en">' . "\n";
$output .= '<head>' . "\n";
$output .= ' <title>' . $information_info['title'] . '</title>' . "\n";
$output .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n";
$output .= ' <meta name="robots" content="noindex">' . "\n";
$output .= '</head>' . "\n";
$output .= '<body>' . "\n";
$output .= ' <h1>' . $information_info['title'] . '</h1>' . "\n";
$output .= html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8') . "\n";
$output .= ' </body>' . "\n";
$output .= '</html>' . "\n";
$this->response->setOutput($output);
}
}
}
?>