Skip to content

TecDefaultCombination — a lightweight PrestaShop module that automatically selects and sets the default product combination (attribute) with the lowest final price. Designed to be executed via a secure cron URL, it updates product and product_shop default attributes and supports bulk processing via a cron-run method.

License

Notifications You must be signed in to change notification settings

ArteInfoRM/tecdefaultcombination

Repository files navigation

TecDefaultCombination

License: MIT
Built for PrestaShop

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 tecdefaultcombination folder into your PrestaShop modules/ 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:

  • dry_run=1 — compute and count changes without applying them (useful for testing).
  • batch_size=N — process at most N products in this run (0 means all products).
  • start=K — pagination offset when using batch_size (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: TECDEFAULTCOMBINATION_SECURE_KEY) 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 Module secure key (persistent token stored as TECDEFAULTCOMBINATION_SECURE_KEY).
  • Enable or disable Debug (switch). When enabled, cron runs will write messages to modules/tecdefaultcombination/logs/cron.log.
  • After changing settings, save and use the displayed Cron URL.

Logs

  • Log file: modules/tecdefaultcombination/logs/cron.log
  • 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 modules/tecdefaultcombination/logs/ to your repository .gitignore.

Make sure the web server user has write permissions to the module logs/ folder. Example:

mkdir -p modules/tecdefaultcombination/logs
chown -R www-data:www-data modules/tecdefaultcombination/logs
chmod 755 modules/tecdefaultcombination/logs

(adjust www-data to your web server user).

Troubleshooting

  • If the cron returns 403 Invalid secure_key, 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 dry_run first to see how many products would be updated.
  • For large catalogs, use batch_size and start 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 CHANGELOG.md for release notes. The module version 1.0.2 includes persistent secure key support, cron parameter support (dry_run, batch_size, start), debug switch and log trimming, and improved price calculation for combinations.

Security

  • Keep the secure_key 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 LICENSE file for details.

Author

Tecnoacquisti.com — support: https://www.tecnoacquisti.com

About

TecDefaultCombination — a lightweight PrestaShop module that automatically selects and sets the default product combination (attribute) with the lowest final price. Designed to be executed via a secure cron URL, it updates product and product_shop default attributes and supports bulk processing via a cron-run method.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published