Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
We have a client which requires the following scenario:
This client wants to create 1 discount code, i.e.: "WELCOMEBACK" which is mailed to the customer and wants to limit the usage of that code to the customer e-mail. So that only one order can be made with that discount code per customer e-mail.
I don't think this is possible at the moment right?
We proposed a different solution, we generate a new Discount Code on the moment the customer buys Product A and send this to MailChimp as a new merge-field. This way the discount code is genuinly unique for that customer.
However this solution can generate a lot of unique discount codes in the back-end. Is this a problem?
Or is there another / better and cleaner solution to this problem?
It's possible, just not out of the box. Vendr discount rules and rewards are fully pluggable so you can define your own rules / rewards. So you could create a "Distinct Email" rule that checks the order for the customer email address and if one is present, do a DB query to see if there are any finalized orders using that email address. If there are not, then the rule can pass successfully.
You can find out more about custom rules / rewards in the documentation at https://vendr.net/docs/core/1-3-0/key-concepts/discount-rules-and-rewards/#discount-rewards
With a custom rule, you should be able to achieve the exact requirement the custom has asked for.
Hope this helps
Thanks again for this great idea. Indeed I could write a custom rule provider to add to the discount rule.
For searching the order history to check if there are earlier orders with applied discount rule, would you recommend using the OrderService.SearchOrders method? Can I filter there on a customer's email address?
I think it might be faster and less intensive to run a direct SQL statement specific to your needs.
var exists = database.ExecuteScalar<int>($"SELECT COUNT(1) FROM vendrOrder WHERE finalizedDate IS NOT NULL AND customerEmail = @0 AND storeId = @1", email, storeId) > 0;
The DiscountRule works great, however I use the Redeem() method just as in the Vendr demo store to redeem the code.
The first time I order this discountcode works and receives the reward as expected. However the second time I can still Redeem the discountcode, while I have only one Rule in the discount. The rule fails, so the discount reward is not added.
However the Redeem() method does not trigger a validationException, it just continues to run. Is that expected behavior? If yes, how can I validate after the Redeem() method that the Discount was not valid anymore?
It is expected behavior yes as discount codes have to be applied in 2 phases. When you apply the code we first check if it is a valid code and that there is a discount with that code defined that is active, but the task of actually calculating the discount to apply occurs during the order calculation process. So, if the code is reused, it will get added to the orders list of applied discount codes as it is a valid code, but it won't apply a discount as the customer hasn't met the criteria.
You can find out whether a discount is fulfilled or not by reading the list of applied discount codes on the order and checking it's IsFulfilled to see if it is false. If it is false, then the discount isn't applied.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted