Search in sources :

Example 31 with Product

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

the class ProductOptionDaoImpl method getProductIdsUsingProductOptionByIdQuery.

private TypedQuery<Long> getProductIdsUsingProductOptionByIdQuery(Long productOptionId, boolean count) {
    // Set up the criteria query that specifies we want to return Products
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
    // The root of our search is ProductOptionXref
    Root<ProductOptionXrefImpl> productOptionXref = criteria.from(ProductOptionXrefImpl.class);
    Join<ProductOptionXref, Product> product = productOptionXref.join("product");
    Join<ProductOptionXref, ProductOption> productOption = productOptionXref.join("productOption");
    if (count) {
        criteria.select(builder.count(product));
    } else {
        // Product IDs are what we want back
        criteria.select(product.get("id").as(Long.class));
    }
    criteria.distinct(true);
    List<Predicate> restrictions = new ArrayList<Predicate>();
    restrictions.add(productOption.get("id").in(sandBoxHelper.mergeCloneIds(ProductOptionImpl.class, productOptionId)));
    // Execute the query with the restrictions
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    return em.createQuery(criteria);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProductOption(org.broadleafcommerce.core.catalog.domain.ProductOption) ProductOptionXref(org.broadleafcommerce.core.catalog.domain.ProductOptionXref) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Predicate(javax.persistence.criteria.Predicate) ProductOptionXrefImpl(org.broadleafcommerce.core.catalog.domain.ProductOptionXrefImpl)

Example 32 with Product

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

the class UncacheableDataProcessor method addCartData.

protected void addCartData(Map<String, Object> attrMap) {
    Order cart = CartState.getCart();
    int cartQty = 0;
    List<Long> cartItemIdsWithOptions = new ArrayList<>();
    List<Long> cartItemIdsWithoutOptions = new ArrayList<>();
    if (cart != null && cart.getOrderItems() != null) {
        cartQty = cart.getItemCount();
        for (OrderItem item : cart.getOrderItems()) {
            if (item instanceof SkuAccessor) {
                Sku sku = ((SkuAccessor) item).getSku();
                if (sku != null && sku.getProduct() != null && item.getParentOrderItem() == null) {
                    if (useSku) {
                        cartItemIdsWithoutOptions.add(sku.getId());
                    } else {
                        Product product = sku.getProduct();
                        List<ProductOptionXref> optionXrefs = product.getProductOptionXrefs();
                        if (optionXrefs == null || optionXrefs.isEmpty()) {
                            cartItemIdsWithoutOptions.add(product.getId());
                        } else {
                            cartItemIdsWithOptions.add(product.getId());
                        }
                    }
                }
            }
        }
    }
    attrMap.put("cartItemCount", cartQty);
    attrMap.put("cartItemIdsWithOptions", cartItemIdsWithOptions);
    attrMap.put("cartItemIdsWithoutOptions", cartItemIdsWithoutOptions);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) ProductOptionXref(org.broadleafcommerce.core.catalog.domain.ProductOptionXref) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) SkuAccessor(org.broadleafcommerce.core.order.domain.SkuAccessor)

Example 33 with Product

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

the class CatalogServiceImpl method findProductByURI.

@Override
public Product findProductByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findProductByURI(createCatalogContextDTO(), uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (Product) holder.getResult();
        }
    }
    return findOriginalProductByURI(uri);
}
Also used : Product(org.broadleafcommerce.core.catalog.domain.Product) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 34 with Product

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

the class ProductSiteMapGenerator method addSiteMapEntries.

@Override
public void addSiteMapEntries(SiteMapGeneratorConfiguration smgc, SiteMapBuilder siteMapBuilder) {
    int pageNum = 0;
    List<Product> products;
    do {
        products = productDao.readAllActiveProducts(pageNum++, pageSize);
        for (Product product : products) {
            if (StringUtils.isEmpty(product.getUrl())) {
                continue;
            }
            SiteMapURLWrapper siteMapUrl = new SiteMapURLWrapper();
            // location
            siteMapUrl.setLoc(generateUri(siteMapBuilder, product));
            // change frequency
            siteMapUrl.setChangeFreqType(smgc.getSiteMapChangeFreq());
            // priority
            siteMapUrl.setPriorityType(smgc.getSiteMapPriority());
            // lastModDate
            siteMapUrl.setLastModDate(generateDate(product));
            constructImageURLs(siteMapBuilder, siteMapUrl, product);
            siteMapBuilder.addUrl(siteMapUrl);
        }
    } while (products.size() == pageSize);
}
Also used : Product(org.broadleafcommerce.core.catalog.domain.Product) SiteMapURLWrapper(org.broadleafcommerce.common.sitemap.wrapper.SiteMapURLWrapper)

Example 35 with Product

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

the class AdminCatalogServiceImpl method cloneProduct.

@Override
public Boolean cloneProduct(Long productId) {
    Product cloneProduct = catalogService.findProductById(productId);
    // initialize the many-to-many to save off
    cloneProduct.getProductOptions().size();
    cloneProduct.getAllParentCategories().size();
    // Detach and save a cloned Sku
    Sku cloneSku = cloneProduct.getDefaultSku();
    cloneSku.getSkuMedia().size();
    em.detach(cloneSku);
    cloneSku.setId(null);
    cloneProduct.setDefaultSku(cloneSku);
    em.detach(cloneProduct);
    cloneProduct.setId(null);
    Product derivedProduct = catalogService.saveProduct(cloneProduct);
    cloneProduct = catalogService.findProductById(productId);
    // Re-associate the new Skus to the new Product
    for (Sku additionalSku : cloneProduct.getAdditionalSkus()) {
        additionalSku.getProductOptionValues().size();
        em.detach(additionalSku);
        additionalSku.setId(null);
        additionalSku.setProduct(derivedProduct);
        catalogService.saveSku(additionalSku);
    }
    return true;
}
Also used : Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

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