Search in sources :

Example 26 with Sku

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;
}
Also used : TypedQuery(javax.persistence.TypedQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 27 with Sku

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ArrayList(java.util.ArrayList) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate)

Example 28 with Sku

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();
}
Also used : FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) Sku(org.broadleafcommerce.core.catalog.domain.Sku) SkuAccessor(org.broadleafcommerce.core.order.domain.SkuAccessor)

Example 29 with Sku

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Predicate(javax.persistence.criteria.Predicate)

Example 30 with Sku

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Predicate(javax.persistence.criteria.Predicate)

Aggregations

Sku (org.broadleafcommerce.core.catalog.domain.Sku)80 Product (org.broadleafcommerce.core.catalog.domain.Product)34 ArrayList (java.util.ArrayList)27 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)22 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)18 Money (org.broadleafcommerce.common.money.Money)16 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)16 Order (org.broadleafcommerce.core.order.domain.Order)15 Category (org.broadleafcommerce.core.catalog.domain.Category)13 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)12 Test (org.testng.annotations.Test)12 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)10 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)10 Transactional (org.springframework.transaction.annotation.Transactional)10 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)9 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)9 HashMap (java.util.HashMap)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)8 Entity (org.broadleafcommerce.openadmin.dto.Entity)8