62
loading...
This website collects cookies to deliver better user experience
Note: I'm only talking about PS1.7 version, not 1.6 or ealier.
classes
, controllers
and themes/<your-theme-name>
. you can learn more about folders architecture from here the documentation is very clear once you understand Hooks (because they are the most confusing, and, easy part).classes
, constrollers
and modules
folders, and place them under overrides
while respecting their original arborescence.var/cache/<dev || prod>/class_index.php
file which is a simple mapping class of the different classes with their overrides.// code/ProductController.php
<?php
# controllers/front/ProductController.php
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
...
class ProductControllerCore extends ProductPresentingFrontControllerCore
{
public function anyFunction()
{
// function shouldn't be private or it won't work
return 'parent value';
}
}
// code/ProductController-override.php
<?php
# overrides/controllers/front/ProductController.php
class ProductController extends ProductControllerCore
{
public function anyFunction()
{
// use parent::anyFunction() to get parent function value
return 'new value';
}
}
@deprecated
tag, some are even from prestashop 1.5 but technically they call the new defined ones.x
with your version.php
and sql
inside the folder [/install-dev/upgrade/](https://github.com/PrestaShop/PrestaShop/tree/develop/install-dev/upgrade)
, notice something? let me explain: // code/configuration.php
Configuration::updateValue('YOUR_UNIQUE_PARAM_NAME', 'new value');
Configuration::get('YOUR_UNIQUE_PARAM_NAME');
Configuration::deleteByName('YOUR_UNIQUE_PARAM_NAME');
// code/context.php
// returns the id of the current used language.
$this->context->language->id;
// assign variables from current controller to the view
$this->context->smarty->assign([
'categories' => $categories,
]);
// the view
return $this->display(__FILE__, 'views/templates/admin/someadminhook.tpl');
// fetching the rendered content of a view,
$this->context->smarty->fetch('module:your_module_dir_name/views/templates/front/display.tpl')
// get current cart
$this->context->cart;
Global variable are prefixed with _PS_
and defined in config/defines.inc.php
making a simple ajax call:
// code/ajax/display.php
// returns the id of the current used language.
$this->context->language->id;
// assign variables from current controller to the view
$this->context->smarty->assign([
'categories' => $categories,
]);
// the view
return $this->display(__FILE__, 'views/templates/admin/someadminhook.tpl');
// fetching the rendered content of a view,
$this->context->smarty->fetch('module:your_module_dir_name/views/templates/front/display.tpl')
// get current cart
$this->context->cart;
// code/ajax/front.js
// preparing the ajax call inside a function
function getProductsByCategoryJs(categoryId) {
$.ajax({
url : AJAX_URL,
type : 'POST',
async: true,
dataType : "json",
data: {
action: 'getProductsByCategoryPhp',
categoryId: categoryId,
ajax: 1
},
success : function (response) {
console.log(response);
$('#your-element').html(response.ajaxTpl);
},
error : function (error) {
console.log(error);
},
});
}
// code/ajax/ajax.php
# my_module/controllers/front/display.php
// making the request url for our contoller in initContent() function
$url = Context::getContext()->link->getModuleLink(
'my_module', // module name
'ajax', // contoller name, could be 'display'
array( // we can define more parameters here
// 'action' => 'DoSomeAction',
// 'ajax' => 1,
)
);
// making variable accessible in javascript
Media::addJsDef([
'AJAX_URL' => $url,
]);