Class ShoppingCartServiceImpl
- java.lang.Object
-
- co.mastermindcms.modules.services.ShoppingCartServiceImpl
-
- All Implemented Interfaces:
ShoppingCartService
@Service public class ShoppingCartServiceImpl extends java.lang.Object implements ShoppingCartService
-
-
Field Summary
Fields Modifier and Type Field Description private AccessManagementServiceaccessManagementServiceprivate CommerceItemRepositorycommerceItemRepositoryprivate CommerceItemServicecommerceItemServiceprivate static com.fasterxml.jackson.databind.ObjectMappermapperprivate SellerRepositorysellerRepositoryprivate SellerSkuRepositorysellerSkuRepositoryprivate SequenceGeneratorServicesequenceGeneratorprivate ShoppingCartRepositoryshoppingCartRepository
-
Constructor Summary
Constructors Constructor Description ShoppingCartServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ShoppingCartDTOaddCommerceItem(AddToCartRequest request)Adds item.private CommerceItemaddCommerceItem(ShoppingCart cart, java.lang.String sellerSkuId, java.math.BigDecimal price, java.lang.Double quantity, java.util.Map<java.lang.String,java.lang.Object> specs, SellerSKU sku)ShoppingCartDTOaddCommerceItem(java.lang.String sellerSkuId)Adds item, simplified approach.ShoppingCartDTOaddCommerceItem(java.util.LinkedHashMap<java.lang.String,java.lang.Object> data)Adds item.ShoppingCartDTOaddCommerceItems(MultipleAddToCartRequest request)Adds item.ShoppingCartDTOaddCommerceItems(java.util.LinkedHashMap<java.lang.String,java.lang.Object> data)Adds item.booleancanAddItem(java.lang.String sellerSkuId)Checks if item is available to add.booleancheckCurrencyForCart(SellerSKU sellerSku)Checking an item to be added to cart with the same currency as the first item.booleancheckInventory(SellerSKU sellerSku)Checks if default price is definedbooleancheckPrice(SellerSKU sellerSku)Checks if default price is definedbooleancheckRestQuantity(SellerSKU sellerSku)Checks if at least minimum order of the inventory could be added to the cart.booleancheckStripeConnect(SellerSKU sellerSku)Checking a stripe connect activation for the sellervoidclearCart()Removes all commerce items from cart.ShoppingCartDTOdecreaseQuantity(java.lang.String itemId)Decreases quantity of commerce item.private ShoppingCartgetCart()private ShoppingCartgetCart(java.lang.String buyerId)ShoppingCartDTOgetCartDTO()Returns DTO of a current cart.ShoppingCartDTOgetCartDTO(java.lang.String buyerId)Returns DTO of a current cart.private java.util.Optional<SellerSKU>getSellerSkuFromCommerceItem(java.util.Optional<CommerceItem> item)ShoppingCartDTOincreaseQuantity(java.lang.String itemId)Increases quantity of commerce item.private ShoppingCartDTOmapToDTO(ShoppingCart cart)ShoppingCartDTOremoveCommerceItem(java.lang.String itemId)Removes item.ShoppingCartDTOupdateQuantity(java.lang.String itemId, java.lang.String quantity)Decreases quantity of commerce item.
-
-
-
Field Detail
-
shoppingCartRepository
@Autowired private ShoppingCartRepository shoppingCartRepository
-
accessManagementService
@Autowired private AccessManagementService accessManagementService
-
commerceItemRepository
@Autowired private CommerceItemRepository commerceItemRepository
-
sellerSkuRepository
@Autowired private SellerSkuRepository sellerSkuRepository
-
sellerRepository
@Autowired private SellerRepository sellerRepository
-
sequenceGenerator
@Autowired private SequenceGeneratorService sequenceGenerator
-
commerceItemService
@Autowired private CommerceItemService commerceItemService
-
mapper
private static final com.fasterxml.jackson.databind.ObjectMapper mapper
-
-
Method Detail
-
getCartDTO
@Transactional public ShoppingCartDTO getCartDTO()
Description copied from interface:ShoppingCartServiceReturns DTO of a current cart.- Specified by:
getCartDTOin interfaceShoppingCartService- Returns:
- DTO
-
getCartDTO
public ShoppingCartDTO getCartDTO(java.lang.String buyerId)
Description copied from interface:ShoppingCartServiceReturns DTO of a current cart.- Specified by:
getCartDTOin interfaceShoppingCartService- Parameters:
buyerId- identification of buyer id- Returns:
- DTO of buyer cart
-
addCommerceItem
@Transactional public ShoppingCartDTO addCommerceItem(java.lang.String sellerSkuId)
Description copied from interface:ShoppingCartServiceAdds item, simplified approach.- Specified by:
addCommerceItemin interfaceShoppingCartService- Parameters:
sellerSkuId- id of SellerSKU to add- Returns:
- DTO of the cart
-
addCommerceItems
public ShoppingCartDTO addCommerceItems(java.util.LinkedHashMap<java.lang.String,java.lang.Object> data)
Description copied from interface:ShoppingCartServiceAdds item.- Specified by:
addCommerceItemsin interfaceShoppingCartService- Parameters:
data- request object which contains all necessary information to add multiple items to cart- Returns:
- DTO of the cart
-
addCommerceItems
public ShoppingCartDTO addCommerceItems(MultipleAddToCartRequest request)
Description copied from interface:ShoppingCartServiceAdds item.- Specified by:
addCommerceItemsin interfaceShoppingCartService- Parameters:
request- multiple items of SellerSKU to add- Returns:
- DTO of the cart
-
addCommerceItem
public ShoppingCartDTO addCommerceItem(java.util.LinkedHashMap<java.lang.String,java.lang.Object> data)
Description copied from interface:ShoppingCartServiceAdds item.- Specified by:
addCommerceItemin interfaceShoppingCartService- Parameters:
data- request object which contains all necessary information to add item to cart- Returns:
- DTO of the cart
-
addCommerceItem
public ShoppingCartDTO addCommerceItem(AddToCartRequest request)
Description copied from interface:ShoppingCartServiceAdds item.- Specified by:
addCommerceItemin interfaceShoppingCartService- Parameters:
request- id of SellerSKU to add- Returns:
- DTO of the cart
-
removeCommerceItem
@Transactional public ShoppingCartDTO removeCommerceItem(java.lang.String itemId)
Description copied from interface:ShoppingCartServiceRemoves item.- Specified by:
removeCommerceItemin interfaceShoppingCartService- Parameters:
itemId- id of commerce item to remove- Returns:
- DTO of the cart
-
clearCart
@Transactional public void clearCart()
Description copied from interface:ShoppingCartServiceRemoves all commerce items from cart.- Specified by:
clearCartin interfaceShoppingCartService
-
decreaseQuantity
public ShoppingCartDTO decreaseQuantity(java.lang.String itemId)
Description copied from interface:ShoppingCartServiceDecreases quantity of commerce item.- Specified by:
decreaseQuantityin interfaceShoppingCartService- Parameters:
itemId- id of the item- Returns:
- DTO of the cart
-
updateQuantity
public ShoppingCartDTO updateQuantity(java.lang.String itemId, java.lang.String quantity)
Description copied from interface:ShoppingCartServiceDecreases quantity of commerce item.- Specified by:
updateQuantityin interfaceShoppingCartService- Parameters:
itemId- id of the itemquantity- string value to update item quantity- Returns:
- DTO of the cart
-
increaseQuantity
public ShoppingCartDTO increaseQuantity(java.lang.String itemId)
Description copied from interface:ShoppingCartServiceIncreases quantity of commerce item.- Specified by:
increaseQuantityin interfaceShoppingCartService- Parameters:
itemId- id of the item- Returns:
- DTO of the cart
-
canAddItem
public boolean canAddItem(java.lang.String sellerSkuId)
Description copied from interface:ShoppingCartServiceChecks if item is available to add.- Specified by:
canAddItemin interfaceShoppingCartService- Parameters:
sellerSkuId- seller sku ID- Returns:
true— if item is available to add
-
checkPrice
public boolean checkPrice(SellerSKU sellerSku)
Description copied from interface:ShoppingCartServiceChecks if default price is defined- Specified by:
checkPricein interfaceShoppingCartService- Parameters:
sellerSku- sellerSKU as entity- Returns:
- true if the price is defined
-
checkInventory
public boolean checkInventory(SellerSKU sellerSku)
Description copied from interface:ShoppingCartServiceChecks if default price is defined- Specified by:
checkInventoryin interfaceShoppingCartService- Parameters:
sellerSku- sellerSKU as entity- Returns:
- true if the inventory is contains requested item
-
checkRestQuantity
public boolean checkRestQuantity(SellerSKU sellerSku)
Description copied from interface:ShoppingCartServiceChecks if at least minimum order of the inventory could be added to the cart.- Specified by:
checkRestQuantityin interfaceShoppingCartService- Parameters:
sellerSku- SellerSKU as entity- Returns:
- true if the quantity could be increased
-
checkCurrencyForCart
public boolean checkCurrencyForCart(SellerSKU sellerSku)
Description copied from interface:ShoppingCartServiceChecking an item to be added to cart with the same currency as the first item.- Specified by:
checkCurrencyForCartin interfaceShoppingCartService- Parameters:
sellerSku- SellerSKU as entity- Returns:
- true if the quantity could be increased
-
checkStripeConnect
public boolean checkStripeConnect(SellerSKU sellerSku)
Description copied from interface:ShoppingCartServiceChecking a stripe connect activation for the seller- Specified by:
checkStripeConnectin interfaceShoppingCartService- Parameters:
sellerSku- SellerSKU as entity- Returns:
- check if stripe connect is activated
-
getSellerSkuFromCommerceItem
private java.util.Optional<SellerSKU> getSellerSkuFromCommerceItem(java.util.Optional<CommerceItem> item)
-
getCart
private ShoppingCart getCart()
-
getCart
private ShoppingCart getCart(java.lang.String buyerId)
-
mapToDTO
private ShoppingCartDTO mapToDTO(ShoppingCart cart)
-
addCommerceItem
private CommerceItem addCommerceItem(ShoppingCart cart, java.lang.String sellerSkuId, java.math.BigDecimal price, java.lang.Double quantity, java.util.Map<java.lang.String,java.lang.Object> specs, SellerSKU sku)
-
-