Search in sources :

Example 36 with Product

use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemServiceImpl method findAllChildProductsInRequest.

protected Set<Product> findAllChildProductsInRequest(List<OrderItemRequestDTO> childItems) {
    Set<Product> allProductsSet = new HashSet<Product>();
    for (OrderItemRequestDTO child : childItems) {
        ConfigurableOrderItemRequest configChild = (ConfigurableOrderItemRequest) child;
        Product childProduct = configChild.getProduct();
        if (childProduct != null) {
            allProductsSet.add(childProduct);
        } else {
            List<OrderItemRequestDTO> productChoices = new ArrayList<OrderItemRequestDTO>(configChild.getProductChoices());
            allProductsSet.addAll(findAllChildProductsInRequest(productChoices));
        }
    }
    return allProductsSet;
}
Also used : OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) HashSet(java.util.HashSet)

Example 37 with Product

use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemServiceImpl method buildOrderItemFromDTO.

@Override
public OrderItem buildOrderItemFromDTO(Order order, OrderItemRequestDTO orderItemRequestDTO) {
    Sku sku = null;
    if (orderItemRequestDTO.getSkuId() != null) {
        sku = catalogService.findSkuById(orderItemRequestDTO.getSkuId());
    }
    Product product = null;
    if (orderItemRequestDTO.getProductId() != null) {
        product = catalogService.findProductById(orderItemRequestDTO.getProductId());
    }
    Category category = null;
    if (orderItemRequestDTO.getCategoryId() != null) {
        category = catalogService.findCategoryById(orderItemRequestDTO.getCategoryId());
    }
    if (category == null && product != null) {
        category = product.getDefaultCategory();
    }
    OrderItem item;
    if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
        NonDiscreteOrderItemRequestDTO ndr = (NonDiscreteOrderItemRequestDTO) orderItemRequestDTO;
        OrderItemRequest itemRequest = new OrderItemRequest();
        itemRequest.setQuantity(ndr.getQuantity());
        itemRequest.setRetailPriceOverride(ndr.getOverrideRetailPrice());
        itemRequest.setSalePriceOverride(ndr.getOverrideSalePrice());
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
        itemRequest.setItemName(ndr.getItemName());
        itemRequest.setOrder(order);
        item = createOrderItem(itemRequest);
    } else if (product == null || !(product instanceof ProductBundle)) {
        DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
        itemRequest.setCategory(category);
        itemRequest.setProduct(product);
        itemRequest.setSku(sku);
        itemRequest.setQuantity(orderItemRequestDTO.getQuantity());
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
        itemRequest.setOrder(order);
        itemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
        itemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
        item = createDiscreteOrderItem(itemRequest);
    } else {
        ProductBundleOrderItemRequest bundleItemRequest = new ProductBundleOrderItemRequest();
        bundleItemRequest.setCategory(category);
        bundleItemRequest.setProductBundle((ProductBundle) product);
        bundleItemRequest.setSku(sku);
        bundleItemRequest.setQuantity(orderItemRequestDTO.getQuantity());
        bundleItemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        bundleItemRequest.setName(product.getName());
        bundleItemRequest.setOrder(order);
        bundleItemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
        bundleItemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
        item = createBundleOrderItem(bundleItemRequest, false);
    }
    if (orderItemRequestDTO.getParentOrderItemId() != null) {
        OrderItem parent = readOrderItemById(orderItemRequestDTO.getParentOrderItemId());
        item.setParentOrderItem(parent);
    }
    if (orderItemRequestDTO.getHasConfigurationError()) {
        item.setHasValidationError(true);
    }
    if (orderItemRequestDTO instanceof ConfigurableOrderItemRequest) {
        ConfigurableOrderItemRequest configRequest = (ConfigurableOrderItemRequest) orderItemRequestDTO;
        if (configRequest.getHasConfigurationError()) {
            item.setHasValidationError(true);
        }
        if (!configRequest.getDiscountsAllowed()) {
            item.setDiscountingAllowed(false);
        }
    }
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) AbstractOrderItemRequest(org.broadleafcommerce.core.order.service.call.AbstractOrderItemRequest) GiftWrapOrderItemRequest(org.broadleafcommerce.core.order.service.call.GiftWrapOrderItemRequest) OrderItemRequest(org.broadleafcommerce.core.order.service.call.OrderItemRequest) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) BundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.BundleOrderItemRequest) Category(org.broadleafcommerce.core.catalog.domain.Category) DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Example 38 with Product

use of org.broadleafcommerce.core.catalog.domain.Product 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 39 with Product

use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.

the class SolrSearchServiceImpl method findSearchResults.

/**
 * Given a qualified solr query string (such as "category:2002"), actually performs a solr search. It will
 * take into considering the search criteria to build out facets / pagination / sorting.
 *
 * @param searchCriteria
 * @param facets
 * @return the ProductSearchResult of the search
 * @throws ServiceException
 */
