Allow deleting a bundle item which has already been ordered - #66
Open
lruozzi9 wants to merge 1 commit into
Open
Conversation
Product bundles remove their items with orphan removal, but
ProductBundleOrderItem referenced them through a non nullable join column
with no on delete behaviour. Removing a product from a bundle therefore
failed with a foreign key constraint violation as soon as that bundle item
had been ordered at least once:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or
update a parent row: a foreign key constraint fails
(`bitbag_product_bundle_order_item`, CONSTRAINT `FK_A615CDA9B7FE950B`
FOREIGN KEY (`product_bundle_item_id`) REFERENCES
`bitbag_product_bundle_item` (`id`))
Order items already store the ordered product variant and its quantity, and
the association is already typed as nullable on both the entity and its
interface, so the reference can simply be set to null when the bundle item
is deleted, leaving order history intact.
Applications need a migration for the schema change: the plugin ships none.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
lruozzi9
force-pushed
the
fix/product-bundle-order-item-nullable-bundle-item
branch
from
August 31, 2026 13:55
4c86b51 to
06092ac
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ProductBundleremoves its items withorphan-removal="true", so removing a product from a bundle in the admin issues aDELETEonbitbag_product_bundle_item.But
ProductBundleOrderItemreferences that same row through a join column mappednullable="false"with noon-deletebehaviour. As soon as a bundle item has been ordered at least once, deleting it fails:Stack trace ends in
ResourceUpdateHandler->handle()→UnitOfWork->executeDeletions(), i.e. the plain admin product update.This is not an edge case: any product ever sold inside a bundle becomes impossible to remove from that bundle.
Fix
Why this is safe
ProductBundleOrderItem::getProductBundleItem()is never read.ProductBundleOrderItemFactory::createFromProductBundleItem()writes it, and already copies the two values that matter onto the order item itself:So the order row is already self-sufficient; the pointer is redundant.
Both
ProductBundleOrderItemInterface::getProductBundleItem()andsetProductBundleItem()are already typed nullable — only the mapping disagreed.config/serialization/ProductBundleOrderItem.xmlexposes onlyid,productVariantandquantity;productBundleItemis in no serialization group, so API responses are unaffected.templates/Admin/Order/Show/_productBundleOrderItems.html.twigrendersitem.productVariant/item.quantityonly.It mirrors the sibling
order_item_idjoin column in the same file, which already declareson-delete="CASCADE".Order history is preserved: the ordered variant and quantity stay on the row, only the link to the now-deleted bundle line is cleared.
Verification
Applied in a Sylius 2 project and tested against real data (~1600
bitbag_product_bundle_order_itemrows):product_variant_idandquantity, withproduct_bundle_item_idset toNULL.doctrine:schema:update --dump-sqlis clean afterwards.Note for applications
The plugin ships no migrations, so consuming applications need one: