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