1. Sitecore Experience Commerce

Sellable item commands, pipelines and blocks

Version:

The following table describes the sellable items commands and pipelines:

Command/PipelineDescription
CreateSellableItemCommand

CreateSellableItemPipeline
Creates a new sellable item in the Commerce Engine.

Parameters:

  • productId: unique identifier for the sellable item
  • name: internal name for the sellable item
  • displayName: display name for the sellable item
  • description: description for the sellable item
  • brand: brand of the sellable item
  • manufacturer: manufacturer of the sellable item
  • typeOfGood: type of good of the sellable item
  • tags: tags associated with the sellable item
Note

When you create a sellable item programmatically, you must also explicitly associate the new item to a catalog, as shown in this

example.
CreateSellableItemVariationCommand

CreateSellableItemVariationPipeline
Creates a variant of an existing sellable item.

Parameters:

  • sellableItemId: identifier for the parent sellable item
  • variantId: identifier for the sellable item variant
  • variantName: name for the sellable item variant
  • variantDisplayName: display name for the sellable item variant
DeleteSellableItemCommandDeletes the specified sellable item.

Parameters:

  • sellableItemId: unique identifier for the sellable item.
DeleteSellableItemVariationCommandDeletes the specified variantof the sellable item.

Parameters:

  • sellableItemId: unique identifier for the parent sellable item.
  • variantId: unique identifier for the sellable item variant.
DisableSellableItemVariationCommand

DisableSellableItemVariationPipeline
Removes the specified variant from a sellable item.

Parameters:

  • sellableItemId: identifier for the parent sellable item
  • variantId: ID for the sellable item variant
EditSellableItemCommand

EditSellableItemPipeline
Makes changes to an existing sellable item.

  • sellableItem: identifier for the sellable item
GetBulkPricesCommand

GetSellableItemPipeline
Retrieves a string of sellable item identifiers and returns a bulk pricing model for each item. Returns pricing on a particular variant if a variant identifier is supplied, otherwise returns pricing on all variants.

Parameters:

  • itemIds: a delimited list of item identifiers; contains a Catalog, ProductId, and VariantId to fully describe a particular item (string).
GetSellableItemsByParentCommand

GetSellableItemsByParentPipeline
Retrieves all sellable items that belong to a specified parent (that is, a catalog or a category).

Parameters:

  • ParentId: identifier for a catalog or for a category
  • Skip: number of items to skip
  • Take: number of items to skip
GetSellableItemCommand

GetSellableItemPipeline
Retrieves the specified sellable item.

Parameters:

  • itemId: identifier for the sellable item
  • filterVariations: indicates whether the sellable item variants should be retrieved
GetSellableItemsCommand

GetSellableItemsPipeline
Retrieves a list of all sellable items in the system.

Parameters: none.
RemoveListPricesCommand

RemoveListPricesPipeline
Removes the specified list prices for a sellable item.

Parameters:

  • itemId: identifier for the sellable item
  • prices: delimited string of prices for different currencies for the sellable item
UpdateListPricesCommand

UpdateListPricesPipeline
Adds or updates the specified list prices (in different currencies) for a sellable item.

Parameters:

  • itemId: identifier for the sellable item
  • prices: delimited string of prices for different currencies for the sellable item
UpdateSellableItemPurchasableCommandDetermines if an item is available for purchase or not.

  • true: the item is available for purchase
  • false: the item cannot be purchased.
DeleteSellableItemBundleReferencesBlockChecks if the item that is being deleted is a sellable item and cleans up bundle associations if necessary.

Example: create a sellable item programmatically

You use the CreateSellableItem command to create a sellable item programmatically. When you create a sellable item using code, you must also include an explicit association to the relevant catalog.

The following example shows a sample createSellableItem command, with the required catalog association:

namespace Sitecore.Commerce.Plugin.Sample
{
    using System;
    using System.Threading.Tasks;
    using Sitecore.Commerce.Core;
    using Sitecore.Commerce.Core.Commands;
    using Sitecore.Commerce.Plugin.Catalog;

    /// <inheritdoc />
    /// <summary>
    /// Defines the SampleCommand command.
    /// </summary>
    public class SampleCommand : CommerceCommand
    {
        private readonly CreateSellableItemCommand _createSellableItemCommand;

        private readonly AssociateSellableItemToParentCommand _associateSellableItemToParent;

        public SampleCommand(CreateSellableItemCommand createSellableItemCommand, AssociateSellableItemToParentCommand associateSellableItemToParent, IServiceProvider serviceProvider) : base(serviceProvider)
        {
            _createSellableItemCommand = createSellableItemCommand;
            _associateSellableItemToParent = associateSellableItemToParent;
        }

        public async Task<SampleEntity> Process(CommerceContext commerceContext, string catalogID)
        {
            using (var activity = CommandActivity.Start(commerceContext, this))
            {
                SellableItem sellableItem = await _createSellableItemCommand.Process(commerceContext, "My Prodcut ID", "", "My Product Name", "My Product DisplayName", "My Description", "My Brand", "Manufacturer", Array.Empty<string>()).ConfigureAwait(continueOnCapturedContext: false);
                if (sellableItem != null)
                {
                    await _associateSellableItemToParent.Process(commerceContext, "Entity-Catalog-Habitat_Master", catalogID, sellableItem.Id).ConfigureAwait(continueOnCapturedContext: false);
                }

                return new SampleEntity();
            }
        }
    }
}
If you have suggestions for improving this article, let us know!