[AddLineItem Parameters]values[/AddLineItem]
Adds a product to the specified shopping cart.

To add products to a visitor's shopping cart, put an AddLineItem context into a template (alternately, you may use the Add command from a URL or a FORM). Whenever WebDNA encounters an AddLineItem context, it opens the shopping cart file (creating a new one if necessary) and adds the product (identified by its SKU) to the end of the LineItems in the shopping cart. The item's price, taxable, canEmail, and unitShipCost information is found by looking for the values of those fields in the product database. You can use a different price by creating a Formulas.db database. Also see Remove, Clear, ShowCart, [SetLineItem] and Purchase.

Example (normally you would put the following text into a .tpl file on your server and use a web browser to link to it):

[AddLineItem cart=5678&sku=1234&db=catalog.txt]quantity=5&textA=Red[/AddLineItem]
Note: you may also add line items to order files that are not inside the ShoppingCarts folder. Using file=/folder/folder/cartname instead of cart=cartname, you can affect any order file in any folder. This is most often used for "back door" administrative maintenance by people inside your organization.

Note:
you may add a maximum of 100 line items to a shopping cart.

The database "catalog.txt" opens, and sku 1234 is found. Shopping cart file "5678" opens, and a new line item is added to the bottom of the list, with a quantity of 5 and textA set to "Red" (as specified in the context above). The price is taken from the database's price field (or, if a formula for [price] is available in Formulas.db, the price is calculated using that formula).

Here are the parameters to the AddLineItem context:
Parameter Description
db
Product database containing the SKU, price, and other information.
sku
Uniquely identifies which product should be added to the cart.
cart
Affected shopping cart file (from ShoppingCarts folder)
file
(alternative to cart) Alternate affected shopping cart file (from any folder). Unlike cart, this file can be in any folder. Specify the file URL-relative to the template.
Context values Description (these values go inside the context)
password
(Optional) In order to change the price (see below) you must provide the line item change password, which can be set in the preferences.
price
(Optional) Sometimes you may need to change the price of a product while adding it to the cart. Normally you use a formula to vary pricing, but sometimes this alternate technique is preferred. Remember to put the line item change password into the parameters. There is a security risk when using this technique, because outsiders can change the price to anything they like.
textA
(Optional) Extra information of any kind that you want associated with this line item. Often used to store extra product information, such as "shoe size" or "color." Also used to pass catalog database fields such as [title] through to the order file so they may be viewed later without needing the original database to look for the value of [title].
textB
Same as textA above.
textC
Same as textA above.
textD
Same as textA above.
textE
Same as textA above.
quantity
(Optional) Indicates how many of this SKU should be added to the cart. This quantity is used when calculating subtotals, unitShipCost, etc.
taxable
(Optional) "T" or "F". Overrides "taxable" field in the database - normally the information about the item's taxable status is taken from a field called "taxable."
canEmail
(Optional) "T" or "F". Overrides "canEmail" field in the database - normally the information about the item's canEmail (electronically deliverable) status is taken from a field called "canEmail."
unitShipCost
(Optional) A number indicating the item's price for shipping. Overrides "unitShipCost" field in the database - normally the information about the item's unitShipCost status is taken from a field called "unitShipCost." ShipTotal and GrandTotal use this number (multiplied by quantity) to determine the total shipping and grand total.
You may set any shopping cart header field (such as Name, taxRate, Address1, etc.) at the same time you add a product to the cart.