Commerce Foundation BasketGroup QueryOperation

This Microsoft Commerce Server 2009 R2 operation is used to retrieve a BasketGroup and related items from the server.

This topic contains the following sub-sections:

  • Syntax

  • Parameters

  • Operation Sequence Components

  • How to Use a BasketGroup Query Operation to Load All Baskets and Addresses

Syntax

        var queryBasketGroup = new CommerceQuery<CommerceEntity>"("BasketGroup");
      

Parameters

The following parameters are supported when using the CommerceModelSearch<BasketGroup> search criteria.

Fields

Description

queryBasketGroup.SearchCriteria.Model.Name

Optional. The name of the BasketGroup.

queryBasketGroup.SearchCriteria.Model.UserID

Required. Specifies the ID of the user whose baskets will be returned. If an ID, OrderNumber, or Name is not specified, all of the user's baskets of the BasketType requested are returned.

Request.SearchCriteria.Model.BasketType

Required. Specifies the type of basket (0 for cart, 1 for order) to be returned.

If BasketType = 0 (cart), specifying both the ID and the Name is not allowed and an exception is thrown. If neither ID nor Name is specified, then all the baskets are returned.

If BasketType = 1 (order), specifying both the ID and the OrderNumber an exception is thrown.If neither ID nor OrderNumber are specified then all baskets are returned.

queryBasketGroup.SearchCriteria.Model.ID

Optional. Specifies the ID of the specific BasketGroup to return. If neither the ID nor the Name is specifed, then all of the user's BasketGroup instances are returned. If the request specifies both the ID and the Name or OrderNumber, an exception will be thrown.

Request.SearchCriteria.Model.OrderNumber

Optional. Specifies the order number of the specific basket to be returned. This property is only supported when BasketType is 1 (order). If an ID, OrderNumber, or Name is not specified, all of the user's baskets of the BasketType requested will be returned. If the Name is specified along with OrderNumber, an exception will be thrown.

Request.QueryOptions.RefreshBasket

Optional. You can use the RefreshBasket property to refresh the contents and subtotal of a basket by creating a CommerceQuery with the Option type CommerceBasketQueryOptionsBuilder. The default value is true. This option should only be specified when BasketType is 0 (cart).

Request.SearchCriteria.Model.TargetingContext

Optional. 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. This property is only meaningful when BasketType is 0 (cart).

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 related Basket Operation.

BasketGroupQueryProcessory

Retrieves the Commerce Server OrderGroup(s) depending on the search criteria and puts it in the operation cache. You can retrieve the selected basketGroup from the cache using GetCachedCommerceServerOrderGroupsOperationCacheDictionary extension method (available when you include the Microsoft.Commerce.SequenceComponents.Utility name space.

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.

BasketGroupResponseBuilder

Populate query response. This component calls Basket operations to populate the Baskets Relationships (if requested).

How to Use a BasketGroup Query Operation to Load All Baskets and Addresses

The following code samples show an example of how to use a BasketGroup query to return all instances of basket entities contained in a BasketGroup. The sample request also retrieves related Basket items (CommerceQueryRelatedItem) such as addresses and LineItems.

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

            var queryBaskets = new CommerceQueryRelatedItem<CommerceEntity>("Baskets", "Basket");
            {
                var queryLineItems = new CommerceQueryRelatedItem<CommerceEntity>("LineItems", "LineItem");
                queryBaskets.RelatedOperations.Add(queryLineItems);
            }

            queryBasketGroup.RelatedOperations.Add(queryBaskets);

            var queryAddresses = new CommerceQueryRelatedItem<CommerceEntity>("Addresses", "Address");
            queryBasketGroup.RelatedOperations.Add(queryAddresses);queryBasketGroup

See Also

Other Resources

Commerce Foundation Basket CommerceQuery

Commerce Foundation BasketGroup UpdateOperation

Commerce Foundation BasketGroup DeleteOperation