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.

  • John Walker 43 posts 66 karma points
    Oct 13, 2011 @ 19:35
    John Walker
    0

    Apply voucher code programatically

    Hello,

    I have a project currently which with the budget is only allowing me to use the free edition of uCommerce. Basically what I need to do is add a discount/voucher code to a users order programatically. I understand that the voucher code feature is not available in the free edition so I know any work needed for this is going to have to be cusom built for the value and which product/categories the voucher is to effect. But could someone point me in the direction of how to apply an voucher to an session.

     

    Thanks,

    John

  • Søren Spelling Lund 1797 posts 2786 karma points
    Oct 13, 2011 @ 20:58
    Søren Spelling Lund
    0

    Take a look at the UCommerce.EntitiesV2.VoucherTarget class in the UCommerce.dll.

    You'll need a UI to manage the voucher codes as well. You can see if you can put something together with the /ucommerce/marketing/dialogs/GenerateVoucher.aspx page.

    Let me know how you get on.

  • John Walker 43 posts 66 karma points
    Oct 13, 2011 @ 21:01
    John Walker
    0

    Current code that I have been trying is:

    var discAmount = 100;
        UCommerce.EntitiesV2.Discount disc = new UCommerce.EntitiesV2.Discount();
        disc.AmountOffTotal = discAmount;
        var lines = UCommerce.EntitiesV2.OrderLine.All();
        var b = UCommerce.Runtime.SiteContext.Current.OrderContext.GetBasket();
         <text>Order lines</text>b.PurchaseOrder.OrderLines.ToString();
        decimal discTotal = 0;               
        foreach (var l in b.PurchaseOrder.OrderLines)
        {
            l.AddDiscount(disc);
            l.Save();
     
            discTotal += l.Discount;
            
            <p>Line saving @l.Discount</p>
        }
        <p>Discount toatl = @discTotal</p>
        b.PurchaseOrder.Save();
        b.Save();
        <p>PurchaseOrder.Discount @b.PurchaseOrder.Discount.Value;</p>

    But PurchaseOrder discount is still coming through as 0 any help would really be appreciated.

    John

  • Søren Spelling Lund 1797 posts 2786 karma points
    Oct 14, 2011 @ 15:29
    Søren Spelling Lund
    0

    When doing a discount like that you'll want to remove the ApplyDiscounts task in the basket pipeline as it clears any discounts before reapplying from scratch.

Please Sign in or register to post replies

Write your reply to:

Draft