Workflow for Order Discount feature of Ecommerce

Ashish Kashyap asked on February 3, 2020 11:23

How to implement Kentico workflow for Ecommerce features like Order Discount, Buy X get Y Discounts.

Recent Answers


David te Kloese answered on February 3, 2020 11:27

So what would you want to happen?

Trigger an advanced workflow after an order is placed to add discounts? (As this has no direct feedback to the live site visitor, so applying discounts could potentially be to late and the client has already finished.

Or apply editorial workflow on the objects in Kentico, e.g. someone needs to approve an discount addition first before it can be used on the site.

0 votesVote for this answer Mark as a Correct answer

Ashish Kashyap answered on February 3, 2020 11:32

Thank you David.

If a seller creates a discount on CMS, it should go through the approval process and on approval by Admin only discount will apply to the products.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on February 3, 2020 12:15

Believe default workflow doesn't work out of the box on those objects.

How is the data entered? Do they direct access to the CMS admin interface? Or did you create something custom?

0 votesVote for this answer Mark as a Correct answer

Dat Nguyen answered on February 3, 2020 13:04 (last edited on February 3, 2020 13:18)

If you're using the standard e-commerce Discount, I recommend hiding the discount Enabled checkbox from sellers, making the Enabled value false when Discounts are created, and allowing only admins to change the discount Enabled value. Doing the following steps is how you can implement this:

  1. Go to Modules > E-commerce > Classes and edit the Discount class.
  2. In the Fields tab, edit the DiscountEnabled field.
  3. In the Visibility condition field, add the following to only allow admin/global admin to see this field (you can modify this as needed): (CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)) || (CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin))
  4. Save the changes.
  5. Now you need to make sure all new discounts are created with the Enabled field set to false. Since you can't do that in the admin interface with the Default value, you'll need to create an event handler that sets the Enabled field to false. This DiscountInfo.TYPEINFO.Events.Insert.After event handler should do the trick:

    private void DiscountInfo_Events_Insert_After(object sender, ObjectEventArgs e)
    {
    
        DiscountInfo discountInfo = 
            DiscountInfoProvider.GetDiscountInfo(((DiscountInfo)e.Object).DiscountID);
        discountInfo.DiscountEnabled = false;
        DiscountInfoProvider.SetDiscountInfo(discountInfo);
    
    }
    

Now any discounts added by a seller would be disabled when they are created, and only admins/global admins can enable them.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on February 3, 2020 13:53

Note that by changing the Kentico module Dat Nguyen mentions a hotfix or upgrade potentially can undo this. So make sure you have this properly documented and perhaps part of a validation test!

And perhaps add a check to the event handlers so Admins can enable it right away when creating one.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.