Skip to main content

Commerce

Optimizely Spire CMS Page Variants: Custom Rule Type Option

Laptop Computer Works

Optimizely Spire CMS provides a feature to create variants of CMS pages. Page variants are variations of a website page with rules for displaying it to end users. Optimizely Spire CMS supports page variants for all CMS pages, including the header and footer. The primary purpose of that user is to see different variations of the same page.

Optimizely Spire CMS provides a feature to apply rule types on page variants. Optimizely Configured Commerce supports creating custom rule types and rule type options to further use the Rules Engine. The basic requirement of creating a custom rule type or using OOTB on a rule type is that users can see different CMS pages as per the applied rule type.

This blog provides complete information on creating custom rule-type options. The steps below will help create a custom rule type option in the Optimizely Configured Commerce solution that can be used in the Optimizely Spire CMS.

How to Create a Custom Rule Type Option in Optimizely Spire CMS

  1. Open Optimizely Configured Commerce solution in Visual Studio.
  2. Go to the “Extensions” class library.
  3. Create a new class, “CustomRuleTypeOption,” and inherit it from the “CriteriaTypeBase” base class. Add Dependency Name attribute with a name of “CustomRuleTypeOption“.Customruletypeoption1
  4. Implement inherited abstract class members.Customruletypeoption2
  5. Change the DisplayName property value to “Custom Rule Type Option“.Customruletypeoption3
  6. Override the remaining properties value.Customruletypeoption4
  7. To show custom rule type option field in CMS, we need to override the “ParameterDescriptions” property and set “Label” and “ValueType” value.Customruletypeoption5
  8. Override the Validate method and add business logic to validate the input value specified in the CMS. If “true” is returned, the user will see the page variant. If “false” is returned, the user will see the default page.Customruletypeoption6
  9. Rebuild the solution.
  10. Login in Admin.
  11. Go to Administration -> System -> Rule Types listing page.
  12. Open the “Page” rule type from the listing page.
  13. Go to “Rule Options” tab and click on “Rule Type Option” button.Customruletypeoption7
  14. Enter “Description” and select the custom rule type option from the “Criteria Type” dropdown and click on the “Save” button.Customruletypeoption8
  15. Log in as a content admin and click the “Edit” icon.
  16. Go to any page and create a variant of the page. For example, go to Header and click on More Options (…).
  17. Select “Create Variant“.Customruletypeoption9
  18. Enter a “Variant Name”, select “Copy Content from Default” and click on “Save” button.Customruletypeoption10
  19. Select the custom rule type option from the rule type dropdown, enter the value, and click the save button.Customruletypeoption11
  20. As per the rule type, verify the variant page on the site.

References:

  1. https://support.optimizely.com/hc/en-us/articles/4413199746317-Manage-page-variants
  2. https://docs.developers.optimizely.com/configured-commerce/docs/create-custom-rule-type-option-for-cms-variants
  3. https://support.optimizely.com/hc/en-us/articles/4413200007437-Rule-type-options

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Gopal Mirkute

Gopal Mirkute is a lead technical consultant working on Optimizely commerce frameworks. He enjoys sharing his knowledge on all things development.

More from this Author

Categories
Follow Us