use of org.rembx.jeeshop.catalog.model.Discount in project jeeshop by remibantos.
the class DiscountsCT method create_shouldPersist.
@Test
public void create_shouldPersist() {
Discount discount = new Discount("discount777", "a discount", ORDER, DISCOUNT_RATE, AMOUNT, null, 0.1, 2.0, 1, true, null, null, false);
entityManager.getTransaction().begin();
service.create(discount);
entityManager.getTransaction().commit();
assertThat(entityManager.find(Discount.class, discount.getId())).isNotNull();
entityManager.remove(discount);
}
use of org.rembx.jeeshop.catalog.model.Discount in project jeeshop by remibantos.
the class DiscountsCT method delete_shouldRemove.
@Test
public void delete_shouldRemove() {
entityManager.getTransaction().begin();
Discount discount = new Discount("discount888", "a discount", ORDER, DISCOUNT_RATE, QUANTITY, null, 0.1, 2.0, 1, true, null, null, false);
entityManager.persist(discount);
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
service.delete(discount.getId());
entityManager.getTransaction().commit();
assertThat(entityManager.find(Discount.class, discount.getId())).isNull();
}
use of org.rembx.jeeshop.catalog.model.Discount in project jeeshop by remibantos.
the class DiscountFinder method findEligibleOrderDiscounts.
/*
* Returns all discounts eligible for end-user
* @param applicableTo the applicable type of discount
* @param locale the locale for results localization
* @return the visible discounts: not disabled, with startDate and endDate respectively before and after now and without
* voucher code, applicable to given number of orders
*/
public List<Discount> findEligibleOrderDiscounts(String locale, Long completedOrderNumbers) {
Date now = new Date();
List<Discount> results = new JPAQueryFactory(entityManager).selectFrom(discount).where(discount.disabled.isFalse(), discount.endDate.after(now).or(discount.endDate.isNull()), discount.startDate.before(now).or(discount.startDate.isNull()), discount.applicableTo.eq(ApplicableTo.ORDER), discount.triggerRule.ne(Discount.Trigger.ORDER_NUMBER).or(discount.triggerValue.eq(completedOrderNumbers.doubleValue() + 1)), discount.voucherCode.isNull()).fetch();
results.forEach((discount) -> discount.setLocalizedPresentation(locale));
return results;
}
use of org.rembx.jeeshop.catalog.model.Discount in project jeeshop by remibantos.
the class DiscountFinder method findVisibleDiscounts.
/*
* Returns all discounts visible to end user
* @param applicableTo the applicable type of discount
* @param locale the locale for results localization
* @return the visible discounts: not disabled, with startDate and endDate respectively before and after now and without
* voucher code
*/
public List<Discount> findVisibleDiscounts(ApplicableTo applicableTo, String locale) {
Date now = new Date();
List<Discount> results = new JPAQueryFactory(entityManager).selectFrom(discount).where(discount.disabled.isFalse(), discount.endDate.after(now).or(discount.endDate.isNull()), discount.startDate.before(now).or(discount.startDate.isNull()), discount.applicableTo.eq(applicableTo), discount.voucherCode.isNull()).fetch();
results.forEach((discount) -> discount.setLocalizedPresentation(locale));
return results;
}
use of org.rembx.jeeshop.catalog.model.Discount in project jeeshop by remibantos.
the class OrderFinder method enhanceOrder.
/**
* Enhance given order with Catalog items data and order static configuration.
*
* @param order the order to enhance
*/
public void enhanceOrder(Order order) {
User user = order.getUser();
order.getItems().forEach(orderItem -> {
Product product = catalogEntityManager.find(Product.class, orderItem.getProductId());
SKU sku = catalogEntityManager.find(SKU.class, orderItem.getSkuId());
product.setLocalizedPresentation(user.getPreferredLocale());
orderItem.setDisplayName(product.getLocalizedPresentation() != null ? product.getLocalizedPresentation().getDisplayName() : product.getName());
orderItem.setSkuReference(sku.getReference());
if (product.getLocalizedPresentation() != null && product.getLocalizedPresentation().getSmallImage() != null)
orderItem.setPresentationImageURI("products/" + orderItem.getProductId() + "/" + product.getLocalizedPresentation().getLocale() + "/" + product.getLocalizedPresentation().getSmallImage().getUri());
});
order.getOrderDiscounts().forEach(orderDiscount -> {
Discount discount = catalogEntityManager.find(Discount.class, orderDiscount.getDiscountId());
discount.setLocalizedPresentation(user.getPreferredLocale());
orderDiscount.setDisplayName(discount.getLocalizedPresentation().getDisplayName() != null ? discount.getLocalizedPresentation().getDisplayName() : discount.getName());
orderDiscount.setRateType(discount.getRateType());
if (discount.getLocalizedPresentation() != null && discount.getLocalizedPresentation().getSmallImage() != null)
orderDiscount.setPresentationImageURI("discounts/" + orderDiscount.getDiscountId() + "/" + discount.getLocalizedPresentation().getLocale() + "/" + discount.getLocalizedPresentation().getSmallImage().getUri());
});
order.setDeliveryFee(orderConfiguration.getFixedDeliveryFee());
order.setVat(orderConfiguration.getVAT());
}
Aggregations