PS PrestaShop Beginner

Expiry Date & Batch Manager — Documentation

Install and use batch-level expiry management: FEFO, automatic discounts, expired lots, cron and alerts.

Updated Module version 1.0.0

Installation

The module installs like any other PrestaShop module, with no dependency and no Composer.

  1. In your back office, open Modules → Module Manager.
  2. Click Upload a module and drop the dfdlc-1.0.0.zip file.
  3. Once installation completes, click Configure.

On install, the module creates two tables (batches and stock movements), adds the Catalog → DLC/DLUO Lots tab and registers four hooks: displayHeader, displayProductAdditionalInfo, actionValidateOrder and actionProductDelete.

If the DLC/DLUO Lots tab does not appear immediately under the Catalog menu, clear the PrestaShop cache from Advanced Parameters → Performance, then log back into the back office.

Understanding use-by and best-before dates

The module distinguishes two date types, and the distinction is not cosmetic: it determines what the module allows itself to do automatically.

Use-by date (DLC)

Worded as “use by”. It applies to microbiologically perishable goods. Past that date the product is considered unsafe and must no longer be sold. The module therefore applies automatic stock actions to use-by batches and, if you choose so, product deactivation.

Best-before date (DLUO / DDM)

Worded as “best before”. It signals a loss of quality, not a safety risk. The product remains legally sellable after that date, provided the customer is clearly informed. The module therefore limits itself to deactivating the expired batch: it never removes stock and never disables the product on a best-before date.

Choose the date type carefully when creating each batch. That field, and only that field, determines whether automatic stock actions are triggered on expiry.

Configuring the module

The configuration page gathers all settings, along with the cron URL and a quick status of your batches.

Front-office display

  • Display expiry date on product page: shows the date of the closest available batch, worded to match the date type.
  • Short-dated badge threshold (days): below this number of remaining days, a “Short-dated” badge appears next to the date. Default: 10 days.

Automatic discounts

  • Enable automatic short-date discounts: turns the whole mechanism on or off.
  • Apply discount when expiry is within (days): the window before the expiry date in which a batch becomes eligible. Default: 15 days.
  • Discount percentage: applied rate, between 1 and 90%. Default: 30%.

Expired batch handling

Three modes are available, from the most cautious to the most automatic:

  1. Deactivate the lot only — no stock action. Best if you prefer to decide case by case.
  2. Deactivate the lot and deduct its remaining quantity from stock — immediately aligns PrestaShop stock with the reality of the warehouse. This is the recommended mode.
  3. Deduct stock and disable the product if no valid lot remains — prevents selling an item whose entire stock has expired.

Alerts

  • Email alert threshold (days before expiry): monitoring window for the summary email. Default: 30 days.
  • Alert recipient email: leave empty to use the shop address.

Creating and managing batches

Go to Catalog → DLC/DLUO Lots. The list shows your batches sorted by ascending expiry date, with colour coding and remaining days. Two key figures at the top of the page show how many expired batches are still active and how many batches are nearing expiry.

Adding a batch

  1. Click Add new lot.
  2. Type at least two characters in the Product field: matching products are suggested. Select one.
  3. If the product has combinations, a second field appears. Leave “All combinations” to attach the batch to the whole product, or pick a specific combination.
  4. Fill in the lot number, date type, expiry date and received quantity.
  5. Supplier reference and note are optional but valuable during a recall.

You can mix both levels on the same product: a few batches attached to a specific combination and a generic batch at product level. Deduction consumes the batches of the ordered combination first, then the product-level batches.

Editing or deleting a batch

Editing lets you adjust the quantity (after a stocktake, for example) or correct a date. Deleting a batch also removes the associated price rule if an automatic discount was running, along with its movement history.

Exporting

The export button on the list generates a CSV of your batches, including applied filters and sorting. Handy for a quality check or a stocktake.

FEFO stock deduction

FEFO stands for First Expired, First Out: the batch with the closest date goes out first. No setting is required, the mechanism applies automatically.

On order validation, for every product line, the module:

  1. gathers the active batches of the product that still have available quantity;
  2. puts those attached to the exact ordered combination first, then those attached to the product;
  3. sorts that subset by ascending expiry date;
  4. deducts the ordered quantity working up that list, batch after batch.

Example: an order of 10 units facing a batch of 4 (expiring 12 August) and a batch of 8 (expiring 3 October) will consume the 4 units of the first batch, then 6 units of the second. Both movements are logged separately, sharing the same originating order.

FEFO deduction is independent of PrestaShop stock, which keeps working normally. The module maintains the breakdown of that stock into dated batches; PrestaShop stock remains the reference for sales availability.

Automatic short-date discounts

When a batch enters the configured window, the cron creates a catalog price rule (a standard PrestaShop specific price) on the product:

  • percentage discount, at the rate you defined;
  • start date: the day it is created;
  • end date: the batch expiry date, at 23:59.

The discount therefore switches itself off on the deadline, leaving no orphan rule in your catalog. The module creates only one discount at a time per product, even if several batches enter the window simultaneously.

On the customer side, the discount displays normally on the product page, and the “Short-dated” badge shows the current percentage.

The rule created is a standard catalog price rule, subject to the same priority mechanisms as your other rules. If you already apply broad catalog discounts, check priority consistency before enabling automatic discounts.

Setting up the cron task

FEFO deduction works without cron, since it is triggered by orders. Three processes do require a daily call, however: automatic discounts, expired batch handling and the email alert.

The token-protected URL is shown on the module configuration page. It looks like this:

https://your-shop.com/index.php?fc=module&module=dfdlc&controller=cron&token=YOUR_TOKEN

Schedule one call per day, preferably early in the morning. Two common methods:

  • Your host’s cron: add a daily task calling the URL with wget or curl.
  • External service: any online cron service accepts this URL.

The response is a JSON report of the run:

{
  "success": true,
  "promos_applied": 3,
  "expired": {
    "lots_deactivated": 2,
    "stock_deducted": 7,
    "products_disabled": 0
  },
  "alerts_sent": 5
}

This format plugs straight into a monitoring tool, so automation never runs blind.

The token is generated randomly on install. If you suspect it has leaked, reinstall the module to generate a new one, and remember to update your scheduled task.

Email alerts

On every cron run, the module looks for batches whose date falls inside the alert window and that have not been reported yet. If it finds any, it sends a single summary email listing, for each batch: the number, the product, the date type, the deadline and the remaining quantity.

Each batch is reported only once, thanks to a flag stored in the database. You therefore never receive the same reminder every day.

Email templates are provided in French and English in the module’s mails/ folder. You can customise them freely, or add other languages by duplicating an existing folder.

Product page display

The module uses the displayProductAdditionalInfo hook, present in the Classic and Hummingbird themes and in the vast majority of third-party themes. The block displays:

  • the wording matching the date type: “Use by” for a use-by date, “Best before” for a best-before date;
  • the date of the closest available batch;
  • the “Short-dated” badge when the threshold is crossed, with the discount percentage if one is active.

If the product has no active batch with stock and a valid date, nothing is displayed: no empty box appears on the page.

Customising the display

Rendering is isolated in the views/templates/hook/product-expiry.tpl template and styles in views/css/front.css. You can override the template from your theme to adjust position or formatting, without modifying the module.

Traceability and product recalls

Every stock deduction is recorded in the movements table with the batch concerned, the quantity and the originating order. Starting from a lot number, you can therefore retrieve the list of orders that consumed it.

This is the foundation of a recall procedure. The module supplies the raw data; the recall procedure itself (informing customers, handling returns, any reporting to authorities) belongs to your quality process.

Frequently asked questions

Does the module replace PrestaShop stock?

No, it complements it. PrestaShop quantities remain the reference for selling. The module maintains a parallel breakdown of that stock into dated batches. In stock removal mode, it adjusts the PrestaShop quantity when an expired use-by batch is removed, so both views stay consistent.

What if my batches do not cover all of my stock?

Nothing blocks. FEFO deduction only consumes what is available in the batches; if the batches run out, the order proceeds normally and only the PrestaShop quantity is deducted. It is up to you to complete batch entry as goods are received.

Can I enter a batch with a date already in the past?

Yes, but it will be treated as expired on the next cron run. For history purposes, it is better to enter its real date and let the module do its job.

Is the module multistore compatible?

Yes. Each batch is attached to the shop in which it was created, and stock removals are applied to that shop.

What happens on uninstall?

Both tables are dropped, the admin tab is removed and the hooks unregistered. Batches and their history are not preserved: back up your database if you plan to reinstall.

Was this page helpful?

Still stuck? Contact support