use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductInstanceFacadeImpl method create.
@Override
public Long create(PersistableProductInstance productInstance, Long productId, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(productInstance, "ProductInstance cannot be null");
Validate.notNull(productId, "Product id cannot be null");
// variation and variation value should not be of same product option code
if (productInstance.getVariant() != null && productInstance.getVariant().longValue() > 0 && productInstance.getVariantValue() != null && productInstance.getVariantValue().longValue() > 0) {
List<ProductVariation> variations = productVariationService.getByIds(Arrays.asList(productInstance.getVariant(), productInstance.getVariantValue()), store);
boolean differentOption = variations.stream().map(i -> i.getProductOption().getCode()).distinct().count() > 1;
if (!differentOption) {
throw new ConstraintException("Product option of instance.variant and instance.variantValue must be different");
}
}
productInstance.setProductId(productId);
productInstance.setId(null);
ProductInstance instance = persistableProductInstanceMapper.convert(productInstance, store, language);
try {
productInstanceService.save(instance);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot save product instance for store [" + store.getCode() + "] and productId [" + productId + "]", e);
}
return instance.getId();
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductInventoryFacadeImpl method getInventory.
@Override
public ReadableEntityList<ReadableInventory> getInventory(Long productId, MerchantStore store, String child, Language language, int page, int count) {
Product product = getProductById(productId);
validateProductHasSameStore(store, product);
Page<ProductAvailability> availabilities = productAvailabilityService.listByProduct(product, store, child, page, count);
List<ReadableInventory> inventories = availabilities.stream().map(pa -> readableInventoryMapper.convert(pa, store, language)).collect(Collectors.toList());
return createReadableList(availabilities, inventories);
}
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, String child, Language language) {
Product product = getProductById(productId);
MerchantStore store = getMerchantStore(child);
if (isStoreParentNotExist(store) || store.getParent().getId().equals(product.getMerchantStore().getId())) {
throw new ResourceNotFoundException("MerchantStore [" + child + "] is not a store of retailer [" + store.getCode() + "]");
}
ProductAvailability availability = productAvailabilityService.getByStore(product, store).orElseThrow(() -> new ResourceNotFoundException("Inventory with not found"));
return this.readableInventory(availability, store, language);
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method createAttributes.
@Override
public List<CodeEntity> createAttributes(List<PersistableProductAttribute> attributes, Long productId, MerchantStore store) {
Validate.notNull(productId, "Product id must not be null");
Validate.notNull(store, "Merchant cannot be null");
// convert to model
List<ProductAttribute> modelAttributes = attributes.stream().map(attr -> persistableProductAttributeMapper.convert(attr, store, null)).collect(Collectors.toList());
try {
productAttributeService.saveAll(modelAttributes);
// save to a product
Product product = this.product(productId, store);
product.getAttributes().addAll(modelAttributes);
productService.save(product);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while saving product with attributes", e);
}
return modelAttributes.stream().map(e -> codeEntity(e)).collect(Collectors.toList());
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method getAttributesList.
@Override
public ReadableProductAttributeList getAttributesList(Long productId, MerchantStore store, Language language, int page, int count) {
try {
Product product = this.product(productId, store);
ReadableProductAttributeList attrList = new ReadableProductAttributeList();
Page<ProductAttribute> attr = null;
if (language != null) {
// all entry
// attributes = productAttributeService.getByProductId(store, product, language);
attr = productAttributeService.getByProductId(store, product, language, page, count);
attrList.setRecordsTotal(attr.getTotalElements());
attrList.setNumber(attr.getSize());
attrList.setTotalPages(attr.getTotalPages());
} else {
attr = productAttributeService.getByProductId(store, product, page, count);
attrList.setRecordsTotal(attr.getTotalElements());
attrList.setNumber(attr.getSize());
attrList.setTotalPages(attr.getTotalPages());
}
List<ReadableProductAttributeEntity> values = attr.getContent().stream().map(attribute -> readableProductAttributeMapper.convert(attribute, store, language)).collect(Collectors.toList());
attrList.setAttributes(values);
return attrList;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting attributes", e);
}
}
Aggregations