Wish list: removeItem() only removes its own items
Read this page if you have code that calls eZWishList::removeItem(), or a shop template or module that posts
item ids to the wish list page. Before, the wish list removed every product collection item whose id it was given,
whether the item belonged to that wish list, to a basket, to an order or to another user's wish list, and an id that
named no item ended in a fatal error.
In short
| What changed | eZWishList::removeItem() is an instance method. It removes the item only when the item belongs to the product collection of that wish list, and returns true if it removed the item, false otherwise. The remove action of shop/wishlist takes only positive whole numbers from the posted list. |
| Who is affected | Code that calls eZWishList::removeItem() statically (it now ends in an Error), or that relies on it removing items of other collections or on it failing for an unknown id. The shipped wish list page needs no change. |
| How to check | grep -rn "eZWishList::removeItem" kernel extension design |
| How to fix | Fetch the wish list and call the method on it: $wishList->removeItem( $itemID ). Check the returned boolean where it matters. |
Details
eZBasket::removeItem() has always compared the item's productcollection_id with the basket's own. The wish list
did not, so every caller had to remember the check, and the page itself did not make it.
- Items of another wish list, a basket or an order are left alone, and
falseis returned. - An unknown id returns
falseinstead of failing on a missing object. - The remove action ignores posted values that are not positive whole numbers, and a posted list that is not a list at all, instead of passing them on.
Option rows of a removed item are not removed with it. That is unchanged and equal to the basket.
Option comparison
When an item is added to the basket or the wish list, the stored options of an existing item are compared with the
posted ones to decide whether it is the same item. The comparison now lives in
eZShopFunctions::isSameOptionSelection() and is shared by both. An attribute the posted list names no option for
explicitly means another selection; before, the comparison read the missing key and raised an "Undefined array key"
warning. In the basket, a missing option for a validated attribute is passed to validateAddToBasket() as null
for the same reason, and in the wish list an option field that is not a list counts as no options.