Search in sources :

Example 81 with OrderItem

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

the class BroadleafCartController method updateAddRequestQuantities.

protected void updateAddRequestQuantities(OrderItemRequestDTO itemRequest, Long originalOrderItemId) {
    // Update the request to match the quantity of the order item it's replacing
    OrderItem orderItem = orderItemService.readOrderItemById(originalOrderItemId);
    // Make sure there is actually an order item to process
    if (orderItem == null) {
        return;
    }
    itemRequest.setQuantity(orderItem.getQuantity());
    for (OrderItemRequestDTO childDTO : itemRequest.getChildOrderItems()) {
        childDTO.setQuantity(childDTO.getQuantity() * orderItem.getQuantity());
    }
}
Also used : OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem)

Example 82 with OrderItem

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

the class BroadleafProductController method handleRequest.

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView model = new ModelAndView();
    Product product = (Product) request.getAttribute(ProductHandlerMapping.CURRENT_PRODUCT_ATTRIBUTE_NAME);
    assert (product != null);
    model.addObject(MODEL_ATTRIBUTE_NAME, product);
    model.addObject(PAGE_TYPE_ATTRIBUTE_NAME, "product");
    // Build the add to cart request and add it to the page
    ConfigurableOrderItemRequest itemRequest = orderItemService.createConfigurableOrderItemRequestFromProduct(product);
    orderItemService.modifyOrderItemRequest(itemRequest);
    model.addObject(CONFIGURATION_ATTRIBUTE_NAME, itemRequest);
    model.addObject(ALL_PRODUCTS_ATTRIBUTE_NAME, orderItemService.findAllProductsInRequest(itemRequest));
    addDeepLink(model, deepLinkService, product);
    String templatePath;
    // Use the products custom template if available
    if (StringUtils.isNotBlank(product.getDisplayTemplate())) {
        templatePath = product.getDisplayTemplate();
    } else {
        // Otherwise, use the controller default.
        templatePath = getDefaultProductView();
    }
    // Allow extension managers to override.
    ExtensionResultHolder<String> erh = new ExtensionResultHolder<String>();
    ExtensionResultStatusType extResult = templateOverrideManager.getProxy().getOverrideTemplate(erh, product);
    if (extResult != ExtensionResultStatusType.NOT_HANDLED) {
        templatePath = erh.getResult();
    }
    model.setViewName(templatePath);
    // Check if this is request to edit an existing order item
    String isEditRequest = request.getParameter("edit");
    String oidParam = request.getParameter("oid");
    if (StringUtils.isNotEmpty(isEditRequest) && StringUtils.isNotEmpty(oidParam)) {
        Long oid = Long.parseLong(oidParam);
        OrderItem orderItem = orderItemService.readOrderItemById(oid);
        if (orderItemBelongsToCurrentCustomer(orderItem)) {
            // Update the itemRequest to contain user's previous input
            orderItemService.mergeOrderItemRequest(itemRequest, orderItem);
            // Add the order item to the model
            model.addObject("isUpdateRequest", true);
            model.addObject("orderItem", orderItem);
        }
    }
    return model;
}
Also used : OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) ModelAndView(org.springframework.web.servlet.ModelAndView) Product(org.broadleafcommerce.core.catalog.domain.Product) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 83 with OrderItem

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

the class FulfillmentGroupServiceImpl method addItemToFulfillmentGroup.

@Override
public // @Transactional("blTransactionManager")
FulfillmentGroup addItemToFulfillmentGroup(FulfillmentGroupItemRequest fulfillmentGroupItemRequest, boolean priceOrder, boolean save) throws PricingException {
    if (priceOrder && !save) {
        throw new IllegalArgumentException("Pricing requires a save");
    }
    Order order = fulfillmentGroupItemRequest.getOrder();
    OrderItem item = fulfillmentGroupItemRequest.getOrderItem();
    FulfillmentGroup fulfillmentGroup = fulfillmentGroupItemRequest.getFulfillmentGroup();
    if (order == null) {
        if (item.getOrder() != null) {
            order = item.getOrder();
        } else {
            throw new IllegalArgumentException("Order must not be null");
        }
    }
    // 1) Find the order item's existing fulfillment group, if any
    for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
        Iterator<FulfillmentGroupItem> itr = fg.getFulfillmentGroupItems().iterator();
        while (itr.hasNext()) {
            FulfillmentGroupItem fgItem = itr.next();
            if (fgItem.getOrderItem().equals(item)) {
                // 2) remove item from it's existing fulfillment group
                itr.remove();
                fulfillmentGroupItemDao.delete(fgItem);
            }
        }
    }
    if (fulfillmentGroup == null) {
        // API user is trying to add an item to a fulfillment group not created
        fulfillmentGroup = fulfillmentGroupDao.create();
        FulfillmentGroupRequest fgRequest = new FulfillmentGroupRequest();
        fgRequest.setOrder(order);
        fulfillmentGroup = addFulfillmentGroupToOrder(fgRequest, false);
        fulfillmentGroup = save(fulfillmentGroup);
        order.getFulfillmentGroups().add(fulfillmentGroup);
    }
    FulfillmentGroupItem fgi = createFulfillmentGroupItemFromOrderItem(item, fulfillmentGroup, fulfillmentGroupItemRequest.getQuantity());
    if (save) {
        fgi = fulfillmentGroupItemDao.save(fgi);
    }
    // 3) add the item to the new fulfillment group
    fulfillmentGroup.addFulfillmentGroupItem(fgi);
    if (save) {
        order = orderService.save(order, priceOrder);
    }
    return fulfillmentGroup;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroupRequest(org.broadleafcommerce.core.order.service.call.FulfillmentGroupRequest) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 84 with OrderItem

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

