Skip to content

Instantly share code, notes, and snippets.

@jonpontet
Created December 16, 2021 11:57
Show Gist options
  • Save jonpontet/b1b96c5a17f510c37f7448e443e16c40 to your computer and use it in GitHub Desktop.
Save jonpontet/b1b96c5a17f510c37f7448e443e16c40 to your computer and use it in GitHub Desktop.
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(
// override 1
DIRECTORY_SEPARATOR . 'module_name' .
DIRECTORY_SEPARATOR . 'folder_name' .
DIRECTORY_SEPARATOR . 'file_name.php',
// override 2
DIRECTORY_SEPARATOR . 'module_name' .
DIRECTORY_SEPARATOR . 'folder_name' .
DIRECTORY_SEPARATOR . 'file_name.php',
);
foreach ($files as $file) {
$from = $module_path . $file;
$to = $override_path . $file;
// Create directories that need creating
$path = pathinfo($to);
if (!file_exists($path['dirname'])) {
if (!mkdir($path['dirname'], 0755, true)) {
// Folder creation failed
return false;
}
}
// Copy file
if (!copy($from, $to)) {
// File copy failed
return false;
}
}
// All done
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment