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.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jan 08, 2013 @ 15:48
    Dan Diplo
    0

    How can you get the PercentOffOrderTotalAward for a DynamicOrderPropertyTarget ?

    This might be a little obscure, but basically I am applying a custom discount to an order based on a property in the member's profile. ie. the member has a custom property called "PriceBand" and this can be "GOLD", "SILVER" etc. In uCommerce I can then easily set up a discount by creating a Dynamic Order Property as an Act and specifying the Percentage off value in the Award. For example:

    Act: "PriceBand" on order = "GOLD"
    Award: Percent: 25%

    I can then get the PriceBand property from a member and add a dynamic order property to the order with the value of the price band. UCommerce then applies the correct discount. This is fantastic, and really easy to set up!

    My problem is that now the client says they want to see the discount applied on products when the member is browsing. I can't think of any way of doing this directly in uCommerce, but what I thought I could do is find the "Percentage off order" value for a PriceBand and then calculate it manually. 

    So if a member is in the "GOLD" PriceBand then I want to get the PercentOffTotalAward value for the related DynamicOrderProperty. I just can't for the life of me figure out how the two relate - I can get all the correct CampaignItems, Awards, Targets etc. but can't see how to get from one to the other. Any help appreciated!

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jan 09, 2013 @ 09:00
    Søren Spelling Lund
    0

    Hi Dan,

    What type of award are we dealing with Unit/Line/Order total?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jan 09, 2013 @ 09:37
    Dan Diplo
    0

    Hi Soren,

    Thanks for getting back to me. The discount is an Order total.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jan 09, 2013 @ 11:50
    Søren Spelling Lund
    100

    Hi Dan,

    When I implemented the dynamic order property target I didn't think about it as something that needed to display so it can't be used as a display target (to show something) out of the box. I'll schedule to a work item to rectify that, but in the meantime you have to do it the manual way:

    1) Locate the target with the proper "PriceBand" on it based on what you've got on your purchase order

    2) Load up the campaign item for that target

    3) Finally find the award associated with the target

    Here's what you need: 

    // Assuming price band is already stored on the basket.
    string priceBand = purchaseOrder["PriceBand"];

    // Find the price band target.
    // Assuming just one target for each price band.
    DynamicOrderPropertyTarget target = DynamicOrderPropertyTarget.SingleOrDefault(x => x.Key == "PriceBand" && x.Value == priceBand);

    // Find the award for the campaign item associated with the target.
    // Again assuming just one award.
    PercentOffOrderTotalAward award = Award.SingleOrDefault(x => x.CampaignItem == target.CampaignItem) as PercentOffOrderTotalAward;

    // Grab the percentage off from the award.
    decimal percentageOffOrderTotal = award != null ? award.PercentOff : 0;

    That's the gist of it. Hope it helps.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jan 09, 2013 @ 15:27
    Dan Diplo
    0

    Wow, thanks Soren, that is most useful. It's the fact that you can cast an Award to the different implementations of Award that I hadn't figured out.

    Dynamic order properties are fantastic, and I can understand that they are new and so don't have display targets. I think my situation is probably a corner case :)

    But it's testament to the flexibility of uCommerce that it can be made to work!

    Just one other small potential issue I've discovered that you might want to investigate. I've noticed that DiscountTotal of a PurchaseOrder isn't showing the correct value (it is showing double the expected amount). However, the discount is being applied correctly in the pipeline and if I sum up the values in the Discounts collection of the PurchaseOrder then these are correct!

    Take this C# code example:

    var basket = TransactionLibrary.GetBasket(true).PurchaseOrder;
    
    decimal discountTotal = basket.DiscountTotal.Value;
    var summedTotal = basket.Discounts.Sum(x => x.AmountOffTotal);
    
    <p>discountTotal = @discountTotal</p>
    <p>summedTotal = @summedTotal</p>
    
    The output I get is:

    discountTotal = 184.0500

    summedTotal = 92.03

    This is using a basket very similar to that in the demo Razor store using latest version of uCommerce. However, I noticed a similar problem in an older version of uCommerce, too. The discount I'm applying is 10% off total order (based on a Dynamic order property). Not sure if it's a bug, or something I'm doing? Maybe worth you taking a look...

     

     

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jan 14, 2013 @ 09:21
    Søren Spelling Lund
    0

    Which version of uCommerce are you using? Version 3.0.2.12355 (see release notes) includes a fix for an issue, which sounds similar to what you're seeing.

    The DiscountTotal value is only used for display purposes.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jan 14, 2013 @ 09:33
    Dan Diplo
    0

    I'm using the latest version, Soren. (In fact, I think it was me that reported the issue that was fixed in 30.0.2.12355 :)) The weird thing is that currently the DiscountTotal is once again giving the correct figure. So I think there must be some combination of factors that causes this to happen - but what they are I'm afraid I cannot say (which I know from a debugging perspective is useless!). At the time when it happened I was doing a lot of testing, so changing discounts, creating new baskets (and deleting cookies) etc. Maybe some caching issue? Anyway, it seems stable currently so I'm happy :)

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jan 14, 2013 @ 09:54
    Søren Spelling Lund
    0

    Alrighty. Let me know if you need anything.

Please Sign in or register to post replies

Write your reply to:

Draft