Page 1 of 1

Projection is not supported on the type 'org.broadleafcommer

Posted: Tue Mar 05, 2013 1:30 pm
by rajnish
Hi There,

I'm trying to implement a new subtotal of cart, only on the cart GUI and not in the java code, for this i am using aggregates of thymeleaf like this, in cart.html:

Code: Select all

<tr th:each="item : ${cart.orderItems}" th:object="${item}" >
   <td th:text="*{#aggregates.sum(![salePrice.doubleValue()])}">23.32</td>
</tr>


But this gives me the following error:

Code: Select all

Projection is not supported on the type 'org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl'


Can someone help?

Thanks in advance!

Regards,
Rajnish

Re: Projection is not supported on the type 'org.broadleafcommer

Posted: Tue Mar 05, 2013 1:42 pm
by rajnish
With some trial i realized the i can use cart and not cart.orderItems the loop and changed the code shared earlier to this:

Code: Select all

         <td th:text="${#aggregates.sum(cart.orderItems.![salePrice.doubleValue()])}">23.32</td>

and this work for me.

May be this will be useful for someone.

Thanks!

Re: Projection is not supported on the type 'org.broadleafcommer

Posted: Tue Mar 05, 2013 3:54 pm
by phillipuniverse
Hm interesting; I was unaware of the aggregates Thymeleaf utility. Thanks for sharing!

However, I will point out a potential problem. There is a reason that we use Money/BigDecimal for our representation of monetary value, and that is because of a possible loss of precision. Since you are summing the doubles up, you might end up showing a price to the user that is less than they will actually be charged. For a concrete example of this loss of precision, check out http://docs.broadleafcommerce.org/curre ... Money.html.

Because of this, I would still recommend doing the addition in a Java class. If you did not want to extend Order to do this, you could also create a Thymeleaf processor to sum up the items in the order using Money.add().

Re: Projection is not supported on the type 'org.broadleafcommer

Posted: Wed Mar 06, 2013 3:34 am
by rajnish
Thanks Phillip,

I see your point, I'll look through this option and update here.

Cheers,
Rajnish