Cart Entry Merge Functionality

The Cart Entry Merge feature joins two cart entries with the same product into one entry, so the cart is kept clean.

Customizable Filters

If cart entries do not have equal bundleTemplate fields, the following EntryMergeStrategy class is implemented to disable merging cart entries. The EntryMergeStrategy class takes the CommerceCartParameter as an input and looks in the entry list to get an entry suitable for merge. To find it, the strategy calls a customizable set of filters. If any of the filters declines the merge, the strategy goes to the next entry. This example filter ensures that an entry has the correct product:
public class EntryMergeFilterProduct implements EntryMergeFilter
{
  @Override
public Boolean apply(@Nonnull final AbstractOrderEntryModel candidate, @Nonnull final AbstractOrderEntryModel target)
  {
    return Boolean.valueOf(Objects.equals(candidate.getProduct(), target.getProduct()));());
  }
}
The method implements the following filters:
Filter name Description
EntryMergeFilterProduct compares product code
EntryMergeFilterUnits compares measurement units
EntryMergeFilterPointOfService compares point of service
EntryMergeFilterIsEntryUpdatable disables changing of unmodifiable entries (giveaway or bundled)
EntryMergeFilterForceNewEntry if the input CommerceCartParameter.isCreateNewEntry flag is set to true, disables any merge
EntryMergeFilterEntryGroup merges only to the same group
EntryMergeFilterConfigurableProduct does not merge configurable products, because they can have different configurations
EntryMergeFilterBundleTemplate does not merge to bundled products. The configurablebundles extension adds this filter.