Search in sources :

Example 1 with Product

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());
}
Also used : User(org.rembx.jeeshop.user.model.User) Discount(org.rembx.jeeshop.catalog.model.Discount) Product(org.rembx.jeeshop.catalog.model.Product) SKU(org.rembx.jeeshop.catalog.model.SKU)

Example 2 with Product

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);
}
Also used : Product(org.rembx.jeeshop.catalog.model.Product) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with Product

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());
}
Also used : Product(org.rembx.jeeshop.catalog.model.Product) Test(org.junit.jupiter.api.Test)

Example 4 with Product

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);
}
Also used : Product(org.rembx.jeeshop.catalog.model.Product) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with Product

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);
    }
}
Also used : WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Product(org.rembx.jeeshop.catalog.model.Product) Test(org.junit.jupiter.api.Test)

Aggregations

Product (org.rembx.jeeshop.catalog.model.Product)9 Test (org.junit.jupiter.api.Test)7 Date (java.util.Date)3 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)3 Test (org.junit.Test)1 Discount (org.rembx.jeeshop.catalog.model.Discount)1 SKU (org.rembx.jeeshop.catalog.model.SKU)1 User (org.rembx.jeeshop.user.model.User)1