Add new comment

ArticleUpgrading modules from OpenCart 1.5.x to OpenCart 2.0.x or changes in the OpenCart 2.0.x

OpenCart 2.0 has been released and it is very different from OpenCart 1.5. Extensions from 1.5 will not work on the 2.0. You need to upgrade them from OpenCart 1.5 to OpenCart 2.0. I decided to write this article where I am planning to describe how to do it and describe differences in the OpenCart 2.0.

I can't give you all the differences in the OpenCart 2.0, because OpenCart is quite a big system and it is always changing. I will give you changes that I discovered.
 
Changes:
 
  • Coding standards. They changed a little. You don't need to put PHP ending tag "?>" In the end of your PHP files. This is correct, many CMS doesn't use this tag for a long time. 
  • bootstrap It'll take you most of the time. What is bootstrap? It is a css framework that helps to build user interfaces with tables, buttons, grids etc. It is really very useful. You don't need to create html and css code for every device and screen resolution. The bootstrap will do it for you. But it will take you time to learn how it works. 
    You can read about bootstrap here. If you don't know how to build something using the bootstrap, I'll give you an advice. Just open the admin product form template and look how it is created. The product form template is a very big template with a big amount of elements. It probably contains the element what you need to create. 
  • OCMOD instead of VQMOD. It is almost the same. It has similar syntax, but OCMOD is built in the OpenCart. OCMOD planned to be more simple for reduce amount of the conflicts. For example, it wasn't supposed to contain the offsets. But after several commits it contains offsets now. So OCMOD has practically the same functionality as the VQMOD. 
  • Events As for me, the Events are the biggest innovation in the OpenCart 2.0. Events give you ability to change OpenCart logic from your modules without changing the OpenCart core files.  The almost every modern CMS has similar functionality. For example Drupal has the hook system. The Events in the OpenCart are in under development now, they are not covering all OpenCart yet, but I hope that they will improve and in some time they will replace the VQMOD (OCMOD). 
  • The controller
1. Assigning template variables  
OpenCart 1.5:

$this->data['foo'] = $foo;

OpenCart 2.0:

$data['foo'] = $foo;

 
2. Assigning a template
OpenCart 1.5:

$this->template = 'module/module.tpl';

OpenCart 2.0:

$this->response->setOutput($this->load->view('module/module', $data));

 
3. Adding child controllers
OpenCart 1.5:

$this->children = array(
  'common/header',
  'common/footer'
);

OpenCart 2.0 (you can load controllers now):

$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');

 
4. Redirect
OpenCart 1.5:

$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));

OpenCart 2.0:

$this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));

 
5. Status field is mandatory for the module now:

if (isset($this->request->post['module_name_status'])) {
  $data['featured_status'] = $this->request->post['module_name_status'];
} else {
  $data['featured_status'] = $this->config->get('module_name_status');
}

 
If during upgrade your modules you will find a new change not described here, please write a comment and I will add it in the article.
 

Filtered HTML ckeditor

Plain text

CAPTCHA
Spam protection
Image CAPTCHA
Enter the characters shown in the image.
You are reporting a typo in the following text:
Simply click the "Send typo report" button to complete the report. You can also include a comment.