Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevin Meilander 82 posts 408 karma points c-trib
    Oct 17, 2022 @ 23:44
    Kevin Meilander
    0

    Vendr Gift With Promo How to Auto Add Product

    We are setting up a "Gift with Purchase" promotion, in that if you purchase a certain amount of certain products, the user gets a free gift with their purchase.   It looks like the promo engine supports the discounts, but we can't figure out how to handle the adding and removal of the product from the cart.   

    We can manually manage it in our controller actions when we modify the cart, but it feels like there should be some sort of common Vendr spot that would be a better place to do this.  Some sort of "validate" cart event or something.  Is there any sort of event that we can use?

    We also are looking at adding to each of the modify events and see that there are validation events and notification events, but we're not sure if either of those types of events are good places to modify the existing shopping cart.  The notification event may work, but so far we've been having issues with it.  

    Has anyone else done a similar promotion using Vendr, and if so how did you handle the adding/removal of the free/gift product?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 18, 2022 @ 08:02
    Matt Brailsford
    100

    Hey Kevin,

    There isn't anything baked in for adding promo products to a cart at the moment, the discounts engine is really just for discounting prices.

    You sound like you are on the right track though as I'd be looking at the events system to add the promo product to the cart whenever it meets your criteria.

    In terms of the types of events, Validation events are purely responsible for validating an action. The only thing these can do is prevent an action from occuring should it not meet your validation logic. To be able to modify the order, you'd want to use a Notification event, and specifically an "ing" based event. As a all purpose event, you could hook into the OrderSavingNotification as this is occurs whenever an order is being persisted so you could check the status of the cart and add the promo product if it doesn't already exist (you don't need to call Save on the order as it's in the process of being saved already).

    You could also look to see if there any more specific events (check here for any notification in the format Order{Something}Notification https://vendr.net/docs/core/3.0.0/reference/vendr-core/vendr-core-events-notification/) such as OrderProductAddingNotification for example that is called when a product is being added to the order. With more targeted events like this, it just means you only need to run your logic occassionally, rather than on every persist.

    Hope this helps

    Matt

  • Kevin Meilander 82 posts 408 karma points c-trib
    Oct 19, 2022 @ 13:35
    Kevin Meilander
    0

    That's what we figured but wanted to make sure there wasn't some way to do that in Vendr already before we add the logic in our code.

    Thanks for the Tips!

Please Sign in or register to post replies

Write your reply to:

Draft