question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better Promotions Free Gift support

See original GitHub issue

Is your feature request related to a problem? Please describe. It is quite common to have a promotion that entitles the customer to a free gift. Currently we are able to support making an item free using an PromotionItemAction, but the customer still has to manually add it to the order.

The ideal flow in this case however is that once the condition(s) pass, then Vendure can automatically add the free gift to the order.

To work around this, I have suggested in the past the creation of a custom addItemToOrder mutation which contains logic to achieve this. However, it would be better to support this common use-case natively.

Describe the solution you’d like Perhaps a new kind of PromotionAction which is dedicated to adding items the order. The exact mechanism of how this would actually work is not yet clear.

Currently all promotion actions are processed as part of the OrderCalculator.applyPriceAdjustments() method. I would not suggest using this same method to add a new item, since this is mixing concerns and also you get this recursive issue where adding a new item during the price calculation can then potentially trigger new promotions, potentially changing prices of those already added etc.

It would probably work in a separate stage, so:

  1. Calculate order price including non-free gift promotion actions
  2. Check for any free gifts to add
  3. call OrderService.addItemToOrder() with any free gifts

Open questions

  1. Do we want the free gift to be removed if the Promotion is no longer applicable? Or leave it in the order and just allow it to go to full price. The latter would be a much simpler implementation. With the former, we’d need to somehow mark the item as “auto added” and verify its status on every change to the order.
  2. Do we want the free gift’s discount to be coupled to the act of adding it to the order? Or have it so it’s simply an “auto add” feature, and the “free” part is controlled in the present way with a PromotionItemAction.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:22 (13 by maintainers)

github_iconTop GitHub Comments

0reactions
michaelbromleycommented, Sep 29, 2022

First feedback from testing:

  • We need a way to handle errors that might arise in the side-effects. For example, I set up a free gift side-effect similar to the example above, but it wasn’t working. I found out it was because there was insufficient stock of the selected ProductVariant, so the orderService.addItemToOrder() call was returning an ErrorResult.

I think we can handle this by wrapping the calls to onActivate and onDeactivate in a try-catch, and in the case of an error, we convert that into a new type of ErrorResult which we’ll have to add to all the union types that can trigger a promotion side effect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Pros & Cons of Free Gift Campaigns
The Pros & Cons of Free Gift Campaigns. Giving away free gifts is a marketing strategy many small businesses use to attract attention...
Read more >
Complete Guide to Gift With Purchase Programs (Examples ...
One of the best ways to get consumers' attention is with gift with purchase promotions. They spread awareness, drive sales, ...
Read more >
19 Customer Appreciation Gift Ideas to Thank Your Customers
Keeping the gift a secret can help in this regard. Customers who receive something free and unexpected are driven to shop more, according...
Read more >
How To Run A Free Gift With Every Purchase Promotion - Creatir
Support Customer Loyalty. A free gift can show your customers that you're committed to offering them the best possible value. As a result,...
Read more >
How to use Free Gift to increase sales | Secomapp
There are always free gifts so why do they need to hurry? Best time for free gift promotion is on the rush time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found