Filter REST calls made from within a view model

REST calls may also be made from within view models as the view models interact with the server while doing do their work.

IMPORTANT: This section describes how to filter REST calls made from within a view model. Please note that dependencies exist between view models such that data retrieved by one view model may be used by another. Care must be taken when filtering view model REST calls so that you do not filter out data needed by another view model.

Filtering the responses for view model REST calls uses the context object and filter map combination described in Programmatically determine the correct response filter key. The context objects are defined within the view models themselves, however, so all you have to do to filter REST calls made from view models is create the filter map and upload it in an application-level JavaScript module (see Include Application-level JavaScript Modules for more information on creating this type of module).

The following filter map example shows the top-level objects that define which response filters are used for REST calls made from view models. It is not necessary to include all of these top-level objects in your filter map, only those for REST calls you want to filter. However, keep in mind that the top-level objects you include in your filter map will overwrite any existing top-level objects.

define(

  //-------------------------------------------------------------------
  // DEPENDENCIES
  //-------------------------------------------------------------------
  ['ccStoreConfiguration'],

  //-------------------------------------------------------------------
  // Module definition
  //-------------------------------------------------------------------
  function(CCStoreConfiguration) {

    'use strict';

    return {
      onLoad : function() {

        console.log("Loading Application Level JS");

           var priorityList = ["endpoint","page","identifier"];

           var filterMap = {
           "getCollection":{
              "megaMenuNavigation": {"ccFilterConfigKey": "categoryNavData"},
              "categoryNavigation": {"ccFilterConfigKey": "categoryNavData"}
            },
            "listProducts":{
              "productListingData": {"ccFilterConfigKey": "PLPData"},
              "collectionWidget": {"ccFilterConfigKey": "collectionData"},
              "getProductData": {"ccFilterConfigKey": "productData"},
              "getProductDataAndRedirect": {"ccFilterConfigKey": "productData"}
            }
            "listMembers": {
              "ccFilterConfigKey": "key-name"
            },
            "getGiftWithPurchaseChoices": {
              "ccFilterConfigKey": "key-name"
            },
            "getAllOrdersForProfile": {
              "ccFilterConfigKey": "key-name"
            },
            "listScheduledOrdersByProfile": {
              "ccFilterConfigKey": "key-name"
            },
            "getItemType": {
              "ccFilterConfigKey": "key-name"
            },
            "getCurrentProfile": {
              "userData": {"ccFilterConfigKey": "key-name"}
            },
            "getAllPrices": {
              "ccFilterConfigKey": "key-name"
            },
            "getStockStatus": {
              "productStockStatus": {"ccFilterConfigKey": "key-name"},
              "stockStatusForProdValidation": {"ccFilterConfigKey": "key-name"}
            },
            "getPaymentGroup": {
              "ccFilterConfigKey": "key-name"
            },
            "getOrder": {
              "orderForSubmit": {"ccFilterConfigKey": "key-name"},
              "templateOrder": {"ccFilterConfigKey": "key-name"},
            },
            "getScheduledOrder": {
              "loadOrder": {"ccFilterConfigKey": "key-name"}
            },
            "getPage": {
              "home": {
                "layoutOnly":{"ccFilterConfigKey": "key-name"},
                "cachableData":{"ccFilterConfigKey": "key-name"},
                "currentData":{"ccFilterConfigKey": "key-name"}
              }
            },
            "getIncompleteOrder": {
              "loadCartForProfile": {"ccFilterConfigKey": "key-name"},
              "refreshCart": {"ccFilterConfigKey": "key-name"}
            },
            "getStockStatuses": {
              "stockStatusesForCart": {"ccFilterConfigKey": "key-name"},
              "stockStatsToValidateCart":{"ccFilterConfigKey": "key-name"},
              "stockStatsForItem":{"ccFilterConfigKey": "key-name"}
            },
            "getMetadata": {
              "dynamicProperties": {"ccFilterConfigKey": "key-name"}
            },
            "listSkus": {
              "skuListing": {"ccFilterConfigKey": "key-name"}
            }
          };
          CCStoreConfiguration.getInstance().updateFiltersToUse(newFilterMap);
      },
    }
  }
);

The following tables describe the data that is returned for the view model REST calls to assist you as you decide what calls you want to filter.

CartViewModel

This table describes the REST calls made from the CartViewModel and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description

{endpoint:"getIncompleteOrder",

identifier:"loadCartForProfile"}

