Browse - Add to Basket

The first step towards making an honest buck is getting customers to add items to the basket. Discover the server-side APIs to get it done and sneak a peek at the client-side APIs available in the Avenue Clothing Demo Store.

 


 

Relevant APIs

UCommerce.Api
TransactionLibrary.AddToBasket(
quantity,
sku,
variantSku = null,
addToExistingLine = true,
executeBasketPipeline = true,
catalogId = null)

Hands-on

The Sku and VariantSku from the page are posted back as form data to your “Product.aspx.cs”. Use the API above to add the product to the basket.


Bonus 1

Add another input field to your form that takes a quantity. Modify AddToBasketButton_OnClick to read that quantity and add it to the call to AddToBasket.


Bonus 2

Use your javascript ninja-skills! Add a reference to JQuery to Main.Master and do an async AddToBasket call - so we’ll not refresh the whole page. Collect Sku, VariantSku and the Quantity.

$.uCommerce.addToBasket(
{
sku: “”,
variantSku: “”,
quantity: 1,
addToExistingLine: true
},
onSuccess,
onError)
{{lineitem.ProductName}}

{{lineitem.VariantName}} - {{lineitem.Quantity}} x {{lineitem.FormattedPrice}} {{lineitem.FormattedPrice}}

Your cart is empty ;(
Total {{basket.FormattedProductsTotal}}
Checkout