Americart Support
posted this on September 05, 2012 18:23
Using Add To Cart links are very useful in remote carting. The url can be used virtually anywhere — a static site, a blog, or even Facebook or Twitter. This makes it easy to get an item in to a customer’s cart to purchase from your checkout. Additionally, the link url can be constructed or extended from the output of the generator to encompass other parameters found in our KnowledgeCenter Article on Embedded Commerce Parameters.




<a /> tag or as a url to post on social media sites or share with your customers directly.
While the generator does not contain all of the possible parameters, the link it creates can be easily extended to include the extra information. The one created in the previous steps will look similar to this:
<a href="http://yourstorename.com/store/addtocart.aspx?itemid=-1&qty=5&itemname=My%20Awesome%20Product">Add to Cart</a>
If you are not familiar with how query strings in urls work, let's break this down.
<a href="...">Add To Cart</a>
This most basic step here is to create a link, which is done using an <a/> tag. The hrefattribute is used to tell the browser where to go once the link is clicked. The text between the opening and closing <a/> tags is what is shown to the user.
http://yourstorename.com/store/addtocart.aspx
In our example above, this is the base url to which the user goes when they click the link. You would replace yourstorename.com with your actual domain, but leave the /store/addtocart.aspx
?itemid=-1&qty=5&itemname=My%20Awesome%20Product
If you are unfamiliar, this is called a query string. It is appeneded to a url in order to give that page certain options and are built using Key-Value pairs. This means that for each option you pass to the url, you also pass the value of that options. The query string is always started with a ? and each Key-Value pair is separated by a &. So when we break this apart, we can see that we are passing three options, more often called parameters. The first is itemid, the second is qty, and the final is itemname. The value of each parameter is denoted after the equal sign in the query string. So we are telling the addtocart.aspx page that the item's id is -1, the quantity is 5, and the product's name is "My Awesome Product". (For more information on what each parameter is and how to use it, visit our KnowledgeCenter Article on Embedded Commerce Parameters).
While this may not be the most practical item to add (considering there is no item number, no price, or any other pertinent information), this would be enough to add a free item with a name to the user's cart and is just about the minimum. The main field of concern here is the itemid field. When this information is passed, the system assumes you are looking for an existing product. If no item id is provided, or is -1, the system will attempt to create what is called a phantom item.