Search in sources :

Example 51 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemServiceImpl method createGiftWrapOrderItem.

@Override
public GiftWrapOrderItem createGiftWrapOrderItem(final GiftWrapOrderItemRequest itemRequest) {
    final GiftWrapOrderItem item = (GiftWrapOrderItem) orderItemDao.create(OrderItemType.GIFTWRAP);
    item.setSku(itemRequest.getSku());
    item.setOrder(itemRequest.getOrder());
    item.setBundleOrderItem(itemRequest.getBundleOrderItem());
    item.setQuantity(itemRequest.getQuantity());
    item.setCategory(itemRequest.getCategory());
    item.setProduct(itemRequest.getProduct());
    item.setBaseSalePrice(itemRequest.getSku().getSalePrice());
    item.setBaseRetailPrice(itemRequest.getSku().getRetailPrice());
    item.setDiscreteOrderItemFeePrices(itemRequest.getDiscreteOrderItemFeePrices());
    if (itemRequest.getSalePriceOverride() != null) {
        item.setSalePriceOverride(Boolean.TRUE);
        item.setSalePrice(itemRequest.getSalePriceOverride());
        item.setBaseSalePrice(itemRequest.getSalePriceOverride());
    }
    if (itemRequest.getRetailPriceOverride() != null) {
        item.setRetailPriceOverride(Boolean.TRUE);
        item.setRetailPrice(itemRequest.getRetailPriceOverride());
        item.setBaseRetailPrice(itemRequest.getRetailPriceOverride());
    }
    // item.updatePrices();
    item.updateSaleAndRetailPrices();
    item.assignFinalPrice();
    item.getWrappedItems().addAll(itemRequest.getWrappedItems());
    for (OrderItem orderItem : item.getWrappedItems()) {
        orderItem.setGiftWrapOrderItem(item);
    }
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)

Example 52 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemServiceImpl method buildOrderItemFromDTO.

@Override
public OrderItem buildOrderItemFromDTO(Order order, OrderItemRequestDTO orderItemRequestDTO) {
    Sku sku = null;
    if (orderItemRequestDTO.getSkuId() != null) {
        sku = catalogService.findSkuById(orderItemRequestDTO.getSkuId());
    }
    Product product = null;
    if (orderItemRequestDTO.getProductId() != null) {
        product = catalogService.findProductById(orderItemRequestDTO.getProductId());
    }
    Category category = null;
    if (orderItemRequestDTO.getCategoryId() != null) {
        category = catalogService.findCategoryById(orderItemRequestDTO.getCategoryId());
    }
    if (category == null && product != null) {
        category = product.getDefaultCategory();
    }
    OrderItem item;
    if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
        NonDiscreteOrderItemRequestDTO ndr = (NonDiscreteOrderItemRequestDTO) orderItemRequestDTO;
        OrderItemRequest itemRequest = new OrderItemRequest();
        itemRequest.setQuantity(ndr.getQuantity());
        itemRequest.setRetailPriceOverride(ndr.getOverrideRetailPrice());
        itemRequest.setSalePriceOverride(ndr.getOverrideSalePrice());
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
        itemRequest.setItemName(ndr.getItemName());
        itemRequest.setOrder(order);
        item = createOrderItem(itemRequest);
    } else if (product == null || !(product instanceof ProductBundle)) {
        DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
        itemRequest.setCategory(category);
        itemRequest.setProduct(product);
        itemRequest.setSku(sku);
        itemRequest.setQuantity(orderItemRequestDTO.getQuantity());
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
        itemRequest.setOrder(order);
        itemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
        itemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
        item = createDiscreteOrderItem(itemRequest);
    } else {
        ProductBundleOrderItemRequest bundleItemRequest = new ProductBundleOrderItemRequest();
        bundleItemRequest.setCategory(category);
        bundleItemRequest.setProductBundle((ProductBundle) product);
        bundleItemRequest.setSku(sku);
        bundleItemRequest.setQuantity(orderItemRequestDTO.getQuantity());
        bundleItemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        bundleItemRequest.setName(product.getName());
        bundleItemRequest.setOrder(order);
        bundleItemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
        bundleItemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
        item = createBundleOrderItem(bundleItemRequest, false);
    }
    if (orderItemRequestDTO.getParentOrderItemId() != null) {
        OrderItem parent = readOrderItemById(orderItemRequestDTO.getParentOrderItemId());
        item.setParentOrderItem(parent);
    }
    if (orderItemRequestDTO.getHasConfigurationError()) {
        item.setHasValidationError(true);
    }
    if (orderItemRequestDTO instanceof ConfigurableOrderItemRequest) {
        ConfigurableOrderItemRequest configRequest = (ConfigurableOrderItemRequest) orderItemRequestDTO;
        if (configRequest.getHasConfigurationError()) {
            item.setHasValidationError(true);
        }
        if (!configRequest.getDiscountsAllowed()) {
            item.setDiscountingAllowed(false);
        }
    }
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) AbstractOrderItemRequest(org.broadleafcommerce.core.order.service.call.AbstractOrderItemRequest) GiftWrapOrderItemRequest(org.broadleafcommerce.core.order.service.call.GiftWrapOrderItemRequest) OrderItemRequest(org.broadleafcommerce.core.order.service.call.OrderItemRequest) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) BundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.BundleOrderItemRequest) Category(org.broadleafcommerce.core.catalog.domain.Category) DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Example 53 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemDaoImpl method readOrderItemsForCustomersInDateRange.

