Buy X Get Y promotion creates orphaned order items with NULL order_id when using Calculated Formatter

Created on 15 July 2025, 17 days ago

Describe your bug or feature request.

When creating a "Buy X Get Y" promotion with a 100% discount and enabling the "Automatically add the offer product to the cart if it isn't in it already" option, a new entry in the commerce_order_item table is created with a NULL order_id whenever the product page is viewed or added to the cart.

This issue occurs when using the Calculated Formatter for prices with the option "Apply promotions to the calculated price" enabled.

These orphaned commerce_order_item entities seem to be generated during price resolution and are not properly cleaned up, leading to unnecessary clutter in the database and potential confusion or performance issues.

If a bug, provide steps to reproduce it from a clean install.

1. Install Drupal with Commerce Kickstart or a fresh Commerce installation.
2. Create a "Buy X Get Y" promotion with:
- Offer type: Buy X Get Y
- Discount: 100% off
- Option enabled: "Automatically add the offer product to the cart if it isn't in it already"
2. Disable all caching and clear caches.
3. Visit the product display page for the qualifying "Buy X" product.
4. Add the product to your cart.

🐛 Bug report
Status

Active

Version

3.1

Component

Promotions

Created by

🇨🇾Cyprus akalyptos

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024