I think the shopping cart needs to be heavily re-written to support this.
Basically, I think the shopping cart should be an abstraction layer over an estimate. ShoppingCart::get() should either generate a new estimate (if user is not logged in, or has no saved shopping cart), retrieve an estimate from a session (if the user is not logged in) or retrieve an existing estimate (if the user is logged in and has an estimate saved).
If the user logs in and has an estimate saved to a session, the estimate should be written to the database at this point and then will be saved for later use.
When we add items to the cart, they should be OrderItem rather than ShoppingCartItem, and similar to how the shopping cart does it now, Order Item's should be tracked separately in a session (as saving them as unsaved associations causes the session data to corrupt).
The cart will also need to merge a session based estimate into a saved estimate if the user has added items while not logged in, then chooses to login and has a saved estimate.
Finally, we need to ensure that the estimate is torn down when the user purchases.
I think the shopping cart needs to be heavily re-written to support this.
Basically, I think the shopping cart should be an abstraction layer over an estimate.
ShoppingCart::get()
should either generate a new estimate (if user is not logged in, or has no saved shopping cart), retrieve an estimate from a session (if the user is not logged in) or retrieve an existing estimate (if the user is logged in and has an estimate saved).If the user logs in and has an estimate saved to a session, the estimate should be written to the database at this point and then will be saved for later use.
When we add items to the cart, they should be
OrderItem
rather thanShoppingCartItem
, and similar to how the shopping cart does it now, Order Item's should be tracked separately in a session (as saving them as unsaved associations causes the session data to corrupt).The cart will also need to merge a session based estimate into a saved estimate if the user has added items while not logged in, then chooses to login and has a saved estimate.
Finally, we need to ensure that the estimate is torn down when the user purchases.