Package de.hybris.platform.order.impl
Class DefaultCartService
- java.lang.Object
-
- de.hybris.platform.servicelayer.internal.service.AbstractService
-
- de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
-
- de.hybris.platform.order.impl.DefaultAbstractOrderService<CartModel,CartEntryModel>
-
- de.hybris.platform.order.impl.DefaultCartService
-
- All Implemented Interfaces:
AbstractOrderService<CartModel,CartEntryModel>
,CartService
,java.io.Serializable
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
DefaultB2BCartService
,DefaultCartServiceForAccelerator
public class DefaultCartService extends DefaultAbstractOrderService<CartModel,CartEntryModel> implements CartService
Default implementation of theCartService
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
AbstractService.SerializableDTO
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
SESSION_CART_PARAMETER_NAME
-
Fields inherited from class de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
modelService, sessionService, txManager
-
Fields inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
tenant
-
-
Constructor Summary
Constructors Constructor Description DefaultCartService()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addToCart(CartModel cartModel, ProductModel productModel, long quantity, UnitModel unitModel)
Deprecated.since 6.2.0void
appendToCart(CartModel sourceCart, CartModel targetCart)
Clones all entries of source cart to the target cart.boolean
calculateCart(CartModel cartModel)
Deprecated.since 6.2.0void
changeCurrentCartUser(UserModel user)
Changes the user of the session cart to the given user.void
changeSessionCartCurrency(CurrencyModel currency)
Changes the currency of the session cart to the given currency.CartModel
clone(ComposedTypeModel orderType, ComposedTypeModel entryType, AbstractOrderModel original, java.lang.String code)
Creates new order from given original and change its type and type for entry.CartModel
createCartFromQuote(QuoteModel quote)
Creates a new cart based on the givenQuoteModel
.protected CreateCartFromQuoteStrategy
getCreateCartFromQuoteStrategy()
protected int
getNextEntryNumber(CartModel cart, AbstractOrderEntryModel forMe)
CartModel
getSessionCart()
Returns the cart attached to the current session.boolean
hasCart()
Deprecated.since 6.2.0boolean
hasSessionCart()
Returnstrue
if the current session already holds a cart,false
otherwise.protected CartModel
internalGetSessionCart()
protected void
postProcessClonedEntries(java.util.Collection<CartEntryModel> sourceClones, int lastEntryNo, CartModel targetCart)
Rearrange cloned entries numbers according to last entry number from the target.void
removeSessionCart()
If existing the current session cart is being detached from this session and removed.void
setAddToCartStrategy(AddToCartStrategy addToCartStrategy)
void
setCartFactory(CartFactory cartFactory)
void
setCreateCartFromQuoteStrategy(CreateCartFromQuoteStrategy createCartFromQuoteStrategy)
void
setOrderCalculation(OrderCalculation orderCalculation)
void
setSessionCart(CartModel cart)
Attach the cart to a session.void
updateQuantities(CartModel cart, java.util.List<java.lang.Long> quantities)
Deprecated.since 6.2.0void
updateQuantities(CartModel cart, java.util.Map<java.lang.Integer,java.lang.Long> quantities)
Updates multiple cart entry quantities at once.-
Methods inherited from class de.hybris.platform.order.impl.DefaultAbstractOrderService
addAllGlobalDiscountValues, addAllTotalTaxValues, addEntryAtPosition, addGlobalDiscountValue, addNewEntry, addNewEntry, addNewEntry, addTotalTaxValue, getAbstractOrderEntryService, getAbstractOrderEntryTypeService, getCloneAbstractOrderStrategy, getCollidingEntry, getEntriesForNumber, getEntriesForProduct, getEntryForNumber, getEntryTypeCode, getGlobalDiscountValue, getOrderDao, getSaveAbstractOrderStrategy, removeGlobalDiscountValue, removeTotalTaxValue, saveOrder, setAbstractOrderEntryService, setAbstractOrderEntryTypeService, setCloneAbstractOrderStrategy, setOrderDao, setSaveAbstractOrderStrategy
-
Methods inherited from class de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
getModelService, getSessionService, getTxManager, setModelService, setSessionService, setTxManager
-
Methods inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
afterPropertiesSet, getCurrentTenant, setBeanName, setCurrentTenant, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.hybris.platform.order.AbstractOrderService
addAllGlobalDiscountValues, addAllTotalTaxValues, addGlobalDiscountValue, addNewEntry, addNewEntry, addNewEntry, addTotalTaxValue, getEntriesForNumber, getEntriesForProduct, getEntryForNumber, getGlobalDiscountValue, removeGlobalDiscountValue, removeTotalTaxValue, saveOrder
-
-
-
-
Field Detail
-
SESSION_CART_PARAMETER_NAME
public static final java.lang.String SESSION_CART_PARAMETER_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
addToCart
@Deprecated public void addToCart(CartModel cartModel, ProductModel productModel, long quantity, UnitModel unitModel) throws InvalidCartException
Deprecated.since 6.2.0Description copied from interface:CartService
Adds to the (existing)CartModel
the (existing)ProductModel
in the givenUnitModel
and with the givenquantity
. If in the cart already an entry with the given product and given unit exists the givenquantity
is added to the the quantity of this cart entry. After this the cart is calculated.- Specified by:
addToCart
in interfaceCartService
- Parameters:
cartModel
- the cart, must existproductModel
- the product which is added to the cartquantity
- the quantity of the productunitModel
- ifnull
ProductService.getOrderableUnit(ProductModel)
is used to determine the unit- Throws:
InvalidCartException
- if theproduct
is a base product OR the quantity is less 1 or no usable unit was found (only when givenunit
is alsonull
)
-
hasSessionCart
public boolean hasSessionCart()
Description copied from interface:CartService
Returnstrue
if the current session already holds a cart,false
otherwise. Please use this instead ofCartService.getSessionCart()
if you like to avoid unnecessary auto-creation of the session cart.- Specified by:
hasSessionCart
in interfaceCartService
- See Also:
CartService.getSessionCart()
-
hasCart
@Deprecated public boolean hasCart()
Deprecated.since 6.2.0- Specified by:
hasCart
in interfaceCartService
-
setSessionCart
public void setSessionCart(CartModel cart)
Description copied from interface:CartService
Attach the cart to a session. Please not that a previously existing session cart is being detached and remove during that operation. It will no longer be available afterwards.- Specified by:
setSessionCart
in interfaceCartService
-
getSessionCart
public CartModel getSessionCart()
Description copied from interface:CartService
Returns the cart attached to the current session. The session cart is, just like current user, current currency or language, a part of session data that lives in the session scope.If there is no cart attached to the current session yet, this method will automatically create a new cart and attaches it to the current session.
The creation process is performed by the injected
CartFactory
. As default aDefaultCartFactory
is being used.- Specified by:
getSessionCart
in interfaceCartService
-
internalGetSessionCart
protected CartModel internalGetSessionCart()
-
calculateCart
@Deprecated public boolean calculateCart(CartModel cartModel)
Deprecated.since 6.2.0Description copied from interface:CartService
Calculates the givencartModel
and returnstrue
if each entry and after this theCartModel
was calculated. Thereby any invalid entry will be automatically removed.- Specified by:
calculateCart
in interfaceCartService
- Parameters:
cartModel
- theCartModel
- Returns:
false
if thecartModel
was already calculated.
-
updateQuantities
@Deprecated public void updateQuantities(CartModel cart, java.util.List<java.lang.Long> quantities)
Deprecated.since 6.2.0Description copied from interface:CartService
Updates the quantities of each cart entry with the list ofquantities
. If the quantity value is 0 the cart entry is removed.- Specified by:
updateQuantities
in interfaceCartService
- Parameters:
cart
- the cart where the quantities are updatedquantities
- the new quantity list for each cart entry
-
updateQuantities
public void updateQuantities(CartModel cart, java.util.Map<java.lang.Integer,java.lang.Long> quantities)
Description copied from interface:CartService
Updates multiple cart entry quantities at once. Entries that receive a quantity < 1 will be removed as well as entries that receive NULL as quantity value. Refreshes a given cart instance after that.Entries with entry numbers that do not occur in the parameter map are not touched.
- Specified by:
updateQuantities
in interfaceCartService
- Parameters:
cart
- the cart to update cart entry quantities atquantities
- the entry specific quantities as map of { entry number -> quantity }
-
removeSessionCart
public void removeSessionCart()
Description copied from interface:CartService
If existing the current session cart is being detached from this session and removed. Afterwards it's no longer available.- Specified by:
removeSessionCart
in interfaceCartService
- See Also:
CartService.getSessionCart()
,CartService.setSessionCart(CartModel)
-
clone
public CartModel clone(ComposedTypeModel orderType, ComposedTypeModel entryType, AbstractOrderModel original, java.lang.String code)
Description copied from interface:AbstractOrderService
Creates new order from given original and change its type and type for entry. Delegates to the specificCloneAbstractOrderStrategy
injected strategy. Resulting order remains not persisted.- Specified by:
clone
in interfaceAbstractOrderService<CartModel,CartEntryModel>
- Parameters:
orderType
- type of result order (OrderModel will be chosen if null is passed)entryType
- type of entry (if null will use service to get proper type)original
- original ordercode
- code for new order- Returns:
- not persisted order model instance.
-
appendToCart
public void appendToCart(CartModel sourceCart, CartModel targetCart)
Description copied from interface:CartService
Clones all entries of source cart to the target cart. After this call, the target cart needs recalculation. To do it, useCalculationService
. The target cart is also not persisted after this method call.- Specified by:
appendToCart
in interfaceCartService
- Parameters:
sourceCart
- the cart providing the entries to copytargetCart
- the target cart to create new entries for
-
changeCurrentCartUser
public void changeCurrentCartUser(UserModel user)
Description copied from interface:CartService
Changes the user of the session cart to the given user. Please mind that the session cart may need recalculation after this call, as the price discounts may be user dependent. In case there is no session cart at the time of this method call, one will be created.- Specified by:
changeCurrentCartUser
in interfaceCartService
- Parameters:
user
- new session cart user
-
postProcessClonedEntries
protected void postProcessClonedEntries(java.util.Collection<CartEntryModel> sourceClones, int lastEntryNo, CartModel targetCart)
Rearrange cloned entries numbers according to last entry number from the target.
-
getNextEntryNumber
protected int getNextEntryNumber(CartModel cart, AbstractOrderEntryModel forMe)
-
setAddToCartStrategy
public void setAddToCartStrategy(AddToCartStrategy addToCartStrategy)
-
setOrderCalculation
public void setOrderCalculation(OrderCalculation orderCalculation)
-
setCartFactory
public void setCartFactory(CartFactory cartFactory)
-
changeSessionCartCurrency
public void changeSessionCartCurrency(CurrencyModel currency)
Description copied from interface:CartService
Changes the currency of the session cart to the given currency. Please mind that the session cart need recalculation after this call. In case there is no session cart at the time of this method call, one will be created.- Specified by:
changeSessionCartCurrency
in interfaceCartService
- Parameters:
currency
- new session cart currency
-
createCartFromQuote
public CartModel createCartFromQuote(QuoteModel quote)
Description copied from interface:CartService
Creates a new cart based on the givenQuoteModel
. Please note that it is the caller's responsibility to persist the new cart returned by this method. The quote passed into this method will not be affected by its logic.- Specified by:
createCartFromQuote
in interfaceCartService
- Parameters:
quote
- the quote model- Returns:
- the new cart model
-
getCreateCartFromQuoteStrategy
protected CreateCartFromQuoteStrategy getCreateCartFromQuoteStrategy()
-
setCreateCartFromQuoteStrategy
public void setCreateCartFromQuoteStrategy(CreateCartFromQuoteStrategy createCartFromQuoteStrategy)
-
-