Basket
Add To Basket
The AddToBasket
method is used for adding products to the current customers basket.
Usage
var currentProduct = Ucommerce.Infrastructure.ObjectFactory.Instance.Resolve<Ucommerce.Api.ICatalogContext>().CurrentProduct; var transactionLibrary = Ucommerce.Infrastructure.ObjectFactory.Instance.Resolve<Ucommerce.Api.ITransactionLibrary>(); transactionLibrary.AddToBasket(quantity: 1, currentProduct.Sku);
Parameters
Parameter | Type | Details | Required |
---|---|---|---|
quantity | int | The quantity of the product in the basket. | Yes |
sku | string | The product SKU, this is how you specify which product from the catalog you want to add. | Yes |
variantSku | string | The variant SKU. If your product has variants you need to specify a VariantSku. | Optional |
unitPrice | decimal? | The unit price to be used for the orderline if the list price should not be used. | Optional |
priceGroup | PriceGroup | The price group to use to find the list price and vat rate. | Optional |
addToExistingLine | bool | If set to true , the quantity is updated if the same product is already added to the basket. Otherwise a new orderline is created. |
Optional |
executeBasketPipeline | bool | If set to true , the basket pipeline will be executed, which will trigger all the basket pipeline tasks in the Baskets.Basket.config configuration file. |
Optional |
parameters | IDictionary<string, object> | A list of properties passed to the AddToBasketPipeline. | Optional |
Execute Basket Pipeline
The ExecuteBasketPipeline
method is used for executing the basket pipeline,
and all the basket pipeline tasks defined in Pipelines/Baskets.Basket.config
The pipeline tasks are responsible for things like calculating order totals, and applying discounts.
Usage
transactionLibrary.ExecuteBasketPipeline();
Get Basket
The GetBasket
method is used for retrieving the basket for the current customer.
GetBasket
throws an ArgumentException
if no basket exists.
Usage
Ucommerce.EntitiesV2.PurchaseOrder basket = transactionLibrary.GetBasket();
Parameters
Parameter | Type | Details |
---|---|---|
create | bool | Optional. If set to true it will create a new basket, if one does not already exist. |
You typically only want create set to True during checkout to prevent visitors getting a basket in case they aren't adding anything to their cart. Otherwise your database can quickly fill up with void baskets (from google bots etc.)
Has Basket
The HasBasket
method is used for determining if the current customer has an active basket.
Usage
bool hasBasket = transactionLibrary.HasBasket();
Update Line Item
The UpdateLineItem
method is used for updating the quantity of a specific order line item.
Usage
transactionLibrary.UpdateLineItemByOrderLineId(orderLineId: 1, 2);
Parameters
Parameter | Type | Details |
---|---|---|
orderLineId | int | The id of the order line to update. |
newQuantity | int | The new quantity of the order line. |