Developer forum

Forum » Ecommerce - Standard features » Apply discount for first time users only - the world of discounts

Apply discount for first time users only - the world of discounts

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I have a requirement where I should apply a discount (based on a voucher code) only the first time for a user. This should work for anonymous and logged in users.

Since it should work for anonymous users too, I was thinking about using a cookie that indicates if the user has been given the discount before. (I realize that this isn't foolproof as people can clear their cookies but the customer is willing to take that risk). However, I can't find a way to set the cookie when the discount has been applied (maybe in CheckoutDoneOrderIsComplete?) nor can I find a way to override  / intercept the validation of the voucher code or to enable / disable the discount based on that cookie.

Does anyone have any pointers on how I could implement this?

Thanks,

Imar


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Imar

You can apply the voucher code when the notification Notifications.eCommerce.Cart.Created is fired. That is the first time a user adds a product to the cart. Here you could check if the user has a cookie before adding the voucher to the new order.

When an order is done, use the Dynamicweb.Notifications.eCommerce.Cart.CheckoutDoneOrderIsComplete as you say. In that notification subscriber you can set the cookie that you check for in the first step.

BR Nicolai

 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

But what if I want the user to enter the voucher code (not add it automatically) but reject it if it has been used? Is thee a way to tap into the voucher code or discount engine and reject the item from being added or remove it after it has been added?

Imar

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

If you place the info of the voucher code in the cookie on checkoutdoneordercomplete, you can when you render the cart, check if this user has used the code and ensure it is not added to the cart - using i.e. JS.

You have the Notifications.eCommerce.Cart.BeforeDefaultPropertiesValueIsChanged notification that is fired whenever a value on a field on the order is changed. The BeforeDefaultPropertiesValueIsChangedArgs contains a property, "PropertyName" that is 'EcomOrderVoucherCode' when that one is set to a new value. You can use that to do it serverside.

BR Nicolai

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Thanks Nicolai, we'll take a stab at this.

Imar

 

You must be logged in to post in the forum