use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductInstanceFacadeImpl method list.
@Override
public ReadableEntityList<ReadableProductInstance> list(Long productId, MerchantStore store, Language language, int page, int count) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(productId, "Product id cannot be null");
Product product = productFacade.getProduct(productId, store);
if (product == null) {
throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
}
Page<ProductInstance> instances = productInstanceService.getByProductId(store, product, language, page, count);
List<ReadableProductInstance> readableInstances = instances.stream().map(rp -> this.readableProductInstanceMapper.convert(rp, store, language)).collect(Collectors.toList());
return createReadableList(instances, readableInstances);
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductInventoryFacadeImpl method getProductAvailabilityToSave.
private ProductAvailability getProductAvailabilityToSave(PersistableInventory inventory, MerchantStore store, Long productId) {
Product product = getProductById(productId);
ProductAvailability availability = productInventoryMapper.convert(inventory, store, store.getDefaultLanguage());
availability.setProduct(product);
availability.setMerchantStore(store);
return availability;
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductInventoryFacadeImpl method get.
@Override
public ReadableInventory get(Long productId, Long inventoryId, MerchantStore store, Language language) {
Product product = getProductById(productId);
if (product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
}
ProductAvailability availability = productAvailabilityService.getByInventoryId(productId, inventoryId, store).orElseThrow(() -> new ResourceNotFoundException("Inventory with id [" + inventoryId + "] not found"));
return readableInventoryMapper.convert(availability, store, language);
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductInventoryFacadeImpl method update.
@Override
public void update(Long productId, PersistableInventory inventory, MerchantStore store, Language language) {
Validate.notNull(productId, "Product id cannot be null");
Validate.notNull(inventory, "Inventory cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Product product = getProductById(productId);
ProductAvailability availability = getAvailabilityById(store, inventory.getId());
if (availability.getProduct().getId().longValue() != productId) {
throw new ResourceNotFoundException("Availability with id [" + inventory.getId() + "] not found for product id [" + productId + "]");
}
inventory.setProductId(product.getId());
availability = productInventoryMapper.merge(inventory, availability, store, language);
availability.setProduct(product);
availability.setMerchantStore(store);
saveOrUpdate(availability);
}
use of com.salesmanager.core.model.catalog.product.Product 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;
}
Aggregations