use of com.salesmanager.core.model.shoppingcart.ShoppingCart 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);
}
use of com.salesmanager.core.model.shoppingcart.ShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method modifyCart.
@Override
public ReadableShoppingCart modifyCart(String cartCode, PersistableShoppingCartItem item, MerchantStore store, Language language) throws Exception {
Validate.notNull(cartCode, "String cart code cannot be null");
Validate.notNull(item, "PersistableShoppingCartItem cannot be null");
ShoppingCart cartModel = getCartModel(cartCode, store);
if (cartModel == null) {
throw new ResourceNotFoundException("Cart code [" + cartCode + "] not found");
}
return modifyCart(cartModel, item, store, language);
}
use of com.salesmanager.core.model.shoppingcart.ShoppingCart in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method mergeCart.
/*
* (non-Javadoc)
*
* @see com.salesmanager.web.shop.controller.customer.facade#mergeCart(final Customer
* customerModel, final String sessionShoppingCartId ,final MerchantStore store,final Language
* language)
*/
@Override
public ShoppingCart mergeCart(final Customer customerModel, final String sessionShoppingCartId, final MerchantStore store, final Language language) throws Exception {
LOG.debug("Starting merge cart process");
if (customerModel != null) {
ShoppingCart customerCart = shoppingCartService.getShoppingCart(customerModel);
if (StringUtils.isNotBlank(sessionShoppingCartId)) {
ShoppingCart sessionShoppingCart = shoppingCartService.getByCode(sessionShoppingCartId, store);
if (sessionShoppingCart != null) {
if (customerCart == null) {
if (sessionShoppingCart.getCustomerId() == null) {
// saved shopping cart does not belong
// to a customer
LOG.debug("Not able to find any shoppingCart with current customer");
// give it to the customer
sessionShoppingCart.setCustomerId(customerModel.getId());
shoppingCartService.saveOrUpdate(sessionShoppingCart);
customerCart = shoppingCartService.getById(sessionShoppingCart.getId(), store);
return customerCart;
// return populateShoppingCartData(customerCart,store,language);
} else {
return null;
}
} else {
if (sessionShoppingCart.getCustomerId() == null) {
// saved shopping cart does not belong
// to a customer
// assign it to logged in user
LOG.debug("Customer shopping cart as well session cart is available, merging carts");
customerCart = shoppingCartService.mergeShoppingCarts(customerCart, sessionShoppingCart, store);
customerCart = shoppingCartService.getById(customerCart.getId(), store);
return customerCart;
// return populateShoppingCartData(customerCart,store,language);
} else {
if (sessionShoppingCart.getCustomerId().longValue() == customerModel.getId().longValue()) {
if (!customerCart.getShoppingCartCode().equals(sessionShoppingCart.getShoppingCartCode())) {
// merge carts
LOG.info("Customer shopping cart as well session cart is available");
customerCart = shoppingCartService.mergeShoppingCarts(customerCart, sessionShoppingCart, store);
customerCart = shoppingCartService.getById(customerCart.getId(), store);
return customerCart;
// return populateShoppingCartData(customerCart,store,language);
} else {
return customerCart;
// return populateShoppingCartData(sessionShoppingCart,store,language);
}
} else {
// the saved cart belongs to another user
return null;
}
}
}
}
} else {
if (customerCart != null) {
// return populateShoppingCartData(customerCart,store,language);
return customerCart;
}
return null;
}
}
LOG.info("Seems some issue with system, unable to find any customer after successful authentication");
return null;
}
use of com.salesmanager.core.model.shoppingcart.ShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method getShoppingCartData.
@Override
public ShoppingCartData getShoppingCartData(final Customer customer, final MerchantStore store, final String shoppingCartId, Language language) throws Exception {
ShoppingCart cart = null;
try {
if (customer != null) {
LOG.info("Reteriving customer shopping cart...");
cart = shoppingCartService.getShoppingCart(customer);
} else {
if (StringUtils.isNotBlank(shoppingCartId) && cart == null) {
cart = shoppingCartService.getByCode(shoppingCartId, store);
}
}
} catch (ServiceException ex) {
LOG.error("Error while retriving cart from customer", ex);
} catch (NoResultException nre) {
// nothing
}
if (cart == null) {
return null;
}
// if cart has been completed return null
if (cart.getOrderId() != null && cart.getOrderId().longValue() > 0) {
if (StringUtils.isNotBlank(shoppingCartId) && !(shoppingCartId.equals(cart.getShoppingCartCode()))) {
cart = shoppingCartService.getByCode(shoppingCartId, store);
} else {
return null;
}
}
LOG.info("Cart model found.");
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);
ShoppingCartData shoppingCartData = shoppingCartDataPopulator.populate(cart, merchantStore, language);
return shoppingCartData;
}
use of com.salesmanager.core.model.shoppingcart.ShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartServiceImpl method getById.
/**
* Get a {@link ShoppingCart} for a given id. Will update the shopping cart
* prices and items based on the actual inventory. This method will remove
* the shopping cart if no items are attached.
*/
@Override
@Transactional
public ShoppingCart getById(final Long id) {
try {
ShoppingCart shoppingCart = shoppingCartRepository.findOne(id);
if (shoppingCart == null) {
return null;
}
getPopulatedShoppingCart(shoppingCart);
if (shoppingCart.isObsolete()) {
delete(shoppingCart);
return null;
} else {
return shoppingCart;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
Aggregations