Developer forum

Forum » Ecommerce - Standard features » List of vouchers or discount codes assign to user/customer

List of vouchers or discount codes assign to user/customer

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

What would be the best way to retrieve a list of Voucher codes or discount codes that a specific customer can use? i am guessing based on the discount (or voucher code) being assigned to all users/customers or assigned specifically to this user/customer.

Thank you,

Adrian


Replies

 
Nicolai Pedersen
Reply

There is no good answer to that. It really depends on how vouchers are setup... There are no build in features to do it.

But I am a logical guy - why use a voucher if I get the discount anyways? "Here is a voucher to input - and get a discount" - why not apply the discount right away? What is with that extra step??

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you for the reply.

I admit it is a bit weird of a request but it's how they have it on their current website.

So far, they've defined the vouchers in NAV and somehow they published them on the website. It is uncler for me at this point if they calculated anything in NAv before the order was sent.

I believe the main reason fo publishing the Vouchers/Discount codes was to remind the user they are entitled to a discount if they follow a specific order format/content.

It's now completely absurd but I agree it's uncommon. I have seen it ocasionally as a customer on other ecommerce sites but I don;t think it is a mainstream feature.

That being said, I am not expecting it to become a feature but I need to know if I can somehow accomplish this with the current API. 

Thank you,

Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

I have to come back to this thread.

Is there any method in the API that would get me the discounts that are available for the current user, outside of the order context?

I understand that a discount will only trigger if the right cart content is detected. But I am thinking a list of discounts that COULD BE availalbe if the right conditions are met.

Like a listing of the current campaigns but takling into consideration User or UserGroup limitations.

What do you think?

Thank you,
Adrian 

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Adrian,

 

Not sure if anything is available, but you can get all discounts that might apply to a user (without order context) where:

  • Current Date is within date range
  • Active = true
  • Discounts's Customer Number = logged in user's customer number
  • Logged in user's groups match/contains Discounts's User group 

 

If you also need to consider other discounts (with some order context/conditions), then it's a bit harder and you need to invert some of the conditions to exclude discouts associated with another customer number or associated with user groups the logged in user does not belong to.

 

If you need help getting that SQL query together let me know and I can help.

 

Best Regards,

Nuno Aguiar

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nuno,

Thank you for the reply.

I have already defined a DataList using a SQL query. But I was hoping there might be an easier way to get them using some method from the API.

So far, it looks like I am stuck with the DataList :)

Thank you anyway.

Adrian

 
Nicolai Pedersen
Reply

HI Adrian

There are a number of methods on the discountservice that could come ind handy - it is currently friend though, but thats an easy fix.

I will also be happy to give you an API call that gets you what you want. But how should it work?

Say you have a discount that works on voucher X, but only for orders over 500 with product Y in it. Would an API call return nothing until the order and product criteria is met? And what happens if you later do things on the order that will change which discounts are available?

The DiscountProvider class (which is not a real provider, but the discount matrix calculater) also have a number of methods that can validate if criterias for the discount are met, i.e. like these:

CheckValidTime(discount, orderTime)
CheckOrderContext(discount, orderContextId)
CheckUser(discount, _user)
CheckUserGroup(discount, _user)
CheckCustomerNumber(discount, _user)
CheckCurrency(discount, currency)
CheckProductsAndProductGroups(discount, products)
CheckLanguage(discount, languageId)
CheckShop(discount)
CheckCountry(discount)
CheckShipping(discount, shippingId)
CheckPayment(discount, paymentId)
CheckProductQuantities(orderDiscount, productQuantityRelation)
CheckTotalPrice(orderDiscount, totalPrice)
CheckOrderFields(orderDiscount, order)
CheckProductFields(orderDiscount, orderline)

Using any combinations of these, and other criterias as well - if other discounts are applied etc, will have an impact on which discounts are valid.

The bottom line is that it is relatively complicated wether a discount can be applied or not. It would be easy to give you a list, but you would probably find it 'buggy' in one scenario or another.

So let me understand the need in the above context, and I'll be happy to provide the API needed.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

HI Nicolai,

Thank you for spending time to think about this.

I believe the scope is a lot more simpler than you think.

My customer, the source of this request, is currently listing all the active promotions and personal vouchers in their current "customer center". They are just informational. Like the attached example.

Their current system is basically listing all discounts that are based on a code during the checkout or just personal voucher codes that have been generated and connected to the authenticated user.

The scope is to remind the customer that they can take advantage of the promotions if they do something without having to calculate the exact benefits.

Something like: We have a promotion to Product X. If you buy it and use this code {xxxxxx} in the checkout, you might get back 10 EUR.

What I did so far was select the active discounts that have a value in DiscountOrderFieldValue. And I made a separate SQL join to get the voucher codes that are assigned to the user and are connected to a valid/active discount.

It's not pretty and might bite me on the ass later but it gets close to their current system. 

Since their customers are used to finding those voucher codes in their customer center, it is hard to change their behavior.

I guess, what I needed was a method or a way to build a method that would just list the voucher codes of the current user for the active discounts. Something like GetDiscountVoucherCodesByUserId(string userid).

I don't think it worths adding something to the API if it isn't there already, since this is probably the first and last request for something like this.

Thank you,

Adrian

 

 

vouchers-example.png
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

>> since this is probably the first and last request for something like this

Still looks pretty cool wink

 
Nicolai Pedersen
Reply

Hi Adrian

Thank you for explaining, I now understand. I think I did not understand because in my world it makes no sense to use vouchers in the above case. If the customer is eligable for the discount, they should just have it. But I can also see that if you have a discount that works once, you can decide when to use it. I guess my problem is that I am rational and selling seems to be all but that :-).

We can look into finding discounts for users.

And maybe in the cart make a list of discounts that meets all but one criteria, so that you can write in the cart, "Add voucher XX to get 10%", "buy for 17,95 more to get free shipping", "Buy product Y to get discount Z" etc.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

I totally understand it. The cart approach seems very nice and very useful in my opinion.
We have already added something for getting free shipping but it is currently based on the fees from the shipping providers and some threshold in the Website settings. Not pretty.

Thank you very much for considering this.

Adrian

 

You must be logged in to post in the forum