Im tring to figure out how i can set up the orderlines sortorder in TeaCommerce.
By default it seems that the sortorder is the same order as the items are added to the cart but my client has asked if its possible to configure the cart to always show the most expensive products first.
Sure i could do a .OrderBy() in every view, but i want this sortorder to be saved on the order object, and not just "displayed" as ordered, so that this order also gets applied in all my views, in my confimation email and in the backoffice. Also, ive created a custom OrderCalculator and i loop through my orderlines with CalculateOrderLineUnitPrice and do some custom price calculations and i want this loop to also be looped in the order by price and not the order they got added to the cart.
Is there a Sort function i could use or a workaround?
That is a good question. as the DB doesnt have any sort order for order lines other than the order they were added this is not possible out of the box. I think the "easy" way to do it is to make an extension method that sorts the order lines the places you need it. This means you have to make a custom order calculator that runs the order lines in the right order. I can't think of a smarter way to do it as you would then have to extend the order line with a sort order property and then make your own order repository that pulls in the order from DB with discounts, order lines etc and uses the custom order line property.
Orderline sortorder.
Hi.
Im tring to figure out how i can set up the orderlines sortorder in TeaCommerce. By default it seems that the sortorder is the same order as the items are added to the cart but my client has asked if its possible to configure the cart to always show the most expensive products first.
Sure i could do a .OrderBy() in every view, but i want this sortorder to be saved on the order object, and not just "displayed" as ordered, so that this order also gets applied in all my views, in my confimation email and in the backoffice. Also, ive created a custom OrderCalculator and i loop through my orderlines with CalculateOrderLineUnitPrice and do some custom price calculations and i want this loop to also be looped in the order by price and not the order they got added to the cart.
Is there a Sort function i could use or a workaround?
Thank you!
Hi Dennis
That is a good question. as the DB doesnt have any sort order for order lines other than the order they were added this is not possible out of the box. I think the "easy" way to do it is to make an extension method that sorts the order lines the places you need it. This means you have to make a custom order calculator that runs the order lines in the right order. I can't think of a smarter way to do it as you would then have to extend the order line with a sort order property and then make your own order repository that pulls in the order from DB with discounts, order lines etc and uses the custom order line property.
Kind regards
Anders
Thank you Anders for the reply. I´ll look in this that.
/ Dennis
is working on a reply...