@Override
public List<OrderItem> readOrderItemsForCustomersInDateRange(List<Long> customerIds, Date startDate, Date endDate) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<OrderItem> criteria = builder.createQuery(OrderItem.class);
    Root<OrderImpl> order = criteria.from(OrderImpl.class);
    Join<Order, OrderItem> orderItems = order.join("orderItems");
    criteria.select(orderItems);
    List<Predicate> restrictions = new ArrayList<>();
    restrictions.add(builder.between(order.<Date>get("submitDate"), startDate, endDate));
    restrictions.add(order.get("customer").get("id").in(customerIds));
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    criteria.orderBy(builder.desc(order.get("customer")), builder.asc(order.get("submitDate")));
    TypedQuery<OrderItem> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(org.broadleafcommerce.core.order.domain.Order) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) ArrayList(java.util.ArrayList) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate)

Example 54 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemDaoImpl method create.

@Override
public OrderItem create(final OrderItemType orderItemType) {
    final OrderItem item = (OrderItem) entityConfiguration.createEntityInstance(orderItemType.getType());
    item.setOrderItemType(orderItemType);
    return item;
}
Also used : OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)

Example 55 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemDaoImpl method readBatchOrderItems.

@Override
public List<OrderItem> readBatchOrderItems(int start, int count, List<OrderStatus> statuses) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<OrderItem> criteria = builder.createQuery(OrderItem.class);
    Root<OrderImpl> order = criteria.from(OrderImpl.class);
    Join<Order, OrderItem> orderItems = order.join("orderItems");
    criteria.select(orderItems);
    List<Predicate> restrictions = new ArrayList<>();
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    if (CollectionUtils.isNotEmpty(statuses)) {
        // We only want results that match the orders with the correct status
        ArrayList<String> statusStrings = new ArrayList<String>();
        for (OrderStatus status : statuses) {
            statusStrings.add(status.getType());
        }
        criteria.where(order.get("status").as(String.class).in(statusStrings));
    }
    TypedQuery<OrderItem> query = em.createQuery(criteria);
    query.setFirstResult(start);
    query.setMaxResults(count);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(org.broadleafcommerce.core.order.domain.Order) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) OrderStatus(org.broadleafcommerce.core.order.service.type.OrderStatus) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl)

Aggregations

OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)100 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)69 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)54 Order (org.broadleafcommerce.core.order.domain.Order)46 ArrayList (java.util.ArrayList)32 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)23 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)20 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)19 Transactional (org.springframework.transaction.annotation.Transactional)19 Test (org.testng.annotations.Test)16 Money (org.broadleafcommerce.common.money.Money)13 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)13 HashMap (java.util.HashMap)11 Sku (org.broadleafcommerce.core.catalog.domain.Sku)10 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)9 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)7 BigDecimal (java.math.BigDecimal)5 ItemNotFoundException (org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)5 List (java.util.List)4 Product (org.broadleafcommerce.core.catalog.domain.Product)4