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