Sitecore OrderCloud Documentation

docs

Portal login

Promotion Integration: Calculating Custom Discounts

Published by Miranda Danielson on December 19, 2024

Learn more about a new configuration within promotions that is used in conjunction with an integration event to support scenarios that fall outside the capabilities of the Rules Engine.

Sample Use Case

As powerful as the Rules Engine is, you may sometimes have a use case that is too complex to solve using the properties and functions accessible within an expression.

For example, let's say you have this promotion: Buy 2 from Category A, Get 2 from Category B for 50% off​, with the following stipulations:

  • Must scale with quantity​

  • Quantities may be split across items​

  • Discount should be applied to the least expensive lines first

While it's not possible to accomplish with a ValueExpression evaluated by the Rules Engine, you can write custom code to calculate the discount yourself and return those discounts to OrderCloud to be applied as determined by your middleware.

General Workflow

  1. A promotion is created in OrderCloud with a null ValueExpression​

  2. Any time that promotion is added to an order, or needs to be recalculated, OrderCloud will call out to your predefined middleware endpoint with information about the order and promotion​

  3. Middleware responds with information to tell OrderCloud what the value of the discount should be​

  4. OrderCloud applies the discount to the order or applicable lineitems.

Key Highlights

  • OrderCloud will still evaluate the promotion's EligibleExpression and only call your middleware when an order is eligible to have a promotion applied

  • Works with Auto Applied promotions

New Property

  • Promotion.UseIntegration

    • boolean, defaults to false

    • when true, OrderCloud will call out to your Marketplace's PromotionIntegration to get the discount amount

New Resource: PromotionIntegration

1{
2 "Url": "",
3 "HashKey": ""
4}

PromotionIntegrationPayload

1{
2 "Environment": "",
3 "Order": {},
4 "LineItems": [],
5 "PromosApplied": [],
6 "PromosRequested": [],
7}
  • Environment can be useful if you host a single middleware for multiple environments so that you know if the call is coming from Production, Staging, or Sandbox

  • The full Order object and list of LineItems are returned

  • A list of Promotions already applied to the order, as well as a list of Promotions requesting to be applied to the order are also included

    • PromosRequested will only have multiple entries in the event AutoApply promotions is being called and more than 1 promotion is eligible

PromotionIntegrationResponse

1{
2 "HttpStatusCode": 200,
3 "PromosAccepted": [],
4 "PromosRejected": [],
5 "UnhandledErrorBody": ""
6}

AcceptedPromo

1{
2 "ID": "",
3 "LineItemID": "", // null if order level promotion
4 "Amount": 0
5}

RejectedPromo

1{
2 "ID": "",
3 "LineItemID": "", // null if order level promotion
4 "Reason": ""
5}

New Endpoints

  • GET v1/integrations/promotion

  • PUT v1/integrations/promotion

  • DELETE v1/integrations/promotion

  • PATCH v1/integrations/promotion


Still have questions?
Ask in our Community Channel

Content Powered By
Sitecore Logo

© Copyright 2024, Sitecore OrderCloud®. All rights reserved.

Contact Us
Privacy Policy
Sitecore