Share via


Commerce Foundation Basket CommerceUpdate

This Microsoft Multi-Channel Commerce Foundation operation is used to update a basket. A submitted basket can contain line items, addresses, payments, and requested promotion codes.

Note: The Commerce Server API requires the Application ID to be passed when saving a purchase order. The API uses the request context channel name as the Application ID. It is important for the StatusManager table of the TransactionConfig database to contain the channel; otherwise an exception will be thrown indicating the application does not have the right to change the status of the order.

Syntax

        var updateBasket = new CommerceUpdate<CommerceEntity>("Basket");
      

Parameters

Supports only CommerceModelSearch<Basket>, however, supports only the following fields:

Fields

Description

Request.SearchCriteria.Model.UserId

Required.

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

Required. Specifies the ID of the specific basket to return. If you do not specify Name. If you specify both Id and Name, the system throws an exception.

Request.SearchCriteria.Model.Name

Required. Specifies the name of the specific basket to be returned. This property is only supported when BasketType is 0 (cart). If you do not specify Id. If you specify both Id and Name, 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

BasketLoader

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

BasketProcessor

Updates the fields of the Commerce Server order group (basket or purchase order) in the operation cache by using the values obtained from the Microsoft Multi-Channel Commerce Foundation Basket.

BasketLineItemsProcessor

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

BasketAddressesProcessor

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

RequestedPromoCodesProcessor

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

PaymentsProcessor

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

TargetingProfilesProcessor

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

OrderPipelinesProcessor

Runs the basket Commerce Server pipeline on each of the Commerce Server OrderGroups in the operation cache if each is of a Commerce Server Basket then, if there were no errors, executes the total pipeline if the basket is in the ReadyForCheckout state.

BasketCommitter

Commits the changes to the OrderGroup in the cache (through Commerce Server APIs). If the basket is in the ReadyForCheckout state, and the type has been updated to Order, the Checkout pipeline is executed before saving.

BasketResponseBuilder

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 when available.

BasketLineItemsResponseBuilder

Converts the line items of the cached Commerce Server basket to Microsoft Multi-Channel Commerce Foundation line items and adds them to the response.

BasketAddressesResponseBuilder

Converts Commerce Server addresses to Microsoft Multi-Channel Commerce Foundation addresses and adds them to the response.

RequestedPromoCodesResponseBuilder

Converts Commerce Server promotion code records to Microsoft Multi-Channel Commerce Foundation RequestedPromoCodes and adds them to the response.

PaymentsResponseBuilder

Converts Commerce Server payments to Microsoft Multi-Channel Commerce Foundation payments and adds them to the response.

ShipmentsResponseBuilder

Converts Commerce Server shipments to Microsoft Multi-Channel Commerce Foundation payments and adds them to the response.

Related Operation

Description

CommerceCreateRelatedItem<Address>

Creates an address that is strongly related to the Basket. This creates an address in a Commerce Server Basket only, and not in the Profiles System.

CommerceUpdateRelatedItem<Address>

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

CommerceDeleteRelatedItem<Address>

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<LineItem>

Creates a line item in the related Commerce Server Basket.

CommerceUpdateRelatedItem<LineItem>

Updates a line item in the related Commerce Server Basket.

CommerceDeleteRelatedItem<LineItem>

Deletes a line item in the related Commerce Server Basket. You cannot delete an item that you created or updated in the same operation.

CommerceCreateRelatedItem<RequestedPromoCode>

Creates a promotion code in the related Commerce Server Basket.

CommerceUpdateRelatedItem<RequestedPromoCode>

Updates a promotion code in the related Commerce Server Basket.

CommerceDeleteRelatedItem<RequestedPromoCode>

Deletes a promotion code in the related Commerce Server Basket. You cannot delete an item that you created or updated in the same operation.

CommerceCreateRelatedItem<Payment>

Creates a payment in the related Commerce Server Basket.

CommerceUpdateRelatedItem<Payment>

Updates a payment in the related Commerce Server Basket.

CommerceDeleteRelatedItem<Payment>

Deletes a payment in the related Commerce Server Basket. You cannot delete an item that you created or updated in the same operation.

Exceptions

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

  • FaultException<GeneralOperationFault>

Updating the Status of a Purchase Order

The CommerceUpdate<Basket> operation provides the ability to change the status of a purchase order using the CommerceBasketUpdateOptionsBuilder.  Commerce Server uses the application id to ensure the transition from one state to another is supported by the application. This information is maintained as part of the StatusManager table of the TransactionConfig table. In Microsoft Multi-Channel Commerce Foundation, the application id translates to the channel passed in the request context. For example:

var updateOrder = new CommerceUpdate< Basket,
                        CommerceModelSearch<Basket>,
                        CommerceBasketUpdateOptionsBuilder>();

    updateOrder.SearchCriteria.Model.Id = orderBasketId;
    updateOrder.SearchCriteria.Model.UserId = userId;
    updateOrder.SearchCriteria.Model.BasketType = BasketType.Order;
    updateOrder.Model.Status = "Shipped";

Optionally, you can prevent the Commerce Server basket pipelines from running as part of the update you can set the CommerceBasketUpdateOptionsBuilder parameter to false, by specifying:

updateOrder.UpdateOptions.RefreshBasket = false;

See Also

Other Resources

Developing with the Commerce Foundation Orders System

Commerce Foundation Basket

CommerceUpdate