silvershop-core icon indicating copy to clipboard operation
silvershop-core copied to clipboard

Order item validation

Open jedateach opened this issue 13 years ago • 2 comments

It is easy to get items in the cart which shouldn't be in there.

When should items be validated

  • Before placing an order
  • Before adding / updating
  • On every request?? - can probably avoid this

What should happen to invalid items

  • Remove from cart?
  • Display a message explaining the problem

Examples

  • Required item attributes are not set: size, relation, etc
  • Product is no longer available
  • Product is now out of stock
  • Trying to add a product, but it has variations

jedateach avatar Aug 31 '12 00:08 jedateach

There are several flaws with how the Shopping-Cart and Order-Items are updated:

  • No easy way to display custom messages to the user, other than relying on Exceptions and try/catch mechanisms.
  • Preventing/altering item-updates is clunky. There are extension hooks like beforeAdd, afterAdd, beforeRemove, afterRemove etc. but these don't provide good tools to intercept unwanted changes (other than throwing an Exception, which doesn't allow to do something like clamping quantity to a max-amount or similar)
  • Too many code-paths that do similar things. An extension that operates on Quantity has to deal with add and setQuantity (where 2 extension hooks exist per operation). Ideally, item modification would only need one place for validation.
  • Switching variations is not affected by any validation. Example: Variation A has 5 items, Variation B has 10 items in stock. Customer adds 10 items of Variation B, can then switch to Variation A and there's no way to validate/prevent that change.

bummzack avatar Oct 11 '16 11:10 bummzack

We need to think about:

  • A better Cart API with less internal code paths
  • Order-Item validation: Validation of a single order item
  • Cart-validation: Validation of the complete order/cart, including modifiers. There might be scenarios where a modifier relies on specific items to be in cart etc.
  • All changes must be rolled back if validation fails.

The easiest way to implement rollbacks are probably DB transactions. Since we already use DB transactions in OrderProcessor::placeOrder, we could use them to roll-back an invalid cart. That would mean that SilverShop will only support Databases with transaction support.

bummzack avatar Oct 11 '16 12:10 bummzack