use of org.broadleafcommerce.core.catalog.domain.Sku in project BroadleafCommerce by BroadleafCommerce.
the class SkuDaoImpl method findSkuByURI.
@Override
public List<Sku> findSkuByURI(String uri) {
if (extensionManager != null) {
ExtensionResultHolder holder = new ExtensionResultHolder();
ExtensionResultStatusType result = extensionManager.getProxy().findSkuByURI(uri, holder);
if (ExtensionResultStatusType.HANDLED.equals(result)) {
return (List<Sku>) holder.getResult();
}
}
String skuUrlKey = uri.substring(uri.lastIndexOf('/'));
String productUrl = uri.substring(0, uri.lastIndexOf('/'));
Query query;
query = em.createNamedQuery("BC_READ_SKU_BY_OUTGOING_URL");
query.setParameter("url", uri);
query.setParameter("productUrl", productUrl);
query.setParameter("skuUrlKey", skuUrlKey);
query.setParameter("currentDate", DateUtil.getCurrentDateAfterFactoringInDateResolution(cachedDate, currentDateResolution));
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
@SuppressWarnings("unchecked") List<Sku> results = query.getResultList();
return results;
}
use of org.broadleafcommerce.core.catalog.domain.Sku in project BroadleafCommerce by BroadleafCommerce.
the class SkuDaoImpl method getCriteriaForActiveSkus.
protected CriteriaQuery<Sku> getCriteriaForActiveSkus(Date currentDate, Long lastId) {
// Set up the criteria query that specifies we want to return Products
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Sku> criteria = builder.createQuery(Sku.class);
// The root of our search is Product
Root<SkuImpl> sku = criteria.from(SkuImpl.class);
// Product objects are what we want back
criteria.select(sku);
// Ensure the product is currently active
List<Predicate> restrictions = new ArrayList<Predicate>();
// Add the active start/end date restrictions
restrictions.add(builder.lessThan(sku.get("activeStartDate").as(Date.class), currentDate));
restrictions.add(builder.or(builder.isNull(sku.get("activeEndDate")), builder.greaterThan(sku.get("activeEndDate").as(Date.class), currentDate)));
if (lastId != null) {
restrictions.add(builder.gt(sku.get("id").as(Long.class), lastId));
}
// Add the restrictions to the criteria query
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
// Add ordering so that paginated queries are consistent
criteria.orderBy(builder.asc(sku.get("id")));
return criteria;
}
use of org.broadleafcommerce.core.catalog.domain.Sku in project BroadleafCommerce by BroadleafCommerce.
the class GoogleUniversalAnalyticsProcessor method getItemJs.
protected String getItemJs(Order order, String trackerPrefix) {
StringBuffer sb = new StringBuffer();
for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
OrderItem orderItem = fulfillmentGroupItem.getOrderItem();
Sku sku = ((SkuAccessor) orderItem).getSku();
sb.append("ga('" + trackerPrefix + "ecommerce:addItem', {");
sb.append("'id': '" + order.getOrderNumber() + "'");
sb.append(",'name': '" + sku.getName() + "'");
sb.append(",'sku': '" + sku.getId() + "'");
sb.append(",'category': '" + getVariation(orderItem) + "'");
sb.append(",'price': '" + orderItem.getAveragePrice() + "'");
sb.append(",'quantity': '" + orderItem.getQuantity() + "'");
sb.append("});");
}
}
return sb.toString();
}
use of org.broadleafcommerce.core.catalog.domain.Sku 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.Sku 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();
}
Aggregations