There are several ways add a product to a cart with JavaScript. You can use price id, product code or product id in combination with parameter values. This JS function is available for all templates.
The following examples use product and parameter ids from https://classic.shoptet.cz/.
shoptet.cartShared.addToCart({priceId: 1745});
priceId
is a unique id of an item in a pricelist. You can also find priceId as a hidden input in the HTML of a page.
shoptet.cartShared.addToCart({productCode: '183/GSB'});
productCode
is a unique code of a product or variant. It can be displayed in the template or is available in HTML. Also backend API provides product code (as code
).
shoptet.cartShared.addToCart({productId: 183, parameterValueId: {78: 210, 10: 204}});
This way is useful if you know parameters from which variant is generated and its values. You have to pass productId
(parent product of variants) and desired parameters values.
For all ways listed above you can also send amount value to add more than one piece of the product:
shoptet.cartShared.addToCart({priceId: 1745, amount: 2});
You can also send silent
parameter to prevent displaying the advanced order window:
shoptet.cartShared.addToCart({priceId: 1745}, true);