use of com.salesmanager.core.model.catalog.product.variation.ProductVariation in project shopizer by shopizer-ecommerce.
the class ProductVariationFacadeImpl method delete.
@Override
public void delete(Long variationId, MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(variationId, "variationId cannot be null");
ProductVariation opt = productVariationService.getById(variationId);
if (opt == null) {
throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
}
if (!opt.getMerchantStore().getCode().equals(store.getCode())) {
throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
}
try {
productVariationService.delete(opt);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while deleting ProductVariation", e);
}
}
use of com.salesmanager.core.model.catalog.product.variation.ProductVariation in project shopizer by shopizer-ecommerce.
the class ProductVariationFacadeImpl method exists.
@Override
public boolean exists(String code, MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(code, "code cannot be null");
ProductVariation var = productVariationService.getByCode(store, code);
if (var != null) {
return true;
}
return false;
}
use of com.salesmanager.core.model.catalog.product.variation.ProductVariation in project shopizer by shopizer-ecommerce.
the class PersistableProductInstanceMapper method merge.
@Override
public ProductInstance merge(PersistableProductInstance source, ProductInstance destination, MerchantStore store, Language language) {
//
Long productVariant = source.getVariant();
Long productVariantValue = source.getVariantValue();
Optional<ProductVariation> variant = productVariationService.getById(store, productVariant);
Optional<ProductVariation> variantValue = productVariationService.getById(store, productVariantValue);
if (variant.isEmpty()) {
throw new ResourceNotFoundException("ProductVariant [" + productVariant + "] + not found for store [" + store.getCode() + "]");
}
destination.setVariant(variant.get());
if (variantValue.isEmpty()) {
throw new ResourceNotFoundException("ProductVariant [" + productVariantValue + "] + not found for store [" + store.getCode() + "]");
}
destination.setVariantValue(variantValue.get());
destination.setCode(variant.get().getCode() + ":" + variantValue.get().getCode());
destination.setAvailable(source.isAvailable());
destination.setDefaultSelection(source.isDefaultSelection());
destination.setSku(source.getSku());
if (StringUtils.isBlank(source.getDateAvailable())) {
source.setDateAvailable(DateUtil.formatDate(new Date()));
}
if (source.getDateAvailable() != null) {
try {
destination.setDateAvailable(DateUtil.getDate(source.getDateAvailable()));
} catch (Exception e) {
throw new ServiceRuntimeException("Cant format date [" + source.getDateAvailable() + "]");
}
}
destination.setSortOrder(source.getSortOrder());
Product product = productService.getById(source.getProductId());
if (product == null) {
throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]");
}
if (product.getMerchantStore().getId() != store.getId()) {
throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]");
}
destination.setProduct(product);
return destination;
}
use of com.salesmanager.core.model.catalog.product.variation.ProductVariation 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.variation.ProductVariation in project shopizer by shopizer-ecommerce.
the class ProductVariationFacadeImpl method create.
@Override
public Long create(PersistableProductVariation var, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
Validate.notNull(var, "PersistableProductVariation cannot be null");
if (this.exists(var.getCode(), store)) {
throw new OperationNotAllowedException("Option set with code [" + var.getCode() + "] already exist");
}
ProductVariation p = persistableProductVariationMapper.convert(var, store, language);
p.setMerchantStore(store);
try {
productVariationService.saveOrUpdate(p);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while creating ProductOptionSet", e);
}
return p.getId();
}
Aggregations