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,
All my products has the same price, more precise one of two: regular or discount. Price depends on a True/False property on the current member.
There is no price property in the product document type. It is moved to the Home document type.
In my custom product adapter, I get a product snapshot and update it with prices from Home node (regular or discount).
I have had problems with converting price from PricePropertyValue to IEnumerable
I'm injecting CurrencyService to get all available currencies, and using lambda to produce list of prices, but I'm not sure if it is a good solution:
public override IProductSnapshot GetProductSnapshot(string productReference, string productVariantReference, string languageIsoCode) { var snapshot = (UmbracoProductSnapshot)base.GetProductSnapshot(productReference, productVariantReference, languageIsoCode); if (snapshot != null) { var homeNode = _umbracoContextAccessor.UmbracoContext.Content.GetAtRoot().Where(x => x.ContentType.Alias.ToLower() == "home").OfType<Home>().FirstOrDefault(); if (homeNode != null) { var nodePrice = homeNode.StandardPrice; var loggedMember = _umbracoContextAccessor.UmbracoContext.HttpContext.User.Identity; if (loggedMember != null) { var member = memberService.GetByUsername(loggedMember.Name); if (member != null) { var hasDiscountPrice = member.GetValue<bool>("reducedPrice"); if (hasDiscountPrice) { nodePrice = homeNode.DiscountPrice; } } } var currencies = currencyService.GetCurrencies(homeNode.Store.Id); var newPrices = currencies.Select(x => nodePrice.GetPriceFor(x.Id)); return new CustomProductDecorator(snapshot, newPrices); } } return null; }
There should be better way to do this conversion?
Kind regards
Tomasz
Hi Tomasz,
Hmm, yea, it looks like that is currently the only way to do it. Looking at this, I could probably just make the PricePropertyValue itself IEnumerable<ProductPrice> which should do the trick.
PricePropertyValue
IEnumerable<ProductPrice>
I'll raise a feature request on the issue tracker.
Matt
Hi, Matt
Thanks for a quick reply, as always :)
Anyway, it's good to know, that I've done it right :)
I've just implemented this locally and will be in an upcoming 1.8.1 release.
Until then, yea, what you have is probably the best approach. 👍
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Convert PricePropertyValue to IEnumerable<ProductPrice> in a custom ProductAdapter
Hi,
All my products has the same price, more precise one of two: regular or discount. Price depends on a True/False property on the current member.
There is no price property in the product document type. It is moved to the Home document type.
In my custom product adapter, I get a product snapshot and update it with prices from Home node (regular or discount).
I have had problems with converting price from PricePropertyValue to IEnumerable
I'm injecting CurrencyService to get all available currencies, and using lambda to produce list of prices, but I'm not sure if it is a good solution:
There should be better way to do this conversion?
Kind regards
Tomasz
Hi Tomasz,
Hmm, yea, it looks like that is currently the only way to do it. Looking at this, I could probably just make the
PricePropertyValue
itselfIEnumerable<ProductPrice>
which should do the trick.I'll raise a feature request on the issue tracker.
Matt
Hi, Matt
Thanks for a quick reply, as always :)
Anyway, it's good to know, that I've done it right :)
Tomasz
I've just implemented this locally and will be in an upcoming 1.8.1 release.
Until then, yea, what you have is probably the best approach. 👍
Matt
is working on a reply...