Немного заметок по разработке на Prestashop. Также будут полезны несколько предыдущих статей: создание модуля Pretsahop 1.6, добавление нового хука, многоязычный текст и многое другое.
Заметки не структурированы, будут периодически добавляться.
Стандартные хуки
displayHeader Displays the content in the page's header area.
displayTop Displays the content in the page's top area.
displayLeftColumn Displays the content in the page's left column.
displayHome Displays the content in the page's central area.
displayRightColumn Displays the content in the page's right column.
displayFooter Displays the content in the page's footer area.
http://doc.prestashop.com/display/PS16/Managing+Hooks
Глобальные переменные
$language
$this->context->language->id
Экранирование в SMARTY
escape:'htmlall':'UTF-8'
Обрезание в SMARTY
truncate:30:'...'
{$product.name|truncate:30:'...'|escape:'htmlall':'UTF-8'}
Добавить текущую страницу в breadcrumbs
https://www.prestashop.com/forums/topic/319440-breadcrumb-declaration-in-prestashop-16/
{capture name=path}{l s='Your shopping cart'}{/capture}
Ссылка на текущую категорию, например в шаблоне товара
{$link->getCategoryLink($category->id_category, $category->link_rewrite)|escape:'html':'UTF-8'}
Текущая страница товара
{$link->getProductLink($product)}
Текущий пользователь
$this->context->customer->id
Подключение api в отдельный файл
require_once __DIR__.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.inc.php';
require_once __DIR__.DIRECTORY_SEPARATOR.'init.php';
Получить товары определенной категории
$category = new Category(5);
// Retrieves the first 15 products of a category
$products = $category->getProducts($this->context->language->id, 1, 15);
// Retrieves the first 15 products of a category, returning the number of total products for that category as well. Ordered by price, lowest to highest
$products = $category->getProducts($this->context->language->id, 1, 15, 'price', 'asc', true);
Вывод ошибок
$this->errors[] = Tools::displayError('Invalid captcha.');
Debug mode
defines.inc.php
define('_PS_MODE_DEV_', false);
Добавить js/css в header
$this->context->controller->addCSS($this->_path.'css/'.$moduleName.'.css', 'all');
$this->context->controller->addJs($this->_path.'js/'.$moduleName.'.js');
Tools::addCSS('http://site.ru/style.css', 'all');
Tools::addjs(($this->_path).'js/search.js', 'all');