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;
}
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();
}
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();
}
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);
}
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);
}
}
}
Aggregations