cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Why does addToCart merges entrys AFTER recalculating the cart?

Former Member
212

We are using Hybris Commerce in version 6.5.

In DefaultCommerceAddToCartStrategy from the b2boccaddon the following steps will be performed after adding an entry to the card:

 @Override
 public CommerceCartModification addToCart(final CommerceCartParameter parameter) throws CommerceCartModificationException
 {
     final CommerceCartModification modification = doAddToCart(parameter);
     getCommerceCartCalculationStrategy().calculateCart(parameter);
     afterAddToCart(parameter, modification);
     // Here the entry is fully populated, so we can search for a similar one and merge.
     mergeEntry(modification, parameter);
     return modification;
 }


The problem is: if you add the same product which is already in the cart -> the cart will be calculated and after that the positions will be merged with the effect that subtotal of the merged entry is wrong! Imho the code should look like:

 public CommerceCartModification addToCart(final CommerceCartParameter parameter) throws CommerceCartModificationException
 {
     final CommerceCartModification modification = doAddToCart(parameter);
         // Here the entry is fully populated, so we can search for a similar one and merge.
     mergeEntry(modification, parameter);
     getCommerceCartCalculationStrategy().calculateCart(parameter);
     afterAddToCart(parameter, modification);
 
     return modification;
 }


What do you think?

Accepted Solutions (0)

Answers (0)