use of com.salesmanager.core.model.catalog.product.instance.ProductInstance in project shopizer by shopizer-ecommerce.
the class ProductInstanceFacadeImpl method delete.
@Override
public void delete(Long productInstance, Long productId, MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(productInstance, "ProductInstance id cannot be null");
Validate.notNull(productId, "Product id cannot be null");
Optional<ProductInstance> instanceModel = this.getProductInstance(productInstance, productId, store);
if (instanceModel.isEmpty()) {
throw new ResourceNotFoundException("ProductInstance with id [" + productInstance + "] not found for store [" + store.getCode() + "] and productId [" + productId + "]");
}
try {
productInstanceService.delete(instanceModel.get());
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot delete product instance [" + productInstance + "] for store [" + store.getCode() + "] and productId [" + productId + "]", e);
}
}
use of com.salesmanager.core.model.catalog.product.instance.ProductInstance in project shopizer by shopizer-ecommerce.
the class ProductInstanceGroupFacadeImpl method delete.
@Override
public void delete(Long productInstanceGroup, Long productId, MerchantStore store) {
ProductInstanceGroup group = this.group(productInstanceGroup, store);
if (group == null) {
throw new ResourceNotFoundException("Product instance group [" + group.getId() + " not found for store [" + store.getCode() + "]");
}
try {
// null all group from instances
for (ProductInstance instance : group.getProductInstances()) {
Optional<ProductInstance> p = productInstanceService.getById(instance.getId(), store);
if (p.isEmpty()) {
throw new ResourceNotFoundException("Product instance [" + instance.getId() + " not found for store [" + store.getCode() + "]");
}
instance.setProductInstanceGroup(null);
productInstanceService.save(instance);
}
// now delete
productInstanceGroupService.delete(group);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot remove product instance group [" + productInstanceGroup + "] for store [" + store.getCode() + "]");
}
}
use of com.salesmanager.core.model.catalog.product.instance.ProductInstance in project shopizer by shopizer-ecommerce.
the class PersistableProductIntanceGroupMapper method merge.
@Override
public ProductInstanceGroup merge(PersistableProductInstanceGroup source, ProductInstanceGroup destination, MerchantStore store, Language language) {
Validate.notNull(source, "PersistableProductInstanceGroup cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
Validate.notNull(source.getProductInstances(), "Product instances cannot be null");
if (destination == null) {
destination = new ProductInstanceGroup();
}
destination.setId(source.getId());
List<ProductInstance> productInstances = productInstanceService.getByIds(source.getProductInstances(), store);
for (ProductInstance p : productInstances) {
p.setProductInstanceGroup(destination);
}
// images are not managed from this object
if (source.getId() != null) {
List<ProductInstanceImage> images = productInstanceImageService.listByProductInstanceGroup(source.getId(), store);
destination.setImages(images);
}
destination.setMerchantStore(store);
destination.setProductInstances(new HashSet<ProductInstance>(productInstances));
return destination;
}
use of com.salesmanager.core.model.catalog.product.instance.ProductInstance in project shopizer by shopizer-ecommerce.
the class ReadableProductInstanceGroupMapper method merge.
@Override
public ReadableProductInstanceGroup merge(ProductInstanceGroup source, ReadableProductInstanceGroup destination, MerchantStore store, Language language) {
Validate.notNull(source, "ProductInstanceGroup cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
if (destination == null) {
destination = new ReadableProductInstanceGroup();
}
destination.setId(source.getId());
Set<ProductInstance> instances = source.getProductInstances();
destination.setProductInstances(instances.stream().map(i -> this.instance(i, store, language)).collect(Collectors.toList()));
// image id should be unique in the list
destination.setImages(source.getImages().stream().map(i -> this.image(i, store, language)).collect(Collectors.toList()));
return destination;
}
use of com.salesmanager.core.model.catalog.product.instance.ProductInstance 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