Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Max 28 posts 80 karma points
    Apr 03, 2014 @ 17:55
    Max
    0

    Generating a promocode for CampaignItem from code

    Hi. I have the CampaignItem set up via uCommerce admin UI that looks like this:

    I have not generated any promo-codes intentially, since for this type of CompaignItems, this is assumed to be only done via code. 

    So right now I am looking for a way to generate a promo-code from C# code and distribute it to the client on one-per-one basis or some other autmomated way, so that I am sure I don't run out of promo codes at some point, plus I can get a hold of the promo code programmatically. 

    Please assist. 

    Thanks.

  • Morten Skjoldager 440 posts 1499 karma points
    Apr 04, 2014 @ 09:16
    Morten Skjoldager
    0

    You can use this to generate a voucher code:

    var generatedCodes = ObjectFactory.Instance.Resolve<IVoucherCodeGenerator>().GenerateCodes(numberToGenerate,
                                                                                                               codeLength, prefix,
                                                                                                               suffix);

    Then you need to find your campaign item in some way and then find the apply target that is your promocode. You can use this services to get all apply targets (one of them if not the only one should be a promo code target.

    var aggregator = ObjectFactory.Instance.Resolve<ITargetAggregator>();
    var targets = aggregator .GetApplyTargets(CampaignItem).ToList();

    Then you can use this to insert the voucher codes to the database:

                   var voucherCodeBulkInsertQuery = ObjectFactory.Instance.Resolve<IVoucherCodeBulkInsertQuery>();
                    ICannedQuery query = voucherCodeBulkInsertQuery.GetQuery(CurrentTarget, maxUses, generatedCodes);
                    ObjectFactory.Instance.Resolve<IRepository<VoucherCode>>().Execute(query);
Please Sign in or register to post replies

Write your reply to:

Draft