Skip to content

Customize Discounts

You can customize the behavior of the Discounts feature by using the following configuration:

Back Office pagination

Use the built-in SiteAccess-aware parameters to change the default pagination settings.

The following parameters are available:

  • list_per_page_limit controls the number of discounts displayed on a single page in discount list view
  • products_list_per_page_limit controls the number of products displayed on a single page in a discount details view

You can set them as in the following example:

1
2
3
4
5
6
7
ibexa:
    system:
        admin_group:
            discounts:
                pagination:
                    list_per_page_limit: 10
                    products_list_per_page_limit: 15

Discount re-indexing

Discounts feature uses Ibexa Messenger to reindex discounts and product prices as background tasks. This way changes are processed efficiently without slowing down the system and disrupting the user experience.

When triggered periodically, the ibexa:discounts:reindex command identifies discounts that require re-indexing, ensuring prices always remain up-to-date. If there are edits to discounts that should result in changed product catalog prices, messages are dispatched to the Ibexa Messenger's queue and consumed by a background worker. The worker passes the messages to the handler, which then starts the re-indexing process at the most convenient moment.

To run discount re-indexing in the background:

1. Make sure that the transport layer is defined properly in Ibexa Messenger configuration.

2. Make sure that the worker starts together with the application to watch the transport bus:

1
php bin/console messenger:consume ibexa.messenger.transport --bus=ibexa.messenger.bus

3. Use a scheduler of your choice, for example, cron, to periodically run the following command:

1
php bin/console ibexa:discounts:reindex

Deploying Symfony Messenger

For more information about deploying the Messenger to production, see Symfony documentation.

Rate limiting

To prevent malicious actors from trying all the possible discount code combinations using brute-force attacks, the /discounts_codes/{cartIdentifier}/apply endpoint is rate limited using the Rate Limiter Symfony component.

You can adjust the default configuration by modifying the config/packages/ibexa_discounts_codes.yaml file created during installation process.

The limiter uses the following pattern: user_%d_ip_%s, using Customer ID and Customer IP address to track usage of both logged-in and anonymous customers. To cover additional use cases, you can add your own logic by listening to the BeforeDiscountCodeApplyEvent event.

Checkout error-handling

A discount can be valid when customer enters the cart, but later become invalid before the checkout process is completed.

For example, this event could occur if the discount expired, was modified, disabled, or deleted before the customer completed the checkout process.

To prevent customers from placing such orders, the Discounts feature comes with built-in error-handling. Once it detects that a discount that can no longer be used is applied to a product, it stops the checkout process and informs the customer.

This error handling is provided by two event subscribers:

  • Ibexa\Bundle\Checkout\EventSubscriber\DiscountsHaveChangedExceptionSubscriber
  • Ibexa\Bundle\DiscountsCodes\EventSubscriber\DiscountCodeUnusableExceptionSubscriber

You can disable this behavior by setting the ibexa_checkout.error_handlers.enabled container parameter to false, which allows you to provide your own solution for these cases.