Standalone Prices

Learn about recent changes to Standalone Prices, and how to apply them using the TypeScript or Java SDK.

  • After completing this page, you should be able to:

    • Identify how the changes affect the TypeScript and Java SDKs.
    • Apply the updated features using the TypeScript or Java SDK.
  • Do you remember how many Embedded Prices can be stored inside a Product Variant? Not more than 100.
    With Standalone Prices, you can have up to 50 000 Prices for each Product Variant. Standalone Prices offers you significantly more flexibility in how you can model pricing. They are a great alternative to Embedded Prices as they are detached from the Product, and are more efficient in managing and importing them.

    In 2023, there were two major updates to Standalone Prices; hopefully you'll agree that these are all great features:

    Remember that when you create a staged price, it's of TypedMoneyDraft type—meaning it can either be Money (centPrecision) or HighPrecisionMoneyDraft (highPrecision).

    The code samples in this module use our sample data. You are however free to use your own data.

    Creating a Standalone Price

    Let's look at how you can create a Standalone Price using the SDKs.

    import { apiRoot } from '../impl/apiClient.js'; // Update to map to your API root
    const StandalonePriceDraft = {
    sku: 'RAM-095',
    key: 'RAM-094-list-4',
    value: {
    currencyCode: 'USD',
    centAmount: 20000,
    },
    active: true,
    //you can now include a staged price when creating a new Standalone Price
    staged: {
    value: {
    type: 'centPrecision', //you can also use "highPrecision"
    currencyCode: 'USD',
    centAmount: 20500,
    },
    },
    };
    async function standalonePrice(draft) {
    try {
    const response = apiRoot.standalonePrices().post({ body: draft }).execute();
    console.log('Success', JSON.stringify(response.body, null, 2));
    } catch (error) {
    console.error('Error creating price', JSON.stringify(error));
    }
    }
    standalonePrice(StandalonePriceDraft);

    Assuming the above code is successfully executed, we should see the following in the Merchant Center (navigate to Prices > Standalone Price list).

    Standalone Price created with the previous code is displayed in the Standalone Price list.

    It is important to understand that Standalone Prices reference the Product Variant by SKU, so you must ensure that a valid SKU is used or the Standalone Price will be orphaned.

    Deleting a Staged Price

    Let's now look at how you can delete a staged value in Standalone Prices.

    import { apiRoot } from '../impl/apiClient.js'; // Update to map to your API root
    const priceKey = 'RAM-094-list-1';
    async function deletePrice(priceKey) {
    try {
    const versionResponse = await apiRoot
    .standalonePrices()
    .withKey({ key: priceKey })
    .get()
    .execute();
    console.log(
    'Version fetched',
    JSON.stringify(versionResponse.body, null, 2)
    );
    const deleteResponse = await apiRoot
    .standalonePrices()
    .withKey({ key: priceKey })
    .post({
    body: {
    version: versionResponse.body.version,
    actions: [{ action: 'removeStagedChanges' }],
    },
    })
    .execute();
    console.log(
    'Version fetched',
    JSON.stringify(deleteResponse.body, null, 2)
    );
    } catch (error) {
    console.log(JSON.stringify(error, null, 2));
    }
    }
    deletePrice(priceKey);

    Using Standalone Prices

    As you can see from the code samples above, Standalone Prices are very similar in structure to Embedded Prices, albeit a few minor differences:

    • Standalone Prices carry a staged attribute that holds a staged value for the price.
    • Standalone Prices need a SKU value to associate them with a Product Variant.

    One important feature of Standalone Prices is that if your update or import operations are scheduled at different times, and the Standalone Price gets created in the Project before its corresponding Product, no error will be thrown.

    You might wonder how Composable Commerce identifies which pricing mode to use for specific Products; this is controlled by the Product priceMode. It's set to Embedded and uses Embedded Prices, by default. To use Standalone Prices for your Products, set it to Standalone.

    Test your knowledge