use of com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance 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.product.instance.ReadableProductInstance 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.product.instance.ReadableProductInstance in project shopizer by shopizer-ecommerce.
the class ProductInstanceFacadeImpl method get.
@Override
public ReadableProductInstance get(Long instanceId, Long productId, MerchantStore store, Language language) {
Optional<ProductInstance> productInstance = this.getProductInstance(instanceId, productId, store);
if (productInstance.isEmpty()) {
throw new ResourceNotFoundException("Product instance + [" + instanceId + "] not found for store [" + store.getCode() + "]");
}
ProductInstance model = productInstance.get();
return readableProductInstanceMapper.convert(model, store, language);
}
use of com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance 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.shop.model.catalog.product.product.instance.ReadableProductInstance in project shopizer by shopizer-ecommerce.
the class ReadableProductInstanceMapper method merge.
@Override
public ReadableProductInstance merge(ProductInstance source, ReadableProductInstance destination, MerchantStore store, Language language) {
Validate.notNull(source, "Product instance cannot be null");
Validate.notNull(source.getProduct(), "Product cannot be null");
if (destination == null) {
destination = new ReadableProductInstance();
}
destination.setSortOrder(source.getSortOrder() != null ? source.getSortOrder().intValue() : 0);
destination.setAvailable(source.isAvailable());
destination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
destination.setId(source.getId());
destination.setDefaultSelection(source.isDefaultSelection());
destination.setProductId(source.getProduct().getId());
destination.setSku(source.getSku());
destination.setSortOrder(source.getSortOrder());
destination.setCode(source.getCode());
// get product
Product baseProduct = source.getProduct();
if (baseProduct == null) {
throw new ResourceNotFoundException("Product instances do not include the parent product [" + destination.getSku() + "]");
}
destination.setProductShipeable(baseProduct.isProductShipeable());
// destination.setStore(null);
destination.setStore(store.getCode());
destination.setVariant(readableProductVariationMapper.convert(source.getVariant(), store, language));
destination.setVariantValue(readableProductVariationMapper.convert(source.getVariantValue(), store, language));
if (source.getProductInstanceGroup() != null) {
Set<String> nameSet = new HashSet<>();
List<ReadableImage> instanceImages = source.getProductInstanceGroup().getImages().stream().map(i -> this.image(i, store, language)).filter(e -> nameSet.add(e.getImageUrl())).collect(Collectors.toList());
destination.setImages(instanceImages);
}
if (!CollectionUtils.isEmpty(source.getAvailabilities())) {
List<ReadableInventory> inventories = source.getAvailabilities().stream().map(i -> readableInventoryMapper.convert(i, store, language)).collect(Collectors.toList());
destination.setInventory(inventories);
}
return destination;
}
Aggregations