use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCartController method reconfigure.
/**
* Takes an order item id and rebuilds the dependant order item tree with the current quantities and options set.
*
* If the method was invoked via an AJAX call, it will render the "ajax/configure" template.
* Otherwise, it will perform a 302 redirect to "/cart/configure"
*
* @param request
* @param response
* @param model
* @param orderItemId
* @throws IOException
* @throws AddToCartException
* @throws PricingException
*/
public String reconfigure(HttpServletRequest request, HttpServletResponse response, Model model, Long orderItemId) throws IOException, AddToCartException, PricingException, Exception {
DiscreteOrderItem orderItem = (DiscreteOrderItem) orderItemService.readOrderItemById(orderItemId);
Long productId = orderItem.getProduct().getId();
Product product = catalogService.findProductById(productId);
ConfigurableOrderItemRequest itemRequest = orderItemService.createConfigurableOrderItemRequestFromProduct(product);
orderItemService.modifyOrderItemRequest(itemRequest);
orderItemService.mergeOrderItemRequest(itemRequest, orderItem);
// update quantities and product options
itemRequest.setQuantity(orderItem.getQuantity());
model.addAttribute("baseItem", itemRequest);
model.addAttribute("isUpdateRequest", Boolean.TRUE);
model.addAttribute("originalOrderItem", orderItemId);
model.addAttribute(ALL_PRODUCTS_ATTRIBUTE_NAME, orderItemService.findAllProductsInRequest(itemRequest));
return isAjaxRequest(request) ? getConfigureView() : getConfigurePageRedirect();
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class ProductOptionDisplayProcessor method populateModelVariables.
@Override
public Map<String, Object> populateModelVariables(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
HashMap<String, String> productOptionDisplayValues = new HashMap<>();
Object item = context.parseExpression(tagAttributes.get("orderItem"));
if (item instanceof DiscreteOrderItem) {
DiscreteOrderItem orderItem = (DiscreteOrderItem) item;
for (String i : orderItem.getOrderItemAttributes().keySet()) {
for (ProductOption option : orderItem.getProduct().getProductOptions()) {
if (option.getAttributeName().equals(i) && !StringUtils.isEmpty(orderItem.getOrderItemAttributes().get(i).toString())) {
productOptionDisplayValues.put(option.getLabel(), orderItem.getOrderItemAttributes().get(i).toString());
}
}
}
}
return ImmutableMap.of("productOptionDisplayValues", (Object) productOptionDisplayValues);
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem 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);
}
}
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderItemServiceImpl method createDynamicPriceDiscreteOrderItem.
@Override
public DiscreteOrderItem createDynamicPriceDiscreteOrderItem(final DiscreteOrderItemRequest itemRequest, @SuppressWarnings("rawtypes") HashMap skuPricingConsiderations) {
final DiscreteOrderItem item = (DiscreteOrderItem) orderItemDao.create(OrderItemType.EXTERNALLY_PRICED);
populateDiscreteOrderItem(item, itemRequest);
SkuPriceWrapper wrapper = new SkuPriceWrapper(itemRequest.getSku());
DynamicSkuPrices prices = dynamicSkuPricingService.getSkuPrices(wrapper, skuPricingConsiderations);
item.setBundleOrderItem(itemRequest.getBundleOrderItem());
item.setBaseRetailPrice(prices.getRetailPrice());
item.setBaseSalePrice(prices.getSalePrice());
item.setSalePrice(prices.getSalePrice());
item.setRetailPrice(prices.getRetailPrice());
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.setDiscreteOrderItemFeePrices(itemRequest.getDiscreteOrderItemFeePrices());
for (DiscreteOrderItemFeePrice fee : itemRequest.getDiscreteOrderItemFeePrices()) {
item.setSalePrice(item.getSalePrice().add(fee.getAmount()));
item.setRetailPrice(item.getRetailPrice().add(fee.getAmount()));
}
item.setPersonalMessage(itemRequest.getPersonalMessage());
applyAdditionalOrderItemProperties(item);
return item;
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class CartMessageOrderItemServiceExtensionHandler method gatherProductCartMessages.
protected List<String> gatherProductCartMessages(OrderItem orderItem) {
List<String> cartMessages = new ArrayList<>();
if (DiscreteOrderItem.class.isAssignableFrom(orderItem.getClass())) {
DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) orderItem;
Product product = discreteOrderItem.getProduct();
for (PromotionMessageGenerator generator : generators) {
Map<String, List<PromotionMessageDTO>> promotionMessages = generator.generatePromotionMessages(product);
List<PromotionMessageDTO> messageDTOs = new ArrayList<>();
addPromotionMessagesForType(messageDTOs, promotionMessages.get(PromotionMessagePlacementType.CART.getType()));
addPromotionMessagesForType(messageDTOs, promotionMessages.get(PromotionMessagePlacementType.EVERYWHERE.getType()));
BLCPromotionMessageUtils.sortMessagesByPriority(messageDTOs);
cartMessages.addAll(BLCPromotionMessageUtils.gatherMessagesFromDTOs(messageDTOs));
}
}
return cartMessages;
}
Aggregations