use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method getByCode.
@Override
public ReadableShoppingCart getByCode(String code, MerchantStore store, Language language) throws Exception {
ShoppingCart cart = shoppingCartService.getByCode(code, store);
ReadableShoppingCart readableCart = null;
if (cart != null) {
readableCart = readableShoppingCartMapper.convert(cart, store, language);
if (!StringUtils.isBlank(cart.getPromoCode())) {
// promo valid 1 day
Date promoDateAdded = cart.getPromoAdded();
if (promoDateAdded == null) {
promoDateAdded = new Date();
}
Instant instant = promoDateAdded.toInstant();
ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
LocalDate date = zdt.toLocalDate();
// date added < date + 1 day
LocalDate tomorrow = LocalDate.now().plusDays(1);
if (date.isBefore(tomorrow)) {
readableCart.setPromoCode(cart.getPromoCode());
}
}
}
return readableCart;
}
use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method getById.
@Override
public ReadableShoppingCart getById(Long shoppingCartId, MerchantStore store, Language language) throws Exception {
ShoppingCart cart = shoppingCartService.getById(shoppingCartId);
ReadableShoppingCart readableCart = null;
if (cart != null) {
readableCart = readableShoppingCartMapper.convert(cart, store, language);
}
return readableCart;
}
use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method removeShoppingCartItem.
@Override
@Nullable
public ReadableShoppingCart removeShoppingCartItem(String cartCode, Long productId, MerchantStore merchant, Language language, boolean returnCart) throws Exception {
Validate.notNull(cartCode, "Shopping cart code must not be null");
Validate.notNull(productId, "product id must not be null");
Validate.notNull(merchant, "MerchantStore must not be null");
// get cart
ShoppingCart cart = getCartModel(cartCode, merchant);
if (cart == null) {
throw new ResourceNotFoundException("Cart code [ " + cartCode + " ] not found");
}
Set<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> items = new HashSet<com.salesmanager.core.model.shoppingcart.ShoppingCartItem>();
com.salesmanager.core.model.shoppingcart.ShoppingCartItem itemToDelete = null;
for (com.salesmanager.core.model.shoppingcart.ShoppingCartItem shoppingCartItem : cart.getLineItems()) {
if (shoppingCartItem.getProduct().getId().longValue() == productId.longValue()) {
// get cart item
itemToDelete = getEntryToUpdate(shoppingCartItem.getId(), cart);
// break;
} else {
items.add(shoppingCartItem);
}
}
// delete item
if (itemToDelete != null) {
shoppingCartService.deleteShoppingCartItem(itemToDelete.getId());
}
// remaining items
if (items.size() > 0) {
cart.setLineItems(items);
} else {
cart.getLineItems().clear();
}
// update cart with remaining items
shoppingCartService.saveOrUpdate(cart);
if (items.size() > 0 & returnCart) {
return this.getByCode(cartCode, merchant, language);
}
return null;
}
use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method modifyCart.
@Override
public ReadableShoppingCart modifyCart(String cartCode, String promo, MerchantStore store, Language language) throws Exception {
ShoppingCart cart = shoppingCartService.getByCode(cartCode, store);
cart.setPromoCode(promo);
cart.setPromoAdded(new Date());
shoppingCartService.save(cart);
return readableShoppingCartMapper.convert(cart, store, language);
}
use of com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method addToCart.
@Override
public ReadableShoppingCart addToCart(PersistableShoppingCartItem item, MerchantStore store, Language language) {
Validate.notNull(item, "PersistableShoppingCartItem cannot be null");
// if cart does not exist create a new one
ShoppingCart cartModel = new ShoppingCart();
cartModel.setMerchantStore(store);
cartModel.setShoppingCartCode(uniqueShoppingCartCode());
if (!StringUtils.isBlank(item.getPromoCode())) {
cartModel.setPromoCode(item.getPromoCode());
cartModel.setPromoAdded(new Date());
}
try {
return readableShoppingCart(cartModel, item, store, language);
} catch (Exception e) {
if (e instanceof ResourceNotFoundException) {
throw (ResourceNotFoundException) e;
} else {
throw new ServiceRuntimeException(e);
}
}
}
Aggregations