Helper classes for Prestashop CMS.
Full documented helper classes for PrestaShop CMS (8, 1.7, 1.6, 1.5). With these helpers some programming tasks becomes more simple and done faster. The library homepage.
Helper list:
Controller list:
Component list:
Every method and class is full documented, so here are several examples, i.e. just a one for each class.
ArrayHelper, indexing an array.
$array = [
['id' => '123', 'data' => 'abc'],
['id' => '345', 'data' => 'def'],
];
$result = ArrayHelper::index($array, 'id');
// The result is:
// [
// '123' => ['id' => '123', 'data' => 'abc'],
// '345' => ['id' => '345', 'data' => 'def'],
// ]
FormHelper, generating a source array for a select
element.
$array = [
['123' => 'abc'],
['345' => 'def'],
];
$result = FormHelper::generateList($array);
// The result is:
// [
// ['id' => '123', 'name' => 'abc'],
// ['id' => '345', 'name' => 'def']
// ]
// The usage in a form definition:
array(
'type' => 'select',
'label' => 'Example',
'name' => 'example',
'options' => array(
'query' => $result,
'id' => 'id',
'name' => 'name',
),
)
LogHelper, logging an error in a module.
public function example() {
$this->log('An error occupied.');
}
public function log($messages, $level = AbstractLogger::WARNING) {
LogHelper::log($messages, $level, $this->name, $this->id);
}
DiagnosticHelper, checking if a method is overridden.
if (DiagnosticHelper::isMethodOverridden('AddressController', 'init')) {
$this->_errors[] = $this->l('The AddressController::init() already overridden.');
}
AjaxModuleFrontController, creating a simple Ajax controller for a module.
class ExampleAjaxModuleFrontController extends AjaxModuleFrontController {
protected function actionSave() {
$this->ajaxResponse->result = true;
$this->ajaxResponse->message = 'Success!';
}
}
// The output result is:
// {"result":true,"data":null,"html":"","message":"Success!","errors":[]}
ModuleHelper, getting an instance of a module by given directory path.
$path = '/var/www/prestashop/modules/homecategoriez/classes';
$module = ModuleHelper::getInstanceByPath($path); /** @var HomeCategoriez $module The instance of the module: HomeCategoriez */
FileHelper, getting a real maximum file size that can be uploaded to a site.
$sizeInBytes = FileHelper::getFileSizeUploadLimit();
Cache component, caching a DB query result.
public function getAllCustomers() {
$cacheKey = CacheProvider::getKeyName(__METHOD__);
$data = CacheProvider::getInstance()->get($cacheKey);
if (false === $data) {
$data = Db::getInstance()->executeS('SELECT * FROM ps_customer', true, false);
CacheProvider::getInstance()->set($cacheKey, $data, 60 * 60 * 24);
}
return $data;
}
Autoloader, using Composer's autoloader to automatically load PHP classes, for example, in a module by adding classmap to your composer.json
file.
"autoload": {
"classmap": [
"classes/",
"interfaces/"
]
}
Add the dependency directly to your composer.json
file:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/zapalm/prestashop-helpers"
}
],
"require": {
"php": ">=5.5",
"zapalm/prestashop-helpers": "dev-master"
},
Give the star to the project. That's all! :)
Contributors must follow the following rules:
Contributors wishing to edit the project's files should follow the following process:
Do not hesitate to create a pull request if even it's hard for you to apply the coding standards.