use of org.rembx.jeeshop.catalog.model.Product 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());
}
use of org.rembx.jeeshop.catalog.model.Product in project jeeshop by remibantos.
the class ProductsCT method create_shouldPersist_for_admin.
@Test
public void create_shouldPersist_for_admin() {
tester.setAdminUser();
Product product = new Product("name", "description", new Date(), new Date(), false, TestCatalog.OWNER);
Product actualProduct = tester.test_create(product);
assertThat(actualProduct).isNotNull();
assertThat(actualProduct.getOwner()).isEqualTo(TestCatalog.OWNER);
}
use of org.rembx.jeeshop.catalog.model.Product in project jeeshop by remibantos.
the class ProductsCT method modifyProduct_ShouldModifyProductAttributesAndPreserveSKUsWhenNotProvided.
@Test
public void modifyProduct_ShouldModifyProductAttributesAndPreserveSKUsWhenNotProvided() {
tester.setAdminUser();
Product product = new Product(tester.getFixtures().aProductWithSKUs().getId(), "New name");
tester.test_modify(product);
assertThat(product.getName()).isEqualTo("New name");
assertThat(product.getChildSKUs()).containsOnlyElementsOf(product.getChildSKUs());
}
use of org.rembx.jeeshop.catalog.model.Product in project jeeshop by remibantos.
the class ProductsCT method create_shouldPersist_for_store_admin.
@Test
public void create_shouldPersist_for_store_admin() {
tester.setAdminUser();
Product product = new Product("name", "description", new Date(), new Date(), false, TestCatalog.OWNER);
Product actualProduct = tester.test_create(product);
assertThat(actualProduct).isNotNull();
assertThat(actualProduct.getOwner()).isEqualTo(TestCatalog.OWNER);
}
use of org.rembx.jeeshop.catalog.model.Product in project jeeshop by remibantos.
the class ProductsCT method modifyUnknownProduct_ShouldThrowNotFoundException.
@Test
public void modifyUnknownProduct_ShouldThrowNotFoundException() {
Product detachedProductToModify = new Product(9999L, null);
try {
tester.setAdminUser();
localService.modify(tester.getSecurityContext(), detachedProductToModify);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
}
}
Aggregations