Search in sources :

Example 1 with PromotionMessageGenerator

use of org.broadleafcommerce.core.promotionMessage.service.PromotionMessageGenerator 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;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) PromotionMessageGenerator(org.broadleafcommerce.core.promotionMessage.service.PromotionMessageGenerator) PromotionMessageDTO(org.broadleafcommerce.core.promotionMessage.dto.PromotionMessageDTO) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with PromotionMessageGenerator

use of org.broadleafcommerce.core.promotionMessage.service.PromotionMessageGenerator in project BroadleafCommerce by BroadleafCommerce.

the class PromotionMessageVariableExpression method getProductPromotionMessages.

public List<PromotionMessageDTO> getProductPromotionMessages(Product product, String... placements) {
    List<String> filteredPlacements = filterInvalidPlacements(placements);
    if (!filteredPlacements.contains(PromotionMessagePlacementType.EVERYWHERE.getType())) {
        filteredPlacements.add(PromotionMessagePlacementType.EVERYWHERE.getType());
    }
    Map<String, List<PromotionMessageDTO>> promotionMessages = new MultiValueMap();
    for (PromotionMessageGenerator generator : generators) {
        promotionMessages.putAll(generator.generatePromotionMessages(product));
    }
    List<PromotionMessageDTO> filteredMessages = BLCPromotionMessageUtils.filterPromotionMessageDTOsByTypes(promotionMessages, filteredPlacements);
    BLCPromotionMessageUtils.sortMessagesByPriority(filteredMessages);
    return filteredMessages;
}
Also used : PromotionMessageGenerator(org.broadleafcommerce.core.promotionMessage.service.PromotionMessageGenerator) PromotionMessageDTO(org.broadleafcommerce.core.promotionMessage.dto.PromotionMessageDTO) ArrayList(java.util.ArrayList) List(java.util.List) MultiValueMap(org.apache.commons.collections.map.MultiValueMap)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 PromotionMessageDTO (org.broadleafcommerce.core.promotionMessage.dto.PromotionMessageDTO)2 PromotionMessageGenerator (org.broadleafcommerce.core.promotionMessage.service.PromotionMessageGenerator)2 MultiValueMap (org.apache.commons.collections.map.MultiValueMap)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)1