use of com.salesmanager.shop.populator.shoppingCart.ShoppingCartDataPopulator in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method removeCartItem.
@Override
public ShoppingCartData removeCartItem(final Long itemID, final String cartId, final MerchantStore store, final Language language) throws Exception {
if (StringUtils.isNotBlank(cartId)) {
ShoppingCart cartModel = getCartModel(cartId, store);
if (cartModel != null) {
if (CollectionUtils.isNotEmpty(cartModel.getLineItems())) {
Set<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> shoppingCartItemSet = new HashSet<com.salesmanager.core.model.shoppingcart.ShoppingCartItem>();
for (com.salesmanager.core.model.shoppingcart.ShoppingCartItem shoppingCartItem : cartModel.getLineItems()) {
if (shoppingCartItem.getId().longValue() == itemID.longValue()) {
shoppingCartService.deleteShoppingCartItem(itemID);
} else {
shoppingCartItemSet.add(shoppingCartItem);
}
}
cartModel.setLineItems(shoppingCartItemSet);
ShoppingCartDataPopulator shoppingCartDataPopulator = new ShoppingCartDataPopulator();
shoppingCartDataPopulator.setShoppingCartCalculationService(shoppingCartCalculationService);
shoppingCartDataPopulator.setPricingService(pricingService);
shoppingCartDataPopulator.setimageUtils(imageUtils);
return shoppingCartDataPopulator.populate(cartModel, store, language);
}
}
}
return null;
}
use of com.salesmanager.shop.populator.shoppingCart.ShoppingCartDataPopulator in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method updateCartItems.
// TODO promoCode request parameter
@Override
public ShoppingCartData updateCartItems(Optional<String> promoCode, final List<ShoppingCartItem> shoppingCartItems, final MerchantStore store, final Language language) throws Exception {
Validate.notEmpty(shoppingCartItems, "shoppingCartItems null or empty");
ShoppingCart cartModel = null;
Set<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> cartItems = new HashSet<com.salesmanager.core.model.shoppingcart.ShoppingCartItem>();
for (ShoppingCartItem item : shoppingCartItems) {
if (item.getQuantity() < 1) {
throw new CartModificationException("Quantity must not be less than one");
}
if (cartModel == null) {
cartModel = getCartModel(item.getCode(), store);
}
com.salesmanager.core.model.shoppingcart.ShoppingCartItem entryToUpdate = getEntryToUpdate(item.getId(), cartModel);
if (entryToUpdate == null) {
throw new CartModificationException("Unknown entry number.");
}
entryToUpdate.getProduct();
LOG.info("Updating cart entry quantity to" + item.getQuantity());
entryToUpdate.setQuantity((int) item.getQuantity());
List<ProductAttribute> productAttributes = new ArrayList<ProductAttribute>();
productAttributes.addAll(entryToUpdate.getProduct().getAttributes());
final FinalPrice finalPrice = productPriceUtils.getFinalProductPrice(entryToUpdate.getProduct(), productAttributes);
entryToUpdate.setItemPrice(finalPrice.getFinalPrice());
cartItems.add(entryToUpdate);
}
cartModel.setPromoCode(null);
if (promoCode.isPresent()) {
cartModel.setPromoCode(promoCode.get());
cartModel.setPromoAdded(new Date());
}
cartModel.setLineItems(cartItems);
shoppingCartService.saveOrUpdate(cartModel);
LOG.info("Cart entry updated with desired quantity");
ShoppingCartDataPopulator shoppingCartDataPopulator = new ShoppingCartDataPopulator();
shoppingCartDataPopulator.setShoppingCartCalculationService(shoppingCartCalculationService);
shoppingCartDataPopulator.setPricingService(pricingService);
shoppingCartDataPopulator.setimageUtils(imageUtils);
return shoppingCartDataPopulator.populate(cartModel, store, language);
}
use of com.salesmanager.shop.populator.shoppingCart.ShoppingCartDataPopulator in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method updateCartItem.
@Override
public ShoppingCartData updateCartItem(final Long itemID, final String cartId, final long newQuantity, final MerchantStore store, final Language language) throws Exception {
if (newQuantity < 1) {
throw new CartModificationException("Quantity must not be less than one");
}
if (StringUtils.isNotBlank(cartId)) {
ShoppingCart cartModel = getCartModel(cartId, store);
if (cartModel != null) {
com.salesmanager.core.model.shoppingcart.ShoppingCartItem entryToUpdate = getEntryToUpdate(itemID.longValue(), cartModel);
if (entryToUpdate == null) {
throw new CartModificationException("Unknown entry number.");
}
entryToUpdate.getProduct();
LOG.info("Updating cart entry quantity to" + newQuantity);
entryToUpdate.setQuantity((int) newQuantity);
List<ProductAttribute> productAttributes = new ArrayList<ProductAttribute>();
productAttributes.addAll(entryToUpdate.getProduct().getAttributes());
final FinalPrice finalPrice = productPriceUtils.getFinalProductPrice(entryToUpdate.getProduct(), productAttributes);
entryToUpdate.setItemPrice(finalPrice.getFinalPrice());
shoppingCartService.saveOrUpdate(cartModel);
LOG.info("Cart entry updated with desired quantity");
ShoppingCartDataPopulator shoppingCartDataPopulator = new ShoppingCartDataPopulator();
shoppingCartDataPopulator.setShoppingCartCalculationService(shoppingCartCalculationService);
shoppingCartDataPopulator.setPricingService(pricingService);
shoppingCartDataPopulator.setimageUtils(imageUtils);
return shoppingCartDataPopulator.populate(cartModel, store, language);
}
}
return null;
}
use of com.salesmanager.shop.populator.shoppingCart.ShoppingCartDataPopulator in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method getShoppingCartData.
// @Override
public ShoppingCartData getShoppingCartData(ShoppingCart shoppingCartModel, Language language) throws Exception {
Validate.notNull(shoppingCartModel, "Shopping Cart cannot be null");
ShoppingCartDataPopulator shoppingCartDataPopulator = new ShoppingCartDataPopulator();
shoppingCartDataPopulator.setShoppingCartCalculationService(shoppingCartCalculationService);
shoppingCartDataPopulator.setPricingService(pricingService);
shoppingCartDataPopulator.setimageUtils(imageUtils);
// Language language = (Language) getKeyValue( Constants.LANGUAGE );
MerchantStore merchantStore = (MerchantStore) getKeyValue(Constants.MERCHANT_STORE);
return shoppingCartDataPopulator.populate(shoppingCartModel, merchantStore, language);
}
use of com.salesmanager.shop.populator.shoppingCart.ShoppingCartDataPopulator in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method addItemsToShoppingCart.
@Override
public ShoppingCartData addItemsToShoppingCart(final ShoppingCartData shoppingCartData, final ShoppingCartItem item, final MerchantStore store, final Language language, final Customer customer) throws Exception {
ShoppingCart cartModel = null;
/**
* Sometimes a user logs in and a shopping cart is present in db (shoppingCartData
* but ui has no cookie with shopping cart code so the cart code will have
* to be added to the item in order to process add to cart normally
*/
if (shoppingCartData != null && StringUtils.isBlank(item.getCode())) {
item.setCode(shoppingCartData.getCode());
}
if (!StringUtils.isBlank(item.getCode())) {
// get it from the db
cartModel = getShoppingCartModel(item.getCode(), store);
if (cartModel == null) {
cartModel = createCartModel(shoppingCartData.getCode(), store, customer);
}
}
if (cartModel == null) {
final String shoppingCartCode = StringUtils.isNotBlank(shoppingCartData.getCode()) ? shoppingCartData.getCode() : null;
cartModel = createCartModel(shoppingCartCode, store, customer);
}
com.salesmanager.core.model.shoppingcart.ShoppingCartItem shoppingCartItem = createCartItem(cartModel, item, store);
boolean duplicateFound = false;
if (CollectionUtils.isEmpty(item.getShoppingCartAttributes())) {
// increment quantity
// get duplicate item from the cart
Set<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> cartModelItems = cartModel.getLineItems();
for (com.salesmanager.core.model.shoppingcart.ShoppingCartItem cartItem : cartModelItems) {
if (cartItem.getProduct().getId().longValue() == shoppingCartItem.getProduct().getId().longValue()) {
if (CollectionUtils.isEmpty(cartItem.getAttributes())) {
if (!duplicateFound) {
if (!shoppingCartItem.isProductVirtual()) {
cartItem.setQuantity(cartItem.getQuantity() + shoppingCartItem.getQuantity());
}
duplicateFound = true;
break;
}
}
}
}
}
if (!duplicateFound) {
// shoppingCartItem.getAttributes().stream().forEach(a -> {a.setProductAttributeId(productAttributeId);});
cartModel.getLineItems().add(shoppingCartItem);
}
/**
* Update cart in database with line items *
*/
shoppingCartService.saveOrUpdate(cartModel);
// refresh cart
cartModel = shoppingCartService.getById(cartModel.getId(), store);
shoppingCartCalculationService.calculate(cartModel, store, language);
ShoppingCartDataPopulator shoppingCartDataPopulator = new ShoppingCartDataPopulator();
shoppingCartDataPopulator.setShoppingCartCalculationService(shoppingCartCalculationService);
shoppingCartDataPopulator.setPricingService(pricingService);
shoppingCartDataPopulator.setimageUtils(imageUtils);
return shoppingCartDataPopulator.populate(cartModel, store, language);
}
Aggregations