foreach (var product in categorySection.Children)
{
var imageIds = product.productImages.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
var images = Umbraco.Media(imageIds);
var firstImage = images.FirstOrDefault();
var firstImageUrl = firstImage.Url;
var firstImageCropUrl = firstImage.GetCropUrl("category image");
<div class="product">
<a href="@product.Url">
<img src="@firstImageCropUrl" />
<span class="brand">@categorySection.Name</span>
<span class="model">@product.Name</span>
</a>
<div class="price">
@product.GetPropertyValue("price") DKK
</div>
</div>
}
As you can see, the PRICE is just a textstring, nothing fancy there.
I would like to be able to sort the bikes by price as you can see in the sidebar where I have a couple of A-tags, none of them works and that's the thing: How do I enable a sorting/filtering feature in Umbraco, based on the price/textstring property?
You just need to add some get param to each filter, and if request contains this param - filter "categorySection.Children" by this param, it's not hard with LINQ.
Hey fellas,
Thank you both for joining in on my little (yet epic) adventure to Umbraco's universe ;o)
Now, this is where I kinda lose track because I'm not that experienced with this kind of programming.
I do not have pagning on my site but now that I think about it, it might be a good idéa? If I have 100 bikes on one page, it would take a long time to load.
But since I don't have any paginig, is it possible for me to see an example of how your idéas works? :)
I have paging on and it works wonderfully! I really appreciate you for sharing your work with me and the rest of the community. You deserve a cold pint buddy.
I learned from this forum so It's about time I start to contribute.
Your reply in the email looks different:
Hey Frans,
Epic share! I salute you Sir (high five)
I have created a partial with you're code. I understand SOME of it but
not everything.
So far I have changed all tags with price which works
great in the scenario you described. But I wish not to show all prices
but sections like Price From: 0 – 999, 1000 – 1999 and so forth.
How can I transform your Get All Categories foreach to a grouped
selection of prices?
Product image error
I also seem to have a problem with the buildItem – Thumbnail. I
created an Upload property entitled productImage, but it returns this
error: Cannot implicitly convert type
'Umbraco.Core.Dynamics.DynamicNull' to
'Umbraco.Core.Models.IPublishedContent'. An explicit conversion exists
(are you missing a cast?)
And thank you!
I have paging on and it works wonderfully! I really appreciate the
share Frans.
Hey buddy,
Thank you for still sticking around :o)
A buddy of mine helped me group the prices together, you can see the code below. I just need to check IF there's any products inside each range and display it accordinaly. Not sure how to yet, but I'll try and figure it out :)
Thank you for posting a fix for the images but it renderes this error:
Cannot implicitly convert type 'Umbraco.Core.Dynamics.DynamicNull' to 'Umbraco.Core.Models.IPublishedContent'. An explicit conversion exists (are you missing a cast?)
Sort nodes by property value (price, textstring)
So another day, another question. I'm diggin deeper and deeper into Umbraco and learning a lot from both the community and on my own.
I'm currently working on a little project in Umbraco 7.5.2 where I'd like to show off some products without selling any of them online.
So it bascially looks like this: Roldskov.sp34k.dk
The bikes are rendered out like so:
As you can see, the PRICE is just a textstring, nothing fancy there.
I would like to be able to sort the bikes by price as you can see in the sidebar where I have a couple of A-tags, none of them works and that's the thing: How do I enable a sorting/filtering feature in Umbraco, based on the price/textstring property?
Can I see the backend?
Login removed
Hi Mike,
You just need to add some get param to each filter, and if request contains this param - filter "categorySection.Children" by this param, it's not hard with LINQ.
Thanks,
Alex
There are 2 ways to get the result you want. One is client side filtering with javascript/jquery and the other is serverside.
If you don't have paging on your productpage I'd opt for the Jquery solution otherwise you will have a page reload every time you click on a price.
If you want to sort them serverside I would call the same page with a querystring.
example:
In the view get the value of the querystring:
You can show the bikes fitting the selected pricegroup with a if statement in the foreach.
Hey fellas, Thank you both for joining in on my little (yet epic) adventure to Umbraco's universe ;o)
Now, this is where I kinda lose track because I'm not that experienced with this kind of programming.
I do not have pagning on my site but now that I think about it, it might be a good idéa? If I have 100 bikes on one page, it would take a long time to load.
But since I don't have any paginig, is it possible for me to see an example of how your idéas works? :)
This is a partial view I used in a project.
What I use here is the tags datatype to define a filter menu. One item can be placed in multiple categories.
The comment's aren't that detailed but it should get you started.
Hey Frans,
Epic share! I salute you Sir (high five)
I have paging on and it works wonderfully! I really appreciate you for sharing your work with me and the rest of the community. You deserve a cold pint buddy.
No problem,
I learned from this forum so It's about time I start to contribute.
Your reply in the email looks different:
Did you solve these problems?
Frans
There are a few errors in the code I shared. I'm in the proces of converting all my code to a strongly typed version rather than a dynamic version.
One mistake is in the buildItem helper.
should be:
That solves your error. After that you only need to change thumbnail to your propertyname (productImage).
Hey buddy, Thank you for still sticking around :o)
A buddy of mine helped me group the prices together, you can see the code below. I just need to check IF there's any products inside each range and display it accordinaly. Not sure how to yet, but I'll try and figure it out :)
You can see it in action here: http://roldskov.sp34k.dk/produkter/cykler/mountain-bikes/
Thank you for posting a fix for the images but it renderes this error:
COMPLETE CODE (based on Frans de Jong's code
is working on a reply...