Search in sources :

Example 46 with OrderItem

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

the class OfferServiceUtilitiesImpl method markTargetsForCriteria.

@Override
public int markTargetsForCriteria(PromotableCandidateItemOffer itemOffer, OrderItem relatedQualifier, boolean checkOnly, Offer promotion, OrderItem relatedQualifierRoot, OfferItemCriteria itemCriteria, List<PromotableOrderItemPriceDetail> priceDetails, int targetQtyNeeded) {
    for (PromotableOrderItemPriceDetail priceDetail : priceDetails) {
        if (relatedQualifier != null) {
            // We need to make sure that this item is either a parent, child, or the same as the qualifier root
            OrderItem thisItem = priceDetail.getPromotableOrderItem().getOrderItem();
            if (!relatedQualifierRoot.isAParentOf(thisItem) && !thisItem.isAParentOf(relatedQualifierRoot) && !thisItem.equals(relatedQualifierRoot)) {
                continue;
            }
        }
        int itemQtyAvailableToBeUsedAsTarget = priceDetail.getQuantityAvailableToBeUsedAsTarget(itemOffer);
        if (itemQtyAvailableToBeUsedAsTarget > 0) {
            if (promotion.isUnlimitedUsePerOrder() || (itemOffer.getUses() < promotion.getMaxUsesPerOrder())) {
                int qtyToMarkAsTarget = Math.min(targetQtyNeeded, itemQtyAvailableToBeUsedAsTarget);
                targetQtyNeeded -= qtyToMarkAsTarget;
                if (!checkOnly) {
                    priceDetail.addPromotionDiscount(itemOffer, itemCriteria, qtyToMarkAsTarget);
                }
            }
        }
        if (targetQtyNeeded == 0) {
            break;
        }
    }
    return targetQtyNeeded;
}
Also used : PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 47 with OrderItem

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

the class BroadleafManageWishlistController method moveItemToCart.

public String moveItemToCart(HttpServletRequest request, HttpServletResponse response, Model model, String wishlistName, Long orderItemId) throws RemoveFromCartException, AddToCartException, PricingException {
    Order wishlist = orderService.findNamedOrderForCustomer(wishlistName, CustomerState.getCustomer());
    List<OrderItem> orderItems = wishlist.getOrderItems();
    OrderItem orderItem = null;
    for (OrderItem item : orderItems) {
        if (orderItemId.equals(item.getId())) {
            orderItem = item;
            break;
        }
    }
    if (orderItem != null) {
        Order cartOrder = orderService.addItemFromNamedOrder(wishlist, orderItem, false);
        cartOrder = orderService.save(cartOrder, true);
    } else {
        throw new IllegalArgumentException("The item id provided was not found in the wishlist");
    }
    model.addAttribute("wishlist", wishlist);
    return getAccountWishlistRedirect();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem)

Example 48 with OrderItem

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

the class GoogleUniversalAnalyticsProcessor method getItemJs.

protected String getItemJs(Order order, String trackerPrefix) {
    StringBuffer sb = new StringBuffer();
    for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
        for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
            OrderItem orderItem = fulfillmentGroupItem.getOrderItem();
            Sku sku = ((SkuAccessor) orderItem).getSku();
            sb.append("ga('" + trackerPrefix + "ecommerce:addItem', {");
            sb.append("'id': '" + order.getOrderNumber() + "'");
            sb.append(",'name': '" + sku.getName() + "'");
            sb.append(",'sku': '" + sku.getId() + "'");
            sb.append(",'category': '" + getVariation(orderItem) + "'");
            sb.append(",'price': '" + orderItem.getAveragePrice() + "'");
            sb.append(",'quantity': '" + orderItem.getQuantity() + "'");
            sb.append("});");
        }
    }
    return sb.toString();
}
Also used : FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) Sku(org.broadleafcommerce.core.catalog.domain.Sku) SkuAccessor(org.broadleafcommerce.core.order.domain.SkuAccessor)

Example 49 with OrderItem

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

the class UncacheableDataProcessor method addCartData.

protected void addCartData(Map<String, Object> attrMap) {
    Order cart = CartState.getCart();
    int cartQty = 0;
    List<Long> cartItemIdsWithOptions = new ArrayList<>();
    List<Long> cartItemIdsWithoutOptions = new ArrayList<>();
    if (cart != null && cart.getOrderItems() != null) {
        cartQty = cart.getItemCount();
        for (OrderItem item : cart.getOrderItems()) {
            if (item instanceof SkuAccessor) {
                Sku sku = ((SkuAccessor) item).getSku();
                if (sku != null && sku.getProduct() != null && item.getParentOrderItem() == null) {
                    if (useSku) {
                        cartItemIdsWithoutOptions.add(sku.getId());
                    } else {
                        Product product = sku.getProduct();
                        List<ProductOptionXref> optionXrefs = product.getProductOptionXrefs();
                        if (optionXrefs == null || optionXrefs.isEmpty()) {
                            cartItemIdsWithoutOptions.add(product.getId());
                        } else {
                            cartItemIdsWithOptions.add(product.getId());
                        }
                    }
                }
            }
        }
    }
    attrMap.put("cartItemCount", cartQty);
    attrMap.put("cartItemIdsWithOptions", cartItemIdsWithOptions);
    attrMap.put("cartItemIdsWithoutOptions", cartItemIdsWithoutOptions);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) ProductOptionXref(org.broadleafcommerce.core.catalog.domain.ProductOptionXref) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) SkuAccessor(org.broadleafcommerce.core.order.domain.SkuAccessor)

Example 50 with OrderItem

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

the class i18nUpdateCartServiceExtensionHandler method fixTranslations.

protected void fixTranslations(Order cart) {
    for (DiscreteOrderItem orderItem : cart.getDiscreteOrderItems()) {
        Sku sku = orderItem.getSku();
        translateOrderItem(orderItem, sku);
    }
    for (OrderItem orderItem : cart.getOrderItems()) {
        if (orderItem instanceof BundleOrderItem) {
            BundleOrderItem bundleItem = (BundleOrderItem) orderItem;
            Sku sku = bundleItem.getSku();
            translateOrderItem(orderItem, sku);
        }
    }
}
Also used : 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) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

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