This context object is used for calls made to the getIncompleteOrder endpoint. The CartViewModel makes this call to retrieve the current incomplete order and load it in the UserViewModel and the CartViewModel. This may happen when an anonymous shopper logs in or creates an account. Also, when a shopper accepts a quoted order and moves to another page (other than the checkout page), the quoted order is removed and the incomplete order is loaded. Similarly, if a shopper is viewing an order that is pending payment and then moves to a page other than the checkout page, the pending payment order is removed and the incomplete order is loaded.

{endpoint:"getIncompleteOrder",

identifier:"refreshCart"}

This context object is used for calls made to the getIncompleteOrder endpoint. The CartViewModel makes this call when the shopper changes pages or the system reloads the cart. The call retrieves any incomplete order data for the logged-in shopper and then populates the CartViewModel and UserViewModel properties with the data it has retrieved.

{endpoint:"getMetadata",

identifier:"dynamicProperties"}

This context object is used for calls made to the getMetadata endpoint. The CartViewModel makes this call to retrieve metadata for dynamic order properties.

Note that if you are using dynamic order properties, you must customize the widget code to use the markDirty flag depending on your preferences. You can, therefore choose to handle changes to dynamic order properties when all properties have been set, or update on selection of each dynamic property. Marking the CartViewModel.isDirty() flag to true would trigger an update order call.

{endpoint:"getOrder",

identifier:"templateOrder"}

This context object is used for calls made to the getOrder endpoint. The Scheduled Order widget triggers the CartViewModel to make this call when the shopper clicks the Place Order button. Clicking this button places the contents of the scheduled order into the shopping cart, allowing the shopper to place a one-time order based on a scheduled order. See Configure page layouts for scheduled orders for more details.

{endpoint:"getStockStatus",

identifier:"stockStatusForProdValidation"}

This context object is used for calls made to the getStockStatus endpoint. The CartViewModel makes this call to retrieve stock status information when the quantity of a product on the cart page is updated.

{endpoint:"getStockStatuses",

identifier:"stockStatusesForCart"}

This context object is used for calls made to the getStockStatuses endpoint. The CartViewModel makes this call to get stock status information when it is refreshing product data for items in the cart. This call is also triggered to get stock status information when a configurable product is reconfigured.

This call does not get made for orders in the PENDING_PAYMENT or PENDING_PAYMENT_TEMPLATE state because these orders cannot be edited; in other words, since the items in the order cannot be edited, stock status for those items is irrelevant.

{endpoint:"getStockStatuses",

identifier:"stockStatsToValidateCart"}

This context object is used for calls made to the getStockStatuses endpoint. The CartViewModel makes this call to retrieve stock status information for the products in the cart during the checkout process. The call is made when the shopper has clicked the checkout link on the Checkout page and the prices of the products in the cart have not changed.

Note: If the prices have changed, the shopper is redirected to the cart page and this call is not made.

{endpoint:"getStockStatuses",

identifier:"stockStatsForItem"}

This context object is used for calls made to the getStockStatuses endpoint. The CartViewModel makes this call to get stock status information for all the SKUs (base product and child SKUs) of a configurable product when that product is added to the cart. (Note that the view model method that makes this call is generic enough that it can be used for adding a product to the cart that is not configurable.)

{endpoint:"listProducts",

identifier:"getProductData"}

This context object is used for calls made to the listProducts endpoint. The CartViewModel makes this call when it needs to check whether the order has stale product data, for example, when the shopper moves from one page to another. Using this call, the CartViewModel retrieves product data from the server and then uses it to update the products in the cart on the client side. By comparing the new product data with the existing product data, Commerce can determine if the cart has become stale (for example, prices have changed or a product has been marked inactive) and whether repricing should be triggered.

{endpoint:"listProducts",

identifier:"getProductDataAndRedirect"}

This context object is used for calls made to the listProducts endpoint. The CartViewModel makes this call when the shopper has clicked the checkout link and the view model needs to check whether the order has stale product data. Using this call, the CartViewModel retrieves product data from the server and then uses it to update the products in the cart on the client side. By comparing the new product data with the existing product data, Commerce can determine if the cart has become stale (for example, prices have changed or a product has been marked inactive) and whether repricing should be triggered or the shopper should be redirected to the cart page.

{endpoint:"listSkus",

identifier:"skuListing"}

