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:
- ArrayHelper
- BackendHelper
- DateHelper
- DiagnosticHelper
- FileHelper
- FormHelper
- HtaccessHelper
- LogHelper
- ModuleHelper
- ObjectHelper
- SecurityHelper
- StringHelper
- TranslateHelper
- UrlHelper
- ValidateHelper
- ProductHelper
Controller list:
- BaseModuleFrontController.php
- AjaxModuleFrontController.php
Component list:
- Cache
- QualityService
- Autoloader (used Composer that goes to boot)
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:
- Make your Pull Request on the dev branch, NOT the master branch.
- Do not update a helper version number.
- Follow PSR coding standards.
Contributors wishing to edit the project's files should follow the following process:
- Create your GitHub account, if you do not have one already.
- Fork the project to your GitHub account.
- Clone your fork to your local machine.
- Create a branch in your local clone of the project for your changes.
- Change the files in your branch. Be sure to follow the coding standards.
- Push your changed branch to your fork in your GitHub account.
- Create a pull request for your changes on the dev branch of the project. If you need help to make a pull request, read the GitHub help page about creating pull requests.
- Wait for the maintainer to apply your changes.
Do not hesitate to create a pull request if even it's hard for you to apply the coding standards.