Skip to content

Instantly share code, notes, and snippets.

@jonpontet
jonpontet / prestashop_sql_commands.php
Created December 16, 2021 11:41
How to execute SQL statements in PrestaShop
<?php
// SQL SELECT
// Simple SELECT
$sql = 'SELECT `id_authorization_role` FROM `' . _DB_PREFIX_ . 'authorization_role` t WHERE ' . implode(' OR ', $whereClauses);
// Or SELECT with INNER JOIN
$sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'orders o
INNER JOIN ' . _DB_PREFIX_ . 'order_detail od
ON o.id_order = od.id_order
WHERE od.product_id = '. $var
);
@jonpontet
jonpontet / prestashop_get_module_instance.php
Created December 16, 2021 11:41
How to get a module instance in PrestaShop
<?php
$module = Module::getInstanceByName('module_name');
$module->functionName();
@jonpontet
jonpontet / prestashop_move_overrides.php
Created December 16, 2021 11:57
PrestaShop will only copy automatically to the override folder the PHP file of the same name of the module. Sometimes you need to override other files of a module - with this code you can that in your own custom module.
<?php
// The path to the /override/modules folder in your custom module
$module_path = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $this->name .
DIRECTORY_SEPARATOR . 'override' . DIRECTORY_SEPARATOR . 'modules';
// The path to the PrestaShop override folder
$override_path = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'override' . DIRECTORY_SEPARATOR . 'modules';
// Add an entry to the array for all of the overrides that you want to be copied to the override folder:
$files = array(
@jonpontet
jonpontet / prestashop_head_js.php
Created December 16, 2021 13:32
How to add a custom JS file to the frontend of PrestaShop
<?php
public function install()
{
// Hook registration needs to go in the install function of your module
if ($this->registerHook('displayHeader')) {
return true;
}
return false;
}
@jonpontet
jonpontet / prestashop_add_to_logs.php
Created December 16, 2021 13:45
Add a generic logging function to your custom PrestaShop module that will log messages to the Logs page of the Back Office
<?php
/**
* Generic logging function
*
* @param $event
* @param $info
* @param int $level
* @param null $supplementary
* @return bool
*/
@jonpontet
jonpontet / prestashop_group_column_for_customers.php
Created December 16, 2021 14:15
How to add a group column to the customers page in the PrestaShop Back Office
<?php
public function install()
{
if ($this->registerHook('actionCustomerGridDefinitionModifier') &&
$this->registerHook('actionCustomerGridQueryBuilderModifier')) {
return true;
}
return false;
}
@jonpontet
jonpontet / prestashop_module_config_form.php
Created December 16, 2021 14:45
How to add a settings config form to your custom module in PrestaShop
<?php
// Add all these functions to your custom module
/**
* Function to display content for your module in the Back Office
*
* @return string
*/
public function getContent()
{
@jonpontet
jonpontet / prestashop_back_office_css.php
Created December 16, 2021 14:54
How to include custom CSS in the Back Office of PrestaShop
<?php
public function install()
{
if ($this->registerHook('actionAdminControllerSetMedia')) {
return true;
}
$this->uninstall();
return false;
@jonpontet
jonpontet / docker-compose.yml
Last active January 16, 2022 20:10
Docker Compose file for PrestaShop with MySQL
version: '3.3'
services:
db:
build:
context: .
network: prestashop-net
container_name: db
image: mysql:5.7
ports:
@jonpontet
jonpontet / .htaccess
Last active October 31, 2023 17:45
Force HTTPS with a 301 redirect on any page with mod_rewrite in htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>