TecDefaultCombination
Automatically set the default product combination (attribute) to the lowest-priced variant.
TecDefaultCombination is a lightweight PrestaShop module that helps you ensure the storefront shows the cheapest product combination as the default selection. It can be run manually from the Back Office or scheduled using a secure front controller (cron-friendly) for bulk updates.
Features
- Scans product combinations and computes the effective final price for each variant.
- Sets the combination with the lowest final price as the product default (updates product_shop.cache_default_attribute and product_attribute default_on flags).
- Designed to be executed via a secure front controller (cron-friendly).
- No extra DB tables added.
- Safe for large catalogs: supports batch processing (when invoked by cron).
- Persisted secure key stored in Configuration (editable from Back Office) to protect cron endpoint.
- Optional debug logging with automatic trimming (keeps last 100 lines).
Requirements & Compatibility
- PrestaShop 1.7+ (tested on PS 8/9; always verify on a staging environment before production use).
- PHP version compatible with your PrestaShop installation.
Installation
1. Upload the <code>tecdefaultcombination</code> folder into your PrestaShop <code>modules/</code> directory. 2. Install the module from the Back Office > Modules > Module Manager or use the CLI/console installer if you prefer. 3. Configure the module from the module page in the Back Office.
Usage
You can trigger the process manually from the module Back Office or schedule it using a cron job calling the module front controller.
Example cron base URL (replace domain and secure_key accordingly):
https://yourshop.example/module/tecdefaultcombination/cron?secure_key=YOUR_FULL_SECURE_KEY
Supported query parameters:
- <code>dry_run=1</code> — compute and count changes without applying them (useful for testing).
- <code>batch_size=N</code> — process at most <code>N</code> products in this run (0 means all products).
- <code>start=K</code> — pagination offset when using <code>batch_size</code> (useful to run multiple batches).
Examples:
# Dry run (no changes applied)
curl -s "https://yourshop.example/module/tecdefaultcombination/cron?secure_key=YOUR_FULL_SECURE_KEY&dry_run=1"
Execute with batch of 50 products
curl -s "https://yourshop.example/module/tecdefaultcombination/cron?secure_key=YOUR_FULL_SECURE_KEY&batch_size=50&start=0"
Notes:
- The module validates the full secure key saved in the module settings (not a short prefix) by default. The secure key is persisted in Configuration (option: <code>TECDEFAULTCOMBINATION_SECURE_KEY</code>) and can be changed in the module Back Office.
- Keep the secure key secret and always call the cron endpoint over HTTPS.
Configuration
Open the module settings in the PrestaShop Back Office to:
- View/edit the <code>Module secure key</code> (persistent token stored as <code>TECDEFAULTCOMBINATION_SECURE_KEY</code>).
- Enable or disable <code>Debug</code> (switch). When enabled, cron runs will write messages to <code>modules/tecdefaultcombination/logs/cron.log</code>.
- After changing settings, save and use the displayed Cron URL.
Logs
- Log file: <code>modules/tecdefaultcombination/logs/cron.log</code>
- When Debug is enabled the module appends cron start/finish/error lines to the file.
- To prevent uncontrolled growth, the module trims the log file keeping only the last 100 lines after each write.
- To avoid committing logs to Git, add <code>modules/tecdefaultcombination/logs/</code> to your repository <code>.gitignore</code>.
Make sure the web server user has write permissions to the module <code>logs/</code> folder. Example:
mkdir -p modules/tecdefaultcombination/logs
chown -R www-data:www-data modules/tecdefaultcombination/logs chmod 755 modules/tecdefaultcombination/logs
(adjust <code>www-data</code> to your web server user).
Troubleshooting
- If the cron returns <code>403 Invalid secure_key</code>, verify the key in the module configuration and that you are calling the cron over HTTPS.
- If the cron does not modify products, run a <code>dry_run</code> first to see how many products would be updated.
- For large catalogs, use <code>batch_size</code> and <code>start</code> to process data in smaller chunks.
- If logs are not written, check directory permissions and confirm Debug is enabled in the module settings.
Changelog
See <code>CHANGELOG.md</code> for release notes. The module version <code>1.0.2</code> includes persistent secure key support, cron parameter support (<code>dry_run</code>, <code>batch_size</code>, <code>start</code>), debug switch and log trimming, and improved price calculation for combinations.
Security
- Keep the <code>secure_key</code> private. Do not expose it in public repositories.
- Use HTTPS for all cron requests.
- Rotate the secure key periodically if required by your security policy.
Development & Contribution
Contributions, bug reports and feature requests are welcome. Please open issues or pull requests on the module repository.
When submitting changes, include:
- PrestaShop version used for testing
- PHP version and any relevant server info
- Steps to reproduce the issue
License
MIT License — see the <code>LICENSE</code> file for details.
Author
Tecnoacquisti.com — support: https://www.tecnoacquisti.com
Comentarios (0)
Su agradecimiento a la reseña no pudo ser enviado
Reportar comentario
Reporte enviado
Su reporte no pudo ser enviado