use of com.salesmanager.shop.model.catalog.product.ReadableProduct in project shopizer by shopizer-ecommerce.
the class ProductFacadeV2Impl method getProductBySeUrl.
@Override
public ReadableProduct getProductBySeUrl(MerchantStore store, String friendlyUrl, Language language) throws Exception {
Product product = productService.getBySeUrl(store, friendlyUrl, LocaleUtils.getLocale(language));
if (product == null) {
throw new ResourceNotFoundException("Product [" + friendlyUrl + "] not found for merchant [" + store.getCode() + "]");
}
ReadableProduct readableProduct = readableProductMapper.convert(product, store, language);
// get all instances for this product group by option
// limit to 15 searches
List<ProductInstance> instances = productInstanceService.getByProductId(store, product, language);
// the above get all possible images
List<ReadableProductInstance> readableInstances = instances.stream().map(p -> this.productInstance(p, store, language)).collect(Collectors.toList());
readableProduct.setVariants(readableInstances);
return readableProduct;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProduct in project shopizer by shopizer-ecommerce.
the class ProductFacadeV2Impl method getProductByCode.
@Override
public ReadableProduct getProductByCode(MerchantStore store, String uniqueCode, Language language) {
Product product = productService.getByCode(uniqueCode, language);
if (product == null) {
throw new ResourceNotFoundException("Product [" + uniqueCode + "] not found for merchant [" + store.getCode() + "]");
}
if (product.getMerchantStore().getId() != store.getId()) {
throw new ResourceNotFoundException("Product [" + uniqueCode + "] not found for merchant [" + store.getCode() + "]");
}
ReadableProduct readableProduct = readableProductMapper.convert(product, store, language);
// get all instances for this product group by option
// limit to 15 searches
List<ProductInstance> instances = productInstanceService.getByProductId(store, product, language);
// the above get all possible images
List<ReadableProductInstance> readableInstances = instances.stream().map(p -> this.productInstance(p, store, language)).collect(Collectors.toList());
readableProduct.setVariants(readableInstances);
return readableProduct;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProduct in project shopizer by shopizer-ecommerce.
the class ProductFacadeV2Impl method relatedItems.
@Override
public List<ReadableProduct> relatedItems(MerchantStore store, Product product, Language language) throws Exception {
// same as v1
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
List<ProductRelationship> relatedItems = productRelationshipService.getByType(store, product, ProductRelationshipType.RELATED_ITEM);
if (relatedItems != null && relatedItems.size() > 0) {
List<ReadableProduct> items = new ArrayList<ReadableProduct>();
for (ProductRelationship relationship : relatedItems) {
Product relatedProduct = relationship.getRelatedProduct();
ReadableProduct proxyProduct = populator.populate(relatedProduct, new ReadableProduct(), store, language);
items.add(proxyProduct);
}
return items;
}
return null;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProduct in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method addProductToCategory.
@Override
public ReadableProduct addProductToCategory(Category category, Product product, Language language) {
Validate.notNull(category, "Category cannot be null");
Validate.notNull(product, "Product cannot be null");
// not alloweed if category already attached
List<Category> assigned = product.getCategories().stream().filter(cat -> cat.getId().longValue() == category.getId().longValue()).collect(Collectors.toList());
if (assigned.size() > 0) {
throw new OperationNotAllowedException("Category with id [" + category.getId() + "] already attached to product [" + product.getId() + "]");
}
product.getCategories().add(category);
ReadableProduct readableProduct = new ReadableProduct();
try {
productService.update(product);
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
populator.populate(product, readableProduct, product.getMerchantStore(), language);
} catch (Exception e) {
throw new RuntimeException("Exception when adding product [" + product.getId() + "] to category [" + category.getId() + "]", e);
}
return readableProduct;
}
use of com.salesmanager.shop.model.catalog.product.ReadableProduct in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method updateProductQuantity.
@Override
public ReadableProduct updateProductQuantity(ReadableProduct product, int quantity, Language language) throws Exception {
Product persistable = productService.getById(product.getId());
if (persistable == null) {
throw new Exception("product is null for id " + product.getId());
}
java.util.Set<ProductAvailability> availabilities = persistable.getAvailabilities();
for (ProductAvailability availability : availabilities) {
availability.setProductQuantity(quantity);
}
productService.update(persistable);
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
populator.populate(persistable, readableProduct, persistable.getMerchantStore(), language);
return readableProduct;
}
Aggregations