...
Code Block | ||||
---|---|---|---|---|
| ||||
$this->context->language->id; |
...
Static shortcuts in
FrontController
subclasses are deprecated:Code Block language php title PrestaShop 1.4 code $id_cart = self::cart->id;
...is to be replaced with...
Code Block language php title PrestaShop 1.5 code $id_cart = $this->context->cart->id;
Do not recreate an object that already exists:
Code Block language php title PrestaShop 1.4 code $language = new Language($cookie->id_lang); $iso_code = $language->iso_code;
...is to be replaced with...
Code Block language php title PrestaShop 1.5 code $iso_code = $this->context->language->iso_code;
More examples of Context use
Old way | New way |
---|---|
$cookie->id_lang; | $this->context->language->id; |
if ($cookie->isLogged()) | if ($this->context->customer->isLogged()) |
if ($cookie->isLoggedBack()) | if ($this->context->employee->isLoggedBack(); |
$cart->getProducts(); | $this->context->cart->getProducts(); |
$language = new Language($cookie->id_lang); | $this->context->language->iso_code; |
new Currency($cookie->id_lang); | $this->context->currency; |
$defaultCountry->id_zone; | $this->context->country->id_zone; |
new Link(); | $this->context->link; |
$smarty->assign(...); | $this->context->smarty->assign(...); |
Using the Context in a PrestaShop 1.4 module
Modules written for PrestaShop 1.5, and which therefore rely on the Context object, can be made to gracefully degrade its Context use in order to work in PrestaShop 1.4.
Add this method to the module's main class:
Code Block |
---|
// Retrocompatibility 1.4/1.5
private function initContext()
{
if (class_exists('Context'))
$this->context = Context::getContext();
else
{
global $smarty, $cookie;
$this->context = new StdClass();
$this->context->smarty = $smarty;
$this->context->cookie = $cookie;
}
}
|
Then, add this line in the module's constructor method:
Code Block |
---|
// Retrocompatibility
$this->initContext(); |
Additionally, when rewriting you v1.5 module in work to work in v1.4, you should use the older hook names, such as displayProductTab
or displayProductTabContent
. These two example hooks are respectively registered using the productTab
and productTabContent
calls, which are compatible for both v1.4 and v1.5, but will not work in the next major version.