use of org.broadleafcommerce.core.catalog.domain.Product 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.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductDaoImpl method readCountAllActiveProductsInternal.
protected Long readCountAllActiveProductsInternal(Date currentDate) {
// Set up the criteria query that specifies we want to return a Long
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
// The root of our search is Product
Root<ProductImpl> product = criteria.from(ProductImpl.class);
// We need to filter on active date on the sku
Join<Product, Sku> sku = product.join("defaultSku");
// We want the count of products
criteria.select(builder.count(product));
// Ensure the product is currently active
List<Predicate> restrictions = new ArrayList<Predicate>();
attachActiveRestriction(currentDate, product, sku, restrictions);
// Add the restrictions to the criteria query
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<Long> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
return query.getSingleResult();
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductDaoImpl method readFilteredActiveProductsByQueryInternal.
protected List<Product> readFilteredActiveProductsByQueryInternal(String query, Date currentDate, SearchCriteria searchCriteria) {
// Set up the criteria query that specifies we want to return Products
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Product> criteria = builder.createQuery(Product.class);
// The root of our search is Product since we are searching
Root<ProductImpl> product = criteria.from(ProductImpl.class);
// We also want to filter on attributes from sku and productAttributes
Join<Product, Sku> sku = product.join("defaultSku");
// Product objects are what we want back
criteria.select(product);
// We only want results that match the search query
List<Predicate> restrictions = new ArrayList<Predicate>();
if (query != null) {
String lq = query.toLowerCase();
restrictions.add(builder.or(builder.like(builder.lower(sku.get("name").as(String.class)), '%' + lq + '%'), builder.like(builder.lower(sku.get("longDescription").as(String.class)), '%' + lq + '%')));
}
attachSearchCriteria(searchCriteria, product, sku, restrictions);
attachActiveRestriction(currentDate, product, sku, restrictions);
attachOrderBy(searchCriteria, product, sku, criteria);
// Execute the query with the restrictions
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<Product> typedQuery = em.createQuery(criteria);
return typedQuery.getResultList();
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductDaoImpl method readProductsByIds.
@Override
public List<Product> readProductsByIds(List<Long> productIds) {
if (productIds == null || productIds.size() == 0) {
return null;
}
if (productIds.size() > 100) {
logger.warn("Not recommended to use the readProductsByIds method for long lists of productIds, since " + "Hibernate is required to transform the distinct results. The list of requested" + "product ids was (" + productIds.size() + ") in length.");
}
// Set up the criteria query that specifies we want to return Products
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Product> criteria = builder.createQuery(Product.class);
Root<ProductImpl> product = criteria.from(ProductImpl.class);
product.fetch("defaultSku", JoinType.LEFT);
criteria.select(product);
// We only want results that match the product IDs
criteria.where(product.get("id").as(Long.class).in(sandBoxHelper.mergeCloneIds(ProductImpl.class, productIds.toArray(new Long[productIds.size()]))));
TypedQuery<Product> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
return query.getResultList();
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductDaoImpl method findProductByURI.
@Override
public List<Product> findProductByURI(String uri) {
if (extensionManager != null) {
ExtensionResultHolder holder = new ExtensionResultHolder();
ExtensionResultStatusType result = extensionManager.getProxy().findProductByURI(uri, holder);
if (ExtensionResultStatusType.HANDLED.equals(result)) {
return (List<Product>) holder.getResult();
}
}
String urlKey = uri.substring(uri.lastIndexOf('/'));
Query query;
query = em.createNamedQuery("BC_READ_PRODUCTS_BY_OUTGOING_URL");
query.setParameter("url", uri);
query.setParameter("urlKey", urlKey);
query.setParameter("currentDate", DateUtil.getCurrentDateAfterFactoringInDateResolution(cachedDate, currentDateResolution));
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
@SuppressWarnings("unchecked") List<Product> results = query.getResultList();
return results;
}
Aggregations