Copied to clipboard

Flag this post as spam?

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


  • Puck Holshuijsen 184 posts 727 karma points
    Jan 17, 2023 @ 15:12
    Puck Holshuijsen
    0

    Thawing Prices of a product

    Hi Matt,

    I am having some issues with thawing prices. Maybe i don't completely understand the way it should work, but this is what I am doing.

    A user logs in and adds a product to his cart. Lets say with a price of 3000 euros.

    The webshop owner wants to change the price to 3100 euros. At this point I am checking if the price has changed in the ContentSavingNotification:

    enter image description here

    The price of the product in the cart isn't changing to the new price. I've tried logging out and then in again, but no change.

    Hope you can see what I am doing wrong :)

    Thanks!

    Kind regards

    Puck

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jan 17, 2023 @ 15:33
    Matt Brailsford
    0

    I think ToString on a Guid will include curly braces. I think you’ll need to call ToString(“N”) to have it exclude the braces.

    They frozen price key is generated without braces so if you don’t exclude them, it won’t match.

  • Puck Holshuijsen 184 posts 727 karma points
    Jan 18, 2023 @ 07:03
    Puck Holshuijsen
    100

    Okay, found the issue i think!

    It does work with my code, only thing is: because i am in the saving event, it thaws with the old price :)

    Lets say, i have a price of 2000. Which shows in my cart.

    I change the price to 2050, in the saving event it thaws my price, but at that point the published price is still 2000. So price wont change.

    When i change the price again to lets say 2075, it thaws the price with 2050, and it shows 2050 in my cart.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jan 18, 2023 @ 07:39
    Matt Brailsford
    0

    Ahh of course. You’ll want to change it to a published event handler 👍🏻

  • Puck Holshuijsen 184 posts 727 karma points
    Jan 18, 2023 @ 07:56
    Puck Holshuijsen
    0

    For anyone who is facing the same issues, here's my Event hooked into the PublishedNotification.

    Because I don't want to thaw prices when the price hasn't changed, I am checking if the Property was dirt (thanks Matt).

    This is my way of doing it:

     public class ContentPublishedEvents : INotificationHandler<ContentPublishedNotification> {
        private readonly IContentService _contentService;
        private readonly IPriceFreezerService _priceFreezerService;
    
        public ContentPublishedEvents(IContentService contentService, IPriceFreezerService priceFreezerService)
        {
            _contentService = contentService;
            _priceFreezerService = priceFreezerService;
        }
    
        public void Handle(ContentPublishedNotification notification)
        {
            foreach (var node in notification.PublishedEntities)
            {
                if (node.ContentType.Alias.Equals(DtProduct.ModelTypeAlias))
                {
                   if(node.WasPropertyDirty("price"))
                    {
                        _priceFreezerService.ThawPrices(partialKey: node.Key.ToString());
                    }
                }
            }
        }
    }
    

    Hope this helps anyone.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jan 18, 2023 @ 08:52
    Matt Brailsford
    1

    Isn’t there a WasPropertyDirty method?

  • Puck Holshuijsen 184 posts 727 karma points
    Jan 18, 2023 @ 08:57
    Puck Holshuijsen
    0

    Well... today i learned haha. Thanks for the hint

    I've updated my code!

Please Sign in or register to post replies

Write your reply to:

Draft