How can I save a shopping cart order and order history? The items price is different according to add-ons attached with it. Can I save as an object ? or use different rows for each item and link or any better and efficient ideas. addons are kept in different class and items in different class.
Maybe,one of the possible implementations of the shopping kart is to have one class Kart where you save the different attributes of the shopping kart. If there are certain properties of it that won't change over time then one option is to create a class to save the shopping kart identifier alongside the attributes that don't change and then in a separate class have the pointer to the original class that represents the shopping kart (by having a pointer to the row in Kart) and rest of the properties that do change (for example the total, or the items).
In this separated class SepKart, it is a good Idea to have the attributes validSince and validUntil, and to have in the beforeSave trigger, a function that sets the validUntil attribute of another row in SepKart that points to the same shopping kart in Kart and doesn't have it's validUntil set.
In the case of the items and the order of them, a list of objects that point to the items would do it, because then, if the order changes, then just saving a new instance of it would save the new order and you would then be able to see what is the history of the shipping kart in the time A just by querying in SepKart for the row that points to the shopping kart Kart, has a validSince of a time before A and a validUntil after A (or validUntil not set).