This context object is used for calls made to the listSkus endpoint. The CartViewModel makes this call to get product data for all the SKUs (base product and child SKUs) of a configurable product when that product is added to the cart. (Note that the view model method that makes this call is generic enough that it can be used for adding a product to the cart that is not configurable.)

delegatedAdminContacts view model

This table describes the REST calls made from the delegatedAdminContacts view model and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description
{endpoint:"listMembers"} This context object is used for calls made to the listMembers endpoint. The delegatedAdminContacts view model makes this call to retrieve a list of an account’s contacts.

GiftProductListingViewModel

This table describes the REST calls made from the GiftProductListingViewModel and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description
{endpoint:"getGiftWithPurchaseChoices"} This context object is used for calls made to the getGiftWithPurchaseChoices endpoint. The GiftProductListingViewModel makes this call to retrieve the gift choices for a gift-with-purchase promotion that allows the shopper to choose her gift.

LayoutContainer view model

This table describes the REST calls made from the layout-container view model and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description

{endpoint:"getPage",

page:"page",

identifier:"layoutOnly"}

This context object is used for calls made to the getPage endpoint. The layout-container view model makes this call to get the layout data for the page.

{endpoint:"getPage",

identifier:"cachableData"}

This context object is used for calls made to the getPage endpoint. The layout-container view model makes this call to get page data that is appropriate to store in a cache, for example, site data.

{endpoint:"getPage",

identifier:"currentData"}

This context object is used for calls made to the getPage endpoint. The layout-container view model makes this call to get page data that should not be stored in a cache, for example, user data.

OrderViewModel

This table describes the REST calls made from the OrderViewModel and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description

{endpoint:"getOrder",

identifier:"orderForSubmit"}

This context object is used for calls made to the getOrder endpoint. The OrderViewModel makes this call when moving a quoted or scheduled order to the submitted state. Specifically, when the shopper views a quoted or scheduled order’s details and then chooses to check out the order, this call is triggered.

OrderHistoryViewModel

This table describes the REST calls made from the OrderHistoryViewModel and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description
{endpoint:"getAllOrdersForProfile"} This context object is used for calls made to the getAllOrdersForProfile endpoint. The OrderHistoryViewModel makes this call to retrieve the orders that are displayed on the order history page.

PaymentAuthResponseViewModel

This table describes the REST calls made from the PaymentAuthResponseViewModel and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description
{endpoint:"getPaymentGroup"} This context object is used for calls made to the getPaymentGroup endpoint. The PaymentAuthResponseViewModel makes this call to get the current authorization status when a shopper places an order using CyberSource.

ProductViewModel

This table describes the REST calls made from the ProductViewModel and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description
{endpoint:"getAllPrices"} This context object is used for calls made to the getAllPrices endpoint. The ProductViewModel makes this call to get the prices for a product when a shopper moves to product page.

{endpoint:"getStockStatus",

identifier:"productStockStatus"}

This context object is used for calls made to the getStockStatus endpoint. The ProductViewModel makes this call to get stock information for the product when a shopper moves to product page. The view model also makes this call to get stock information for the gift choices a shopper can choose when she is presented with a gift-with-purchase promotion that allows her to choose her own gift.

scheduled-order view model

This table describes the REST calls made from the scheduled-order view model and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description

{endpoint:"getScheduledOrder",

identifier:"loadOrder"}

This context object is used for calls made to the getScheduledOrder endpoint. The scheduled-order view model makes this call to load a selected scheduled order’s details so that it can be displayed by the Scheduled Order widget.

scheduledOrderList view model

This table describes the REST calls made from the scheduledOrderList view model and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description
{endpoint:"listScheduledOrdersByProfile"} This context object is used for calls made to the listScheduledOrdersByProfile endpoint. The scheduledOrderList view model makes this call to retrieve the list of scheduled orders for the current profile.

skuPropertiesHandler view model

This table describes the REST calls made from the skuPropertiesHandler view model and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description
{endpoint:"getItemType"} This context object is used for calls made to the getItemType endpoint. The skuPropertiesHandler view model makes this call to get the properties for a SKU.

UserViewModel

This table describes the REST calls made from the UserViewModel and provides details on the context objects that are used to locate a response filter for each type of REST call the view model makes.

Context Object Description
{endpoint:"getCurrentProfile"} This context object is used for calls made to the getCurrentProfile endpoint. The UserViewModel makes this call to get profile data for the logged-in shopper.