protected SearchResult findSearchResults(String qualifiedSolrQuery, List<SearchFacetDTO> facets, SearchCriteria searchCriteria, String defaultSort, String... filterQueries) throws ServiceException {
    Map<String, SearchFacetDTO> namedFacetMap = getNamedFacetMap(facets, searchCriteria);
    // Left here for backwards compatibility for this method signature
    if (searchCriteria.getQuery() == null && qualifiedSolrQuery != null) {
        searchCriteria.setQuery(qualifiedSolrQuery);
    }
    // Build the basic query
    // Solr queries with a 'start' parameter cannot be a negative number
    int start = (searchCriteria.getPage() <= 0) ? 0 : (searchCriteria.getPage() - 1);
    SolrQuery solrQuery = new SolrQuery().setQuery(searchCriteria.getQuery()).setRows(searchCriteria.getPageSize()).setStart((start) * searchCriteria.getPageSize()).setRequestHandler(searchCriteria.getRequestHandler());
    // This is for SolrCloud.  We assume that we are always searching against a collection aliased as "PRIMARY"
    if (solrConfiguration.isSiteCollections()) {
        solrQuery.setParam("collection", solrConfiguration.getSiteAliasName(BroadleafRequestContext.getBroadleafRequestContext().getNonPersistentSite()));
    } else {
        // This should be ignored if not using SolrCloud
        solrQuery.setParam("collection", solrConfiguration.getPrimaryName());
    }
    solrQuery.setFields(shs.getIndexableIdFieldName());
    if (filterQueries != null) {
        solrQuery.setFilterQueries(filterQueries);
    }
    // add category filter if applicable
    if (searchCriteria.getCategory() != null) {
        solrQuery.addFilterQuery(getCategoryFilter(searchCriteria));
    }
    solrQuery.addFilterQuery(shs.getNamespaceFieldName() + ":(\"" + solrConfiguration.getNamespace() + "\")");
    solrQuery.set("defType", "edismax");
    solrQuery.set("qf", buildQueryFieldsString(solrQuery, searchCriteria));
    // Attach additional restrictions
    attachActiveFacetFilters(solrQuery, namedFacetMap, searchCriteria);
    attachFacets(solrQuery, namedFacetMap, searchCriteria);
    modifySolrQuery(solrQuery, searchCriteria.getQuery(), facets, searchCriteria, defaultSort);
    // on child documents.
    if (StringUtils.isNotBlank(defaultSort) || StringUtils.isNotBlank(searchCriteria.getSortQuery())) {
        solrQuery.remove("bq");
        solrQuery.remove("bf");
        solrQuery.remove("boost");
    }
    attachSortClause(solrQuery, searchCriteria, defaultSort);
    solrQuery.setShowDebugInfo(shouldShowDebugQuery());
    if (LOG.isTraceEnabled()) {
        try {
            LOG.trace(URLDecoder.decode(solrQuery.toString(), "UTF-8"));
        } catch (Exception e) {
            LOG.trace("Couldn't UTF-8 URL Decode: " + solrQuery.toString());
        }
    }
    // Query solr
    QueryResponse response;
    List<SolrDocument> responseDocuments;
    int numResults = 0;
    try {
        response = solrConfiguration.getServer().query(solrQuery, getSolrQueryMethod());
        responseDocuments = getResponseDocuments(response);
        numResults = (int) response.getResults().getNumFound();
        if (LOG.isTraceEnabled()) {
            LOG.trace(response.toString());
            for (SolrDocument doc : responseDocuments) {
                LOG.trace(doc);
            }
        }
    } catch (SolrServerException e) {
        throw new ServiceException("Could not perform search", e);
    } catch (IOException e) {
        throw new ServiceException("Could not perform search", e);
    }
    // Get the facets
    setFacetResults(namedFacetMap, response);
    sortFacetResults(namedFacetMap);
    filterEmptyFacets(facets);
    SearchResult result = new SearchResult();
    result.setFacets(facets);
    result.setQueryResponse(response);
    setPagingAttributes(result, numResults, searchCriteria);
    if (useSku) {
        List<Sku> skus = getSkus(responseDocuments);
        result.setSkus(skus);
    } else {
        // Get the products
        List<Product> products = getProducts(responseDocuments);
        result.setProducts(products);
    }
    return result;
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) Product(org.broadleafcommerce.core.catalog.domain.Product) SearchResult(org.broadleafcommerce.core.search.domain.SearchResult) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ServiceException(org.broadleafcommerce.common.exception.ServiceException) IOException(java.io.IOException) SolrDocument(org.apache.solr.common.SolrDocument) ServiceException(org.broadleafcommerce.common.exception.ServiceException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 40 with Product

use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.

the class ProductDataProvider method provideBasicProduct.

/**
 * A basic product is actually a Product and a Sku
 */
@DataProvider(name = "basicProduct")
public static Object[][] provideBasicProduct() {
    Product ci = new ProductImpl();
    Sku defaultSku = new SkuImpl();
    defaultSku.setName("setOfAggieDominoes");
    defaultSku.setDescription("a fine set of bones for 42");
    ci.setDefaultSku(defaultSku);
    return new Object[][] { { ci } };
}
Also used : SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) DataProvider(org.testng.annotations.DataProvider)

Aggregations

Product (org.broadleafcommerce.core.catalog.domain.Product)77 Sku (org.broadleafcommerce.core.catalog.domain.Sku)34 ArrayList (java.util.ArrayList)23 Category (org.broadleafcommerce.core.catalog.domain.Category)18 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)17 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)12 Order (org.broadleafcommerce.core.order.domain.Order)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.testng.annotations.Test)11 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)10 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)9 Money (org.broadleafcommerce.common.money.Money)9 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)9 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)8 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)7 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)7 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 RelatedProduct (org.broadleafcommerce.core.catalog.domain.RelatedProduct)6 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)6