This is a shopping cart component to be used by an e-commerce web site.
When you do shopping on a web site, what you intend to buy is displayed on the cart, that you will pay after validation, just as in a physical shop you store your articles in a cart or a basket that is provided by the shop, and before leaving you dispose your shopping on the check-out belt.
The shopping cart is classically displayed on a web page that displays articles, possibly from a database. Each article is displayed with a user interface that allows to add it in the cart (in the example, that interface is the + sign at the end of the line : you click on the + to add the article in the cart).
The quantity column also displays a pair of arrows to adjust it, one to the top and one to the bottom, just as what Microsoft calls a spin.
When clicking on the arrow to the top (spin up) you increase the quantity of one. The same result is obtained by clicking a new time on the line of the article, where you clicked to insert the article in the cart.
When clicking on the arrow to the bottom (spin down) you decrease the quantity of one. When the quantity reaches zero the line disappears from the cart.
The lines are ordered by the catalog line number. The resulting order is reflected in a sequential number in the first column, that is updated each time an article is inserted to or removed from the cart.
The user command is stored in his/her profile, in the Panier string variable. That string contains the different lines separated by a column (;). Each line is composed of the following fields, separated by commas (,) :
- sequential order : this is jut a placeholder, its value is in fact ignored
- catalog line number : this column is the index of the cart, which means the articles in the cart are always ordered by catalog line number
- reference : this column has vocation to be unique to designate the article, but no control is operated on it, articles are just considered matching if the catalog line number is the same. Commas and columns must be removed, as well as quote characters.
- designation : this column is intended for more clarity to the user, it is localizable, which means it can be displayed in a languaged chosen by -or for- the user. The language is supposed to be chosen before the articles. Commas and columns must be removed, as well as quote characters.
- Price : this information is enclosed between single quotes, and the decimals are separated by a dot, independantly from the decimal separator of the language (this only concerns the storage of the data, not its display in the cart)
- Quantity : the title is self-explanatory, this data is an entity.
Supposing a line does not contain the correct number of fields, this generates an exception. Each line must end with a column.
The host page where the cart is displayed must present a user interface for each article, to add it in the cart (in the demo it is a + sign at the end of the line). That interface sends a line composed as specified hereabove, with a quantity of 1, to a LignesCommande class that will add it to the profile. If the article already exists in the profile (which is detected by an equal catalog line number), the quantity is increased of 1. If the article is not already present in the profile, it is inserted. The LignesCommande class is also able to increase the quantity of an article just knowing its catalog line number, which is used when spinning up the quantity in the cart. In case of an attempt to increase the quantity of an article not present in the cart, just with its catalog line number, this throws an exception.
CodeProjects proposes a shopping cart component, that stores its data in a cookie. The style of it was used, as well the JQuery management of the possibility to move it on the page with the mouse, and to schrink/expand the cart by clicking on the icon in the top left corner.
The management of data inside the cart was not kept, as first it was adapted for a culture with decimal separation by a dot, and second the accentuated characters caused the lines to appear twice in the cart. So, I decided to create a pair of element/collection classes, and to store the command lines in the user profile to avoid relying on the navigator parameters.
The presentation page uses the Accordion control of the AjaxControlToolkit, which both benefits from the diffusion abilities of Microsoft and the richness of the opensource development.
The Membership and Roles ASP.Net services are based on MySQL, thanks to providers from CodeProjects, after adapting them.
The presented products originate from the AdventureWorks test database of Microsoft. Only products that include an english and a french descriptions have been kept.