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