Add new comment

Changes in OpenCart 2.2.2.0.0_a1

Yesterday OpenCart 2.2.0.0_a1 has been released.
This is an alfa version, it released for developers and it is strongly not recommended to use it on the working shop.
It has plenty changes and I decided to write entire article about it.
So, what is new in OpenCart 2.2.0.0 a1?
 

Admin area

1. Themes settings now are available by this route:
admin/index.php?route=theme/theme_default
That is definitely more comfortable than search them in the store's settings page.
Now you can also have different settings for the different themes.
 
2. New payment methods: 
  • Lay-Buy
  • Cardinity
  • Eway
3. New modules:
  • Lay-Buy
  • sagepay
 

Structure

1. OpenCart is compatible with the composer now:
composer.json
From version 2.2 composer has been added to aid developers who want to use composer libraries. 2 versions of OpenCart
will become available, one compiled and one non-compiled (composer.json only - no files in vendor folder).
 
2. index.php has been changed very much. It has just about 20 lines of the code. 
 

// Version
define('VERSION', '2.2.0.0_a1');
 
// Configuration
if (is_file('config.php')) {
  require_once('config.php');
}
 
// Install
if (!defined('DIR_APPLICATION')) {
  header('Location: install/index.php');
  exit;
}
 
// Startup
require_once(DIR_SYSTEM . 'startup.php');
 
$application_config = 'catalog';
 
// Application
require_once(DIR_SYSTEM . 'framework.php');

As we can see all the code from index.php was added to the file framework.php
It is good, because there are no duplicate of the code and all the code is located in one place. 
 
3. New folder 
/catalog/controller/startup
in which was moved all the files which are loaded in startup:
  • startup.php
  • session.php
  • seo_url.php
  • router.php 
  • maintenance.php
  • event.php
  • error.php
 
4. New folder
/catalog/controller/event
with files:
  • theme.php
  • debug.php
 
5. New class /system/engine/proxy.php
6. All the files for the cart was moved to 
/system/library/cart:
  • weight.php
  • user.php
  • tax.php
  • length.php
  • customer.php
  • currency.php
  • cart.php
  • affiliate.php
7. New folder 
/system/library/session
with files:
  • db.php
  • file.php
As we can see from the names, this is needed for ability to save sessions in the database, the class has written, but it is not included, maybe it will be done in the future 
 
8. Localisation now is located in 
language/en-gb
instead of
language/english
 

Code

1. Links creation has been changed
was:

'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')

now:

'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)

SSL is included in the constructor of the library:
system/library/url.php

public function __construct($ssl = false) {

 
2. Loading views has been changed
was:

$this->response->setOutput($this->load->view('analytics/google_analytics.tpl', $data));

now:

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

Now we don't need to write an extension of the template, it is added automatically
Also template render now is in the adaptor:
upload/system/library/template.php

public function render($template) {
  return $this->adaptor->render($template);
}

Adaptor's name has been changed
/system/library/template/basic.php 
in 2.1 it was php.php
There are the namespaces:
namespace Template;
 
I don't really understand why adaptor is needed for the templates because we have only one adaptor which is hardcoded: 

$template = new Template('basic');

Maybe in the future we will have ability to have several Template Engine like SMARTY or twig. But I believe that this will never happen because after that you will need to create several templates for each module and modules creation will become a real hell.
 
3. Localisation
Loading language file is changing for a very long time. I want to think that it is the last.
was:

$this->language->load('catalog/attribute_group');

now:

$this->load->language('catalog/attribute_group');

It is still possible to load language by $this->language->load but now it is strongly recommended to do it from the loader because in that case triggers can be fired:

$this->registry->get('event')->trigger('language/' . $route . '/before', $route);
$this->registry->get('language')->load($route);      
$this->registry->get('event')->trigger('language/' . $route . '/after', $route);

Language image now is in the language's folder, not in the image folder
was:

<img src="image/flags/<?php echo $language['image']; ?>" alt="<?php echo $language['name']; ?>" title="<?php echo $language['name']; ?>">

now:

<img src="catalog/language/<?php echo $language['code']; ?>/<?php echo $language['code']; ?>.png" alt="<?php echo $language['name']; ?>" title=">

 
4. Events
They have been rewritten again. It is probably tenth times from the time they are appeared
was:

if (version_compare(VERSION, '2.0.1', '>=')) {
  $this->load->model('extension/event');
  $this->model_extension_event->addEvent('openbay', 'post.admin.product.delete', 'extension/openbay/eventDeleteProduct');
  $this->model_extension_event->addEvent('openbay', 'post.admin.product.edit', 'extension/openbay/eventEditProduct');
} else {
  $this->load->model('tool/event');
  $this->model_tool_event->addEvent('openbay', 'post.product.delete', 'extension/openbay/eventDeleteProduct');
  $this->model_tool_event->addEvent('openbay', 'post.product.edit', 'extension/openbay/eventEditProduct');
}

now:

$this->load->model('extension/event');
$this->model_extension_event->addEvent('openbay', 'admin/model/catalog/product/deleteProduct/before', 'extension/openbay/eventDeleteProduct');
$this->model_extension_event->addEvent('openbay', 'admin/model/catalog/product/editProduct/before', 'extension/openbay/eventEditProduct');

 
Deleting was:

if (version_compare(VERSION, '2.0.1', '>=')) {
  $this->load->model('extension/event');
  $this->model_extension_event->deleteEvent('openbay');
} else {
  $this->load->model('tool/event');
  $this->model_tool_event->deleteEvent('openbay');
}

now:

$this->model_extension_event->deleteEvent('openbay');

 
Triggers adding was

$this->event->trigger('pre.view.' . str_replace('/', '.', $template), $data);

now

$result = $this->registry->get('event')->trigger('view/' . $route . '/before', array(&$route, &$data));

Almost all the triggers were deleted from the models and controllers. There were plenty of them in the models and controllers of the customer and order 
Now triggers are only in
  • system/engine/loader.php
  • catalog/model/openbay/etsy_order.php
  • catalog/model/openbay/ebay_openbay.php
  • catalog/controller/startup/router.php
  • admin/controller/startup/router.php
That is all!
 
5. Emails validation has been changed
was:

if (utf8_strlen($email) > 0 && preg_match('/^[^\@]+@.*.[a-z]{2,15}$/i', $email)) {

now:

if (utf8_strlen($email) > 0 && filter_var($email, FILTER_VALIDATE_EMAIL)) {

 
6.  system/engine/action.php was rewrited 
Now it uses Reflection class what is very controversial decision because this API is very slow and it loads for the every controller.
 

Conclusion

Reflection, composer, namespaces.. is it still OpenCart? :)
I am very happy to see all these things in OpenCart because it means that OpenCart is evolving. 
But it is very bad that this process is extremely slow. Events could work in 2.0, now is 2.2, they have been rewritten probably tenth times and they are still not  working as they should like in Drupal or other CMS where you can using hooks or events change almost everything.
 
Is it necessary to change version of your shop from 2.1 to 2.2?
I haven't seen big and useful changes in 2.2. The structure has been changed but it just will add you more troubles with modules compatibility. Some cosmetics changes have been added in the admin area. Some bugs was fixed. So I don't see why it is necessary to change version very fast. But of course it is better to have always new version. 
 
CAPTCHA
Spam protection
Target Image