the class MergeCartServiceImpl method reconstructCart.

@Override
public ReconstructCartResponse reconstructCart(Customer customer, boolean priceOrder) throws PricingException, RemoveFromCartException {
    ReconstructCartResponse reconstructCartResponse = new ReconstructCartResponse();
    Order customerCart = orderService.findCartForCustomerWithEnhancements(customer);
    if (customerCart != null) {
        List<OrderItem> itemsToRemove = new ArrayList<OrderItem>();
        for (OrderItem orderItem : customerCart.getOrderItems()) {
            if (orderItem instanceof DiscreteOrderItem) {
                DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
                if (!checkActive(doi) || !checkInventory(doi) || !checkOtherValidity(orderItem)) {
                    itemsToRemove.add(orderItem);
                }
            } else if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
                for (DiscreteOrderItem doi : bundleOrderItem.getDiscreteOrderItems()) {
                    if (!checkActive(doi) || !checkInventory(doi) || !checkOtherValidity(orderItem)) {
                        itemsToRemove.add(doi.getBundleOrderItem());
                    }
                }
            }
        }
        // Remove any giftwrap items who have one or more wrapped item members that have been removed
        for (OrderItem orderItem : customerCart.getOrderItems()) {
            if (orderItem instanceof GiftWrapOrderItem) {
                for (OrderItem wrappedItem : ((GiftWrapOrderItem) orderItem).getWrappedItems()) {
                    if (itemsToRemove.contains(wrappedItem)) {
                        itemsToRemove.add(orderItem);
                        break;
                    }
                }
            }
        }
        for (OrderItem item : itemsToRemove) {
            orderService.removeItem(customerCart.getId(), item.getId(), false);
        }
        reconstructCartResponse.setRemovedItems(itemsToRemove);
        customerCart = orderService.save(customerCart, priceOrder);
    }
    reconstructCartResponse.setOrder(customerCart);
    return reconstructCartResponse;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) 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) ArrayList(java.util.ArrayList) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) ReconstructCartResponse(org.broadleafcommerce.core.order.service.call.ReconstructCartResponse)

Example 85 with OrderItem

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

the class OrderItemServiceImpl method createOrderItem.

@Override
public OrderItem createOrderItem(final OrderItemRequest itemRequest) {
    final OrderItem item = orderItemDao.create(OrderItemType.BASIC);
    item.setName(itemRequest.getItemName());
    item.setQuantity(itemRequest.getQuantity());
    item.setOrder(itemRequest.getOrder());
    if (itemRequest.getSalePriceOverride() != null) {
        item.setSalePriceOverride(Boolean.TRUE);
        item.setSalePrice(itemRequest.getSalePriceOverride());
    }
    if (itemRequest.getRetailPriceOverride() != null) {
        item.setRetailPriceOverride(Boolean.TRUE);
        item.setRetailPrice(itemRequest.getRetailPriceOverride());
    }
    if (MapUtils.isNotEmpty(itemRequest.getItemAttributes())) {
        Map<String, OrderItemAttribute> attributeMap = item.getOrderItemAttributes();
        if (attributeMap == null) {
            attributeMap = new HashMap<String, OrderItemAttribute>();
            item.setOrderItemAttributes(attributeMap);
        }
        for (Entry<String, String> entry : itemRequest.getItemAttributes().entrySet()) {
            OrderItemAttribute orderItemAttribute = new OrderItemAttributeImpl();
            orderItemAttribute.setName(entry.getKey());
            orderItemAttribute.setValue(entry.getValue());
            orderItemAttribute.setOrderItem(item);
            attributeMap.put(entry.getKey(), orderItemAttribute);
        }
    }
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) 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) OrderItemAttributeImpl(org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl)

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