Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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:
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
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.
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.
Ahh of course. You’ll want to change it to a published event handler 👍🏻
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.
Isn’t there a WasPropertyDirty method?
Well... today i learned haha. Thanks for the hint
I've updated my code!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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:
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
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.
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.
Ahh of course. You’ll want to change it to a published event handler 👍🏻
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:
Hope this helps anyone.
Isn’t there a WasPropertyDirty method?
Well... today i learned haha. Thanks for the hint
I've updated my code!
is working on a reply...