Share via


Commerce Foundation Basket CommerceQuery

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

Syntax

        var queryBasket = new CommerceQuery<CommerceEntity>("Basket");
      

Parameters

Baskets whose BasketType is 0 (Cart) only support the CommerceModelSearch<Basket> search criteria. Baskets whose BasketType is 1 (Order) support both the CommerceModelSearch<Basket> and CommerceModelSearch<BasketOrderSearch> search criteria.

The following properties are supported when using the CommerceModelSearch<Basket> search criteria:

Fields

Description

Request.SearchCriteria.Model.UserId

Required. Specifies the ID of the user whose baskets will be returned.

Request.SearchCriteria.Model.BasketType

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

Request.SearchCriteria.Model.Id

Optional. Specifies the ID of the specific basket to return. If neither ID, OrderNumber nor Name is specified, all of the user's baskets of the BasketType requested will be returned. If the ID is specified along with Name or OrderNumber, an exception will be thrown.

Request.SearchCriteria.Model.Name

Optional. Specifies the name of the specific basket to be returned. This property is only supported when BasketType is 0 (cart). If neither ID, OrderNumber nor Name is 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.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 neither ID, OrderNumber nor Name is 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

You can use the RefreshBasket property to refresh the contents and subtotal of a basket by creating a CommerceQuery with the TOption 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).

To search for an order by using a date range filter on the created date, use the following fields:

Fields

Description

CommerceRequest.SearchCriteria.Model.UserId

Required. Specifies the ID of the user whose baskets will be returned.

CommerceRequest.SearchCriteria.Model.CreatedDateStart

Required. Specifies the start of the date range. The time portion is ignored and the system assumes it represents the start of the day specified.

CommerceRequest.SearchCriteria.Model.CreatedDateEnd

Required. The time portion is ignored and the system assumes it represents the end of the day specified.

Operation Sequence Components

Operation Sequence Component

Description

BasketQueryProcessor

Retrieves the Commerce Server basket or purchase order depending on the search criteria and puts it in the operation cache. You can retrieve the selected basket from the cache using GetCachedCommerceServerOrderGroupsOperationCacheDictionary extension method (available when you include the Microsoft.Commerce.Providers.Utility name space).

TargetingProfilesProcessor

Adds targeting information to the Commerce Server basket, including user profile and targeting profile information.

RequestedPromoCodesProcessor

Processes the query for Commerce Server promotion code records, converts them to Microsoft Multi-Channel Commerce Foundation RequestedPromoCodes, and adds them to the response.

OrderPipelinesProcessor

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 were 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.

BasketProcessor

Converts the OrderGroup from the cache (potentially modified by the pipelines) to a Microsoft Multi-Channel Commerce Foundation basket and adds it to the response, depending on the supplied Options.ReturnModel. Also includes BasketErrors from the Commerce Server Basket pipeline if the pipelines were run (depending on BasketType).

BaslketLineItemsResponseBuilder

Updates Commerce Server line items on the Commerce Server OrderGroup in the operation response.

BasketAddressesResponseBuilder

Updates Commerce Server order addresses on the Commerce Server OrderGroup in the operation response.

RequestedPromoCodesResponseBuilder

Updates Commerce Server promotion codes on the Commerce Server OrderGroup in the operation response.

PaymentResponseBuilder

Updates Commerce Server payments on the Commerce Server OrderGroup in the operation response.

ShipmentsResponseBuilder

Updates Commerce Server shipments on the Commerce Server OrderGroup in the operation response.

Related Operation

Description

CommerceQueryRelatedItem<Address>(Addresses)

Requests the retrieval of all the addresses of the parent basket. Does not support any filtering criteria.

CommerceQueryRelatedItem<LineItem>(LineItems)

Requests the retrieval of all the line items of the parent basket. Does not support any filtering criteria. This can operation contain child operations CommerceQueryRelatedItem<Discount> (BasketLevelDiscounts) and

CommerceQueryRelatedItem<Discount> (ItemLevelDiscounts)

CommerceQueryRelatedItem<RequestedPromoCode>(RequestedPromoCodes)

Requests the retrieval of all the RequestedPromoCodes of the parent basket. Does not support any filtering criteria.

CommerceQueryRelatedItem<Payment>(Payments)

Requests the retrieval of all the payments of the parent basket. Does not support any filtering criteria. This operation can contain a child CommerceQueryRelatedItem<PaymentAccount>(PaymentAccount), and the CommerceQueryRelatedItem<PaymentAccount>(PaymentAccount) operation can

contain a child CommerceQueryRelatedItem<PaymentMethod>>(PaymentMethod)

CommerceQueryRelatedItem<Shipment>(Shipments)

Requests the retrieval of all the shipments of the parent basket. Does not support any filtering criteria. This operation can contain child operations CommerceQueryRelatedItem<Discount>(Discounts) and

CommerceQueryRelatedItem<ShippingMethod>(ShippingMethod)

Return Value

This query returns a CommerceQueryOperationResponse containing the requested Basket commerce entities.

Exceptions

Microsoft Multi-Channel Commerce Foundation can throw the following exception during this operation:

  • FaultException<GeneralOperationFault>

Performing a Basket Refresh

You can use the RefreshBasket property to refresh the contents of a basket by creating a CommerceQuery using the 3-parameter generic class. For example:

var query = new CommerceQuery<CommerceEntity, CommerceModelSearch<CommerceEntity>,
CommerceBasketQueryOptionsBuilder>("Basket");

or

var query = new CommerceQuery<CommerceEntity, CommerceModelSearch<CommerceEntity>, CommerceBasketQueryOptionsBuilder>();
query.Model.ModelName = "Basket";
query.SearchCriteria.Model.ModelName = "BasketOrderSearch";

If the CommerceBasketQueryOptionsBuilder parameter is not specified or not modified, it will default to true, indicating the basket will be refreshed by running the Commerce Server basket pipelines as part of the query, which may recalculate the basket using more recent information. While this may be appropriate for Baskets of type Cart, it is not desirable for Baskets of type Order. To prevent the Commerce Server basket pipelines from running as part of the query you can set the CommerceBasketQueryOptionsBuilder parameter to false, by specifying:

commerceQuery.QueryOptions.RefreshBasket=false;

See Also

Other Resources

Developing with the Commerce Foundation Orders System

Commerce Foundation Basket

CommerceQuery