Copied to clipboard

Flag this post as spam?

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


  • Ben McKean 272 posts 549 karma points
    Aug 10, 2021 @ 09:18
    Ben McKean
    0

    Setting Discount as inactive programatically

    Hi Matt,

    How would I go about setting a discount as inactive programatically?

    I've tried to use .GetDiscount but this only returns DiscountReadOnly which I can't edit or save.

    Thanks Ben

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 10, 2021 @ 09:33
    Matt Brailsford
    100

    Hi Ben,

    All Vendr's APIs return read only entities by default, you need to make it writable to edit it. You can find info on read only and writable entities, and how to make a read only entity writable here https://vendr.net/docs/core/1.8.0/key-concepts/readonly-and-writable-entities/

    Ultimately, you'd need something like

    using(var uow = _vendrApi.Uow.Create())
    {
         var discount = _vendrApi.GetDiscount(discountId).AsWritable(uow)
            .SetActive(false);
    
        _vendrApi.SaveDiscount(discount);
    
        uow.Complete();
    }
    

    Matt

  • Ben McKean 272 posts 549 karma points
    Aug 10, 2021 @ 09:45
    Ben McKean
    0

    Perfect, thanks Matt.

Please Sign in or register to post replies

Write your reply to:

Draft