Copied to clipboard

Flag this post as spam?

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


  • Mikkel Johannsen 32 posts 185 karma points
    Aug 01, 2018 @ 16:55
    Mikkel Johannsen
    0

    Generating a discount code

    Hello fellow Umbracians (and Tea Commercians?)

    Has anyone worked out a way to generate discount codes on the fly? Generating giftcards is very simple, but I have yet to find a way to generate discount codes.

    Thanks :)

  • Mikkel Johannsen 32 posts 185 karma points
    Aug 01, 2018 @ 17:14
    Mikkel Johannsen
    102

    I figured it out.

    You have to first create a Marketing campaign through Tea Commerce, as far as I can see, you're not able to do this programatically using the Tea Commerce API.

    When having created the Marketnig campaign, you have to add a Discount Code rule and an award, then you have to get the ID of the discount code rule. There's probably a way better way to get the ID, but the way I've done it so far is this:

        // TODO: REMOVE THIS IN PRODUCTION
        public ActionResult DiscountCodeGenerate(long storeId)
        {
            var allCampaigns = TeaCommerce.Api.Marketing.Services.CampaignService.Instance.GetAllActive(storeId);
            var campaign = allCampaigns.FirstOrDefault(i => i.Name == "NewsletterSignupDiscount");
            return Content(campaign.RulesGroups.FirstOrDefault().Rules.FirstOrDefault().Id.ToString());
        }
    

    Next, you need to generate the actual code. So let's assume the rule ID is 1, you can execute the following code:

    TeaCommerce.Api.Marketing.Services.DiscountCodeService.Instance.Generate(storeId, 1, 1, 1, 10, String.Empty, String.Empty);
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies