Add To Basket Pipeline
The add to basket pipeline runs when you call 'Add to basket' on Ucommerce.Api.ITransactionLibrary
The purpose of the pipeline is to create a hook when a user adds a product to their basket. It is a great hook if you want events to happen only at this point. Usually the basket pipeline can be used for this purpose as well, but the basket pipeline will run every time the user modifies their basket. This pipeline is only run once per add to basket.
Read about transactionlibrary if you are unsure how to add products to the basket
Pipeline implementation
- windsor component id
AddToBasket
- type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.AddToBasketPipeline
Tasks and execution order
ValidatePipelineArgumentsTask
- Windsor component id
AddToBasket.ValidatePipelineArguments
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.ValidatePipelineArgumentsTask
- Description
Validates the input parameters.
ValidateOrderAssignedToProductCatalogGroupTask
- Windsor component id
AddToBasket.ValidateProductCatalogGroupContext
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.ValidateOrderAssignedToProductCatalogGroupTask
- Description
Insure that order has a catalog group assigned.
ValidateIsSellableProductTask
- Windsor component id
AddToBasket.ValidateIsSellableProduct
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.ValidateIsSellableProductTask
- Description
Checks whatever the product is not a product family.
ValidateProductIsAddedWithSameCurrencyAsBasketTask
- Windsor component id
AddToBasket.ValidateProductIsAddedWithSameCurrencyAsBasket
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.ValidateProductIsAddedWithSameCurrencyAsBasketTask
- Description
Validates that currency of the price group matches the basket's billing currency.
CreateOrderLineTask
- Windsor component id
AddToBasket.CreateOrderLine
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.CreateOrderLineTask
- Description
Creates a new order line and sets it as the order line on the response.
CopyProductNameFromCatalogTask
- Windsor component id
AddToBasket.CopyProductNameFromCatalog
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.CopyProductNameFromCatalogTask
- Description
Copies the name from the Catalog and sets it on the response's order line.
OverrideOrderlineWithExistingTask
- Windsor component id
AddToBasket.OverrideOrderlineWithExisting
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.OverrideOrderlineWithExistingTask
IncrementQuantityTask
- Windsor component id
AddToBasket.IncrementQuantity
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.IncrementQuantityTask
- Description
Increments the response's order line's quantity by the request's quantity.
CalculateUnitPriceTask
- Windsor component id
AddToBasket.CalculateUnitPrice
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.CalculateUnitPriceTask
- Description
Calculates the unit price if it's not set on the request and updates the response's orderline accordingly.
RoundingOffUnitPriceTask
- Windsor component id
AddToBasket.RoundingOffUnitPrice
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.RoundingOffUnitPriceTask
- Description
Rounds the unit price of the order line, using the IRoundingService.
CalculateUnitTaxTask
- Windsor component id
AddToBasket.CalculateUnitTax
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.CalculateUnitTaxTask
- Description
Calculates the unit tax if it's not set on the request and updates the response's orderline accordingly.
AddNewOrderLineToOrderTask
- Windsor component id
AddToBasket.AddNewOrderLineToOrder
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.AddNewOrderLineToOrderTask
- Description
If a new order line was created it gets added to the purchase order and vice versa.
AddPropertiesToOrderLineTask
- Windsor component id
AddToBasket.AddPropertiesToOrderLine
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.AddPropertiesToOrderLineTask
ExecuteBasketPipelineTask
- Windsor component id
AddToBasket.ExecuteBasketPipeline
- Type
Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.ExecuteBasketPipelineTask
- Description
Check whatever BasketPipeline should be execute or not.
Pipeline configuration
Configuration as found under ucommerce\pipelines\Baskets.AddToBasket.config
<configuration> <components> <!-- Pipeline Instance --> <component id="AddToBasket" service="Ucommerce.Pipelines.IPipeline`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.AddToBasketPipeline, Ucommerce.Pipelines"> <parameters> <tasks> <array> <!-- Validation --> <value>${AddToBasket.ValidatePipelineArguments}</value> <value>${AddToBasket.ValidateProductCatalogGroupContext}</value> <value>${AddToBasket.ValidateIsSellableProduct}</value> <value>${AddToBasket.ValidateProductIsAddedWithSameCurrencyAsBasket}</value> <!-- Set up new order line --> <value>${AddToBasket.CreateOrderLine}</value> <value>${AddToBasket.CopyProductNameFromCatalog}</value> <!-- If existing order line should be used, override if found --> <value>${AddToBasket.OverrideOrderlineWithExisting}</value> <value>${AddToBasket.IncrementQuantity}</value> <!--Calculate amounts--> <value>${AddToBasket.CalculateUnitPrice}</value> <value>${AddToBasket.RoundingOffUnitPrice}</value> <value>${AddToBasket.CalculateUnitTax}</value> <value>${AddToBasket.AddNewOrderLineToOrder}</value> <value>${AddToBasket.AddPropertiesToOrderLine}</value> <value>${AddToBasket.ExecuteBasketPipeline}</value> </array> </tasks> </parameters> </component> <!-- Pipeline Tasks--> <component id="AddToBasket.ValidatePipelineArguments" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.ValidatePipelineArgumentsTask, Ucommerce.Pipelines" /> <component id="AddToBasket.ValidateProductIsAddedWithSameCurrencyAsBasket" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.ValidateProductIsAddedWithSameCurrencyAsBasketTask, Ucommerce.Pipelines" /> <component id="AddToBasket.AddNewOrderLineToOrder" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.AddNewOrderLineToOrderTask, Ucommerce.Pipelines" /> <component id="AddToBasket.IncrementQuantity" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.IncrementQuantityTask, Ucommerce.Pipelines" /> <component id="AddToBasket.ValidateProductCatalogGroupContext" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.ValidateOrderAssignedToProductCatalogGroupTask, Ucommerce.Pipelines" /> <component id="AddToBasket.ValidateIsSellableProduct" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.ValidateIsSellableProductTask, Ucommerce.Pipelines" /> <component id="AddToBasket.CalculateUnitPrice" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.CalculateUnitPriceTask, Ucommerce.Pipelines" /> <component id="AddToBasket.RoundingOffUnitPrice" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.RoundingOffUnitPriceTask, Ucommerce.Pipelines" /> <component id="AddToBasket.CalculateUnitTax" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.CalculateUnitTaxTask, Ucommerce.Pipelines" /> <component id="AddToBasket.OverrideOrderlineWithExisting" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.OverrideOrderlineWithExistingTask, Ucommerce.Pipelines" /> <component id="AddToBasket.CopyProductNameFromCatalog" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.CopyProductNameFromCatalogTask, Ucommerce.Pipelines" /> <component id="AddToBasket.CreateOrderLine" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.CreateOrderLineTask, Ucommerce.Pipelines" /> <component id="AddToBasket.AddPropertiesToOrderLine" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.AddPropertiesToOrderLineTask, Ucommerce.Pipelines"> <parameters> <propertiesToCopy> <array> <value>_hasCustomPrice</value> </array> </propertiesToCopy> </parameters> </component> <component id="AddToBasket.ExecuteBasketPipeline" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="Ucommerce.Pipelines.Transactions.Baskets.AddToBasket.ExecuteBasketPipelineTask, Ucommerce.Pipelines"> <parameters> <basketPipeline>${Basket}</basketPipeline> </parameters> </component> </components> </configuration>
Custom task
If you're interested in creating your own pipeline task, here's a code sample and configuration below for the AddToBasket pipeline. If you haven't read how to create custom pipeline tasks before, we recommend giving it a read as there's a lot of valuable information covered in the article.
Code sample
using Ucommerce.Pipelines; using Ucommerce.Pipelines.AddToBasket; namespace MyProject.Extensions.Pipelines.AddToBasket { public class MyAddToBasketPipelineTask : Ucommerce.Pipelines.IPipelineTask<Ucommerce.Pipelines.IPipelineArgs<Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce.Pipelines.AddToBasket.AddToBasketResponse>> { public PipelineExecutionResult Execute(Ucommerce.Pipelines.IPipelineArgs<Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce.Pipelines.AddToBasket.AddToBasketResponse> subject) { return PipelineExecutionResult.Success; } } }
Configuration
<configuration> <components> <component id="AddToBasket.MyAddToBasketPipelineTask" service="Ucommerce.Pipelines.IPipelineTask`1[[Ucommerce.Pipelines.IPipelineArgs`2[[Ucommerce.Pipelines.AddToBasket.AddToBasketRequest, Ucommerce],[Ucommerce.Pipelines.AddToBasket.AddToBasketResponse, Ucommerce]], Ucommerce]], Ucommerce" type="MyProject.Extensions.Pipelines.AddToBasket.MyAddToBasketPipelineTask, MyAssembly" /> <partial-component id="AddToBasket"> <parameters> <tasks> <array> <value insert="last">${AddToBasket.MyAddToBasketPipelineTask}</value> </array> </tasks> </parameters> </partial-component> </components> </configuration>
The configuration above just inserts your task as the last task in the pipeline. Mind this line in the configuration above:
<value insert="last">${AddToBasket.MyAddToBasketPipelineTask}</value>
Additionally you can insert first, or before or after a specific task. Just like the example below
You may also use insert="first"
insert-before="${AddToBasket.ValidatePipelineArguments}"
or insert-after="${AddToBasket.ValidatePipelineArguments}"