Package de.hybris.platform.order
Interface CartService
-
- All Superinterfaces:
AbstractOrderService<CartModel,CartEntryModel>
- All Known Subinterfaces:
B2BCartService
- All Known Implementing Classes:
DefaultB2BCartService
,DefaultCartService
,DefaultCartServiceForAccelerator
public interface CartService extends AbstractOrderService<CartModel,CartEntryModel>
Service providing cart oriented functionality. On contrary to order, cart does not represent a legal contract with the customer, but similarly toOrderModel
,CartModel
is a subtype ofAbstractOrderModel
, so the service fulfills the contract ofAbstractOrderService
for theCartModel
andCartEntryModel
types. Additionally it provides methods for handling the session cart.- Spring Bean ID:
- cartService
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
addToCart(CartModel cart, ProductModel product, long quantity, UnitModel unit)
Deprecated.since 6.2.0 - UseAbstractOrderService.addNewEntry(AbstractOrderModel, ProductModel, long, UnitModel)
from the cart service instead.void
appendToCart(CartModel sourceCart, CartModel targetCart)
Clones all entries of source cart to the target cart.boolean
calculateCart(CartModel cartModel)
Deprecated.since 6.2.0 - UseCalculationService.calculate(AbstractOrderModel)
to calculate carts.void
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
createCartFromQuote(QuoteModel quote)
Creates a new cart based on the givenQuoteModel
.CartModel
getSessionCart()
Returns the cart attached to the current session.boolean
hasCart()
Deprecated.since 6.2.0 - usehasSessionCart()
boolean
hasSessionCart()
Returnstrue
if the current session already holds a cart,false
otherwise.void
removeSessionCart()
If existing the current session cart is being detached from this session and removed.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.0 - Update cart entries quantities directly viaAbstractOrderEntryModel.setQuantity(Long)
or useupdateQuantities(CartModel, Map)
void
updateQuantities(CartModel cart, java.util.Map<java.lang.Integer,java.lang.Long> quantities)
Updates multiple cart entry quantities at once.-
Methods inherited from interface de.hybris.platform.order.AbstractOrderService
addAllGlobalDiscountValues, addAllTotalTaxValues, addGlobalDiscountValue, addNewEntry, addNewEntry, addNewEntry, addTotalTaxValue, clone, getEntriesForNumber, getEntriesForProduct, getEntryForNumber, getGlobalDiscountValue, removeGlobalDiscountValue, removeTotalTaxValue, saveOrder
-
-
-
-
Method Detail
-
addToCart
@Deprecated void addToCart(CartModel cart, ProductModel product, long quantity, UnitModel unit) throws InvalidCartException
Deprecated.since 6.2.0 - UseAbstractOrderService.addNewEntry(AbstractOrderModel, ProductModel, long, UnitModel)
from the cart service instead. Please mind the fact thatAbstractOrderService.addNewEntry(AbstractOrderModel, ProductModel, long, UnitModel)
method does not calculate or save the cart.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.- Parameters:
cart
- the cart, must existproduct
- the product which is added to the cartquantity
- the quantity of the productunit
- 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
)
-
setSessionCart
void setSessionCart(CartModel cart)
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.
-
getSessionCart
CartModel getSessionCart()
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.
-
removeSessionCart
void removeSessionCart()
If existing the current session cart is being detached from this session and removed. Afterwards it's no longer available.- See Also:
getSessionCart()
,setSessionCart(CartModel)
-
hasSessionCart
boolean hasSessionCart()
Returnstrue
if the current session already holds a cart,false
otherwise. Please use this instead ofgetSessionCart()
if you like to avoid unnecessary auto-creation of the session cart.- See Also:
getSessionCart()
-
hasCart
@Deprecated boolean hasCart()
Deprecated.since 6.2.0 - usehasSessionCart()
-
calculateCart
@Deprecated boolean calculateCart(CartModel cartModel)
Deprecated.since 6.2.0 - UseCalculationService.calculate(AbstractOrderModel)
to calculate carts.Calculates the givencartModel
and returnstrue
if each entry and after this theCartModel
was calculated. Thereby any invalid entry will be automatically removed.- Parameters:
cartModel
- theCartModel
- Returns:
false
if thecartModel
was already calculated.
-
updateQuantities
@Deprecated void updateQuantities(CartModel cart, java.util.List<java.lang.Long> quantities)
Deprecated.since 6.2.0 - Update cart entries quantities directly viaAbstractOrderEntryModel.setQuantity(Long)
or useupdateQuantities(CartModel, Map)
Updates the quantities of each cart entry with the list ofquantities
. If the quantity value is 0 the cart entry is removed.- Parameters:
cart
- the cart where the quantities are updatedquantities
- the new quantity list for each cart entry
-
updateQuantities
void updateQuantities(CartModel cart, java.util.Map<java.lang.Integer,java.lang.Long> quantities)
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.
- Parameters:
cart
- the cart to update cart entry quantities atquantities
- the entry specific quantities as map of { entry number -> quantity }
-
appendToCart
void appendToCart(CartModel sourceCart, CartModel targetCart)
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.- Parameters:
sourceCart
- the cart providing the entries to copytargetCart
- the target cart to create new entries for- Throws:
java.lang.IllegalArgumentException
- if targetCart is null.
-
changeCurrentCartUser
void changeCurrentCartUser(UserModel user)
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.- Parameters:
user
- new session cart user- Throws:
java.lang.IllegalArgumentException
- when user is null
-
changeSessionCartCurrency
void changeSessionCartCurrency(CurrencyModel currency)
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.- Parameters:
currency
- new session cart currency
-
createCartFromQuote
CartModel createCartFromQuote(QuoteModel quote)
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.- Parameters:
quote
- the quote model- Returns:
- the new cart model
- Throws:
java.lang.IllegalArgumentException
- when quote is null
-
-