Class DefaultItemListItemMergingService<I extends com.broadleafcommerce.cart.client.domain.ItemListItem>
java.lang.Object
com.broadleafcommerce.cartoperation.service.AbstractItemMergingService<com.broadleafcommerce.cart.client.domain.ItemList,I>
com.broadleafcommerce.cartoperation.service.DefaultItemListItemMergingService<I>
- All Implemented Interfaces:
ItemListItemMergingService<I>
,ItemMergingService<com.broadleafcommerce.cart.client.domain.ItemList,
I>
public class DefaultItemListItemMergingService<I extends com.broadleafcommerce.cart.client.domain.ItemListItem>
extends AbstractItemMergingService<com.broadleafcommerce.cart.client.domain.ItemList,I>
implements ItemListItemMergingService<I>
The default implementation of an item list item merging service.
- Author:
- Jacob Mitash
-
Constructor Summary
ConstructorDescriptionDefaultItemListItemMergingService
(@NonNull CatalogProvider<? extends CatalogItem> catalogProvider, @NonNull CartOperationServiceProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionprotected CatalogItemRequest
buildCatalogItemRequest
(@NonNull MergeItemPair<I> mergeItemPair, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Hook point to build theCatalogItemRequest
and populate any additional attributes that should be passed to theCatalogProvider
when fetching the catalog representation for merging the item list item.protected Collection<CatalogItemRequest>
buildCatalogItemRequestsForMergeItem
(@NonNull List<MergeItemPair<I>> mergeItemPairs, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
doMergeCombine
(@NonNull MergeItemPair<I> itemPair) Perform the actual combination of two items (quantity change) for the combination merge type.protected CatalogProvider<? extends CatalogItem>
protected Collection<I>
getItemsFromContainer
(@NonNull com.broadleafcommerce.cart.client.domain.ItemList container, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Gets the from the item container.protected CartOperationServiceProperties
protected com.broadleafcommerce.common.extension.TypeFactory
protected String
hashMatchingCriteria
(@NonNull com.broadleafcommerce.cart.client.domain.ItemListItem item) Generates a hash for any information on the item that should be used to determine if they represent the same item configuration.protected String
identifyCatalogItemKey
(@NonNull MergeItemPair<I> mergeItemPair, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected boolean
isSameItem
(@NonNull com.broadleafcommerce.cart.client.domain.ItemListItem item1, @NonNull com.broadleafcommerce.cart.client.domain.ItemListItem item2) Tells if two item instances are actually the same instance.protected void
resolveMergeTypes
(@NonNull List<MergeItemPair<I>> mergeItemPairs, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Determines what merge types should be used for the items and applies it to the merge item pairs.void
setTypeFactory
(com.broadleafcommerce.common.extension.TypeFactory typeFactory) Methods inherited from class com.broadleafcommerce.cartoperation.service.AbstractItemMergingService
findMatchingItems, findMatchingItems, handleRejectedMerges, merge, mergeCombine, mergeIgnore, mergeItems, mergeSeparate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.cartoperation.service.ItemMergingService
mergeItems
-
Constructor Details
-
DefaultItemListItemMergingService
public DefaultItemListItemMergingService(@NonNull @NonNull CatalogProvider<? extends CatalogItem> catalogProvider, @NonNull @NonNull CartOperationServiceProperties properties)
-
-
Method Details
-
getItemsFromContainer
protected Collection<I> getItemsFromContainer(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.ItemList container, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from class:AbstractItemMergingService
Gets the from the item container.- Specified by:
getItemsFromContainer
in classAbstractItemMergingService<com.broadleafcommerce.cart.client.domain.ItemList,
I extends com.broadleafcommerce.cart.client.domain.ItemListItem> - Parameters:
container
- the container to fetch the items fromcontext
- the context of the request- Returns:
- the items from the container
-
isSameItem
protected boolean isSameItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.ItemListItem item1, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.ItemListItem item2) Description copied from class:AbstractItemMergingService
Tells if two item instances are actually the same instance. This would typically be determined by something like the item ID. Note that this does NOT indicate that "these items are the same so they should be merged". This is used to prevent creating an item match with itself during an update scenario.- Specified by:
isSameItem
in classAbstractItemMergingService<com.broadleafcommerce.cart.client.domain.ItemList,
I extends com.broadleafcommerce.cart.client.domain.ItemListItem> - Parameters:
item1
- an item to compareitem2
- another item to compare- Returns:
- true if the two items are referring to the same instance
-
hashMatchingCriteria
protected String hashMatchingCriteria(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.ItemListItem item) Description copied from class:AbstractItemMergingService
Generates a hash for any information on the item that should be used to determine if they represent the same item configuration. For example, if an item contains a reference to a SKU with no options, this should hash the SKU reference since that can be used to determine if two items are the same.This implementation uses the following criteria:
- attribute choices, which are product options of type CART_ITEM_ATTRIBUTE or VARIANT_DISTINGUISHING
- sku, which uniquely identifies products and their variations
- merchandising context, which identifies selector products
- pricing key- Specified by:
hashMatchingCriteria
in classAbstractItemMergingService<com.broadleafcommerce.cart.client.domain.ItemList,
I extends com.broadleafcommerce.cart.client.domain.ItemListItem> - Parameters:
item
- the item to generate a hash for- Returns:
- a hashed string of some subset of the items attributes
-
resolveMergeTypes
protected void resolveMergeTypes(@NonNull @NonNull List<MergeItemPair<I>> mergeItemPairs, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from class:AbstractItemMergingService
Determines what merge types should be used for the items and applies it to the merge item pairs.- Specified by:
resolveMergeTypes
in classAbstractItemMergingService<com.broadleafcommerce.cart.client.domain.ItemList,
I extends com.broadleafcommerce.cart.client.domain.ItemListItem> - Parameters:
mergeItemPairs
- the item pairs to resolve the merge types for
-
buildCatalogItemRequestsForMergeItem
protected Collection<CatalogItemRequest> buildCatalogItemRequestsForMergeItem(@NonNull @NonNull List<MergeItemPair<I>> mergeItemPairs, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) -
buildCatalogItemRequest
protected CatalogItemRequest buildCatalogItemRequest(@NonNull @NonNull MergeItemPair<I> mergeItemPair, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Hook point to build theCatalogItemRequest
and populate any additional attributes that should be passed to theCatalogProvider
when fetching the catalog representation for merging the item list item.- Parameters:
mergeItemPair
- theMergeItemPair
containing the details for the item mergecontext
- context information around sandbox and multitenant state- Returns:
- the populated
CatalogItemRequest
for theItemListItem
-
identifyCatalogItemKey
protected String identifyCatalogItemKey(@NonNull @NonNull MergeItemPair<I> mergeItemPair, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) -
doMergeCombine
Description copied from class:AbstractItemMergingService
Perform the actual combination of two items (quantity change) for the combination merge type.- Specified by:
doMergeCombine
in classAbstractItemMergingService<com.broadleafcommerce.cart.client.domain.ItemList,
I extends com.broadleafcommerce.cart.client.domain.ItemListItem> - Parameters:
itemPair
- the item pair to combine
-
getCatalogProvider
-
getProperties
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
setTypeFactory
@Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-