Skip to content

Prevent attribute deletion from wiping all wishlists and statistics - #474

Open
boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:fix/attribute-delete-wipes-wishlists
Open

Prevent attribute deletion from wiping all wishlists and statistics#474
boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:fix/attribute-delete-wipes-wishlists

Conversation

@boo-code

Copy link
Copy Markdown
Questions Answers
Description? Deleting any product attribute from the Back Office wiped the entire ps_wishlist_product and ps_blockwishlist_statistics tables (every customer's wishlist + all statistics). hookActionAttributeDelete calls removeNonExistingProductAttributesFrom{Wishlist,Statistics}(), whose LEFT JOIN product_attribute ... WHERE pa.id_product_attribute IS NULL lookup also matched simple-product rows (which use id_product_attribute = 0, never present in product_attribute). Each match called removeProductFrom…(null, 0); with a null product and a falsy 0 attribute the helper built an empty WHERE clause, so Db::delete() executed DELETE FROM ps_wishlist_product (and the statistics table) unconstrained. Fix = (1) restrict the orphan lookups to real combinations (id_product_attribute > 0), and (2) guard the delete helpers so an empty WHERE clause can never run a table-wide DELETE.
Type? bug fix
Category? FO
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #448.
How to test? Put both a simple product (no combinations) and a combination product in a wishlist, then delete any attribute (e.g. a Size value) in BO → Catalog → Attributes & Features. Before this fix the whole wishlist table is emptied; after it, only rows pointing at a genuinely-deleted combination are removed. Deterministic repro: insert into ps_wishlist_product three rows with id_product_attribute = 0 (simple), a valid combination id, and a non-existent id (e.g. 999999); call WishList::removeNonExistingProductAttributesFromWishlist(). Before: table emptied (3 → 0). After: 0 and the valid combination survive, only 999999 is removed; and WishList::removeProductFromWishlist(null, 0) returns false without deleting anything.
Sponsor company

@ps-jarvis

Copy link
Copy Markdown

Hello @boo-code!

This is your first pull request on blockwishlist repository of the PrestaShop project.

Thank you, and welcome to this Open Source community!

removeNonExistingProductAttributesFrom{Wishlist,Statistics}() selected every
row whose id_product_attribute had no matching product_attribute. Simple
products use id_product_attribute = 0, which never matches, so those rows were
selected and removeProductFrom{Wishlist,Statistics}(null, 0) was called. With a
null product and a falsy 0 attribute, the WHERE clause built there is empty, so
Db::delete() ran 'DELETE FROM ps_wishlist_product' (and the statistics table)
with no condition, wiping every customer's wishlist on any attribute deletion.

Restrict the orphan lookups to real combinations (id_product_attribute > 0), and
guard the delete helpers so an empty WHERE clause can never delete the table.
@boo-code
boo-code force-pushed the fix/attribute-delete-wipes-wishlists branch from 55fb499 to 19838e1 Compare July 29, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

bug: Deleting any catalog attribute completely wipes all wishlist products and statistics tables (empty WHERE clause)

2 participants