Commerce Foundation BasketGroup UpdateOperation

This Microsoft Commerce Server 2009 R2 operation is used to update an existing BasketGroup entity.

Note

In absence of an existing BasketGroup entity to update, the <BasketGroup> UpdateOperation acts as a create request and results in the creation of a BasketGroup.

This topic contains the following sub-sections:

  • Syntax

  • Parameters

  • Operation Sequence Components

  • How to Use the BasketGroup Update Operation to Create and Update a BasketGroup

Syntax

        var updateBasketGroup = new CommerceUpdate<CommerceEntity>"("BasketGroup");
      

Parameters

Only supports CommerceModelSearchBasketGroup. The following table lists and describes supported parameters.

Fields

Description

Request.SearchCriteria.Model.UserId

Required. Specifies the ID of the user associated with the BasketGroup to update.

Request.SearchCriteria.Model.BasketType

Required. Type of basket specified as follows:

0 - Cart

1 - Order

Note: When updating an Order status property, the RequestContext.Channel property is used as the application ID into the Commerce Server purchase order save method. Ensure the StatusManager table of the TransactionConfig database is updated accordingly.

Request.SearchCriteria.Model.Id

Specifies the ID of the specific BasketGroup to update.

Optional if basketType = 0 (Cart).

If both Id and Name are specified, the system throws an exception. If neither Id nor Name is specified, then the update operation fails.

Required if basketType = 1 (Order).

If both Id and Name are specified, the system throws an exception.

Request.SearchCriteria.Model.Name

Optional. Specifies the name of the specific BasketGroup to update.

This property is only supported when basketType is 0 (cart).

If both Id and Name are specified, then the system throws an exception.

Request.SearchCriteria.Model.TargetingContext

If specified, provides additional targeting information used to evaluate eligibility for discounts. This must contain a CommerceRelationship whose Target is a commerce entity with model name TargetingContext.

Operation Sequence Components

Operation Sequence Component

Description

BasketAuthorizationSequenceComponent

Processes the Authorization query to validate if the current identity is authorized to perform this operation on this entity.

BasketGroupValidator

Performs a validation to ensure no Address related operations are included in the Basket level operation.

BasketGroupLoader

Loads the OrderGroup based on the request.

BasketGroupProcessor

Loads updates to the BasketGroup entity. Uses the Basket operations for any updates applied at the OrderForm level object or any objects contained with OrderForm (such as LineItems, Payments).

OrderPipelinesProcessorElement

Runs the order Commerce Server pipeline on each of the Commerce Server OrderGroups in the operation cache if each is of type Cart, then if there are no errors, executes the total pipeline if the basket is in the ReadyForCheckout state.

The system never runs pipelines for a basket that is already of BasketType=Order.

BasketGroupCommitter

Commits the changes to the OrderGroup in the cache (through Commerce Server APIs).

BasketGroupResponseBuilder

Populates update response if ReturnModel/Queries are specified. This component calls Basket operations to populate the Baskets Relationships (if requested).

Related Operation

Description

CommerceCreateRelatedItem<Addresses>

Creates address entities that are strongly related to the BasketGroup. This creates addresses in a Commerce Server Basket only and not in the Profiles System.

CommerceUpdateRelatedItem<Addresses>

Updates addresses that are strongly related to the Basket. This updates an address in a Commerce Server Basket only and not in the Profiles System.

CommerceDeleteRelatedItem<Addresses>

Deletes an address that is strongly related to the Basket. This deletes an address in a Commerce Server Basket only and not in the Profile System.

CommerceCreateRelatedItem<Baskets>

Creates basket entities that are strongly related to the BasketGroup.

CommerceUpdateRelatedItem< Baskets >

Updates basket entities that are strongly related to the BasketGroup.

CommerceDeleteRelatedItem< Baskets >

Deletes basket entities that are strongly related to the BasketGroup.

How to Use the BasketGroup CommerceUpdate Operation to Create and Update a BasketGroup

Following are three code samples. The first sample shows how to use the BasketGroup CommerceUpdate operation to create an instance of a BasketGroup that contains a Basket instance (added as a Related Item of BasketGroup) which in turn defines LineItems.

The second sample shows how to use the BasketGroup CommerceUpdate operation to update an existing BasketGroup instance (created above) by adding a second Basket instance as a Related Item. Note that the new Basket instance also contains LineItems.

The third code sample shows how the BasketGroup is updated by deleting a Basket instance it contains.


             var updateBasketGroup = new CommerceUpdate<CommerceEntity, CommerceModelSearch<CommerceEntity>>("BasketGroup");
            updateBasketGroup.SearchCriteria.Model.Properties["Name"] = "Default";
            updateBasketGroup.SearchCriteria.Model.Properties["UserId"] = "{22FEEF65-8941-4488-BC57-5AC1E8792D10}";
            updateBasketGroup.SearchCriteria.Model.Properties["BasketType"] = 0;

            //// Create related Basket(OrderForm) #1
            var newBasket = new CommerceCreateRelatedItem<CommerceEntity>("Baskets", "Basket");
            {
                newBasket.Model.Properties["Name"] = "OrderForm1";
                var newLineItem = new CommerceCreateRelatedItem<CommerceEntity>("LineItems", "LineItem");
                {
                    newLineItem.Model.Properties["CatalogName"] = "Adventure Works Catalog";
                    newLineItem.Model.Properties["ProductId"] = "AW210-12";
                    newLineItem.Model.Properties["VariantId"] = "4";
                    newLineItem.Model.Properties["Quantity"] = 1;
                }
                newBasket.RelatedOperations.Add(newLineItem);
            }
            updateBasketGroup.RelatedOperations.Add(newBasket);

            //// Update related Basket(OrderForm) #2
            var updateBasket = new CommerceUpdateRelatedItem<CommerceEntity>("Baskets", "Basket");
            {
                updateBasket.SearchCriteria.Model.Properties["Name"] = "OrderForm2";
                var newLineItem2 = new CommerceCreateRelatedItem<CommerceEntity>("LineItems", "LineItem");
                {
                    newLineItem2.Model.Properties["CatalogName"] = "Adventure Works Catalog";
                    newLineItem2.Model.Properties["ProductId"] = "AW210-12";
                    newLineItem2.Model.Properties["VariantId"] = "4";
                    newLineItem2.Model.Properties["Quantity"] = 1;
                }
                updateBasket.RelatedOperations.Add(newLineItem2);
            }
            updateBasketGroup.RelatedOperations.Add(updateBasket);

            //// Delete a related Basket(OrderForm) #3
            var delBasket = new CommerceDeleteRelatedItem<CommerceEntity>("Baskets", "Basket");
            {
                delBasket.SearchCriteria.Model.Properties["Name"] = "OrderForm3";
            }
            updateBasketGroup.RelatedOperations.Add(delBasket);

See Also

Other Resources

Commerce Foundation BasketGroup

Commerce Foundation BasketGroup QueryOperation

Commerce Foundation BasketGroup DeleteOperation