class PersistableProductVariantGroupMapper implements Mapper<PersistableProductVariantGroup, ProductVariantGroup>{

	
	@Autowired
	private ProductVariantService productVariantService;
	
	@Autowired
	private ProductVariantImageService productVariantImageService;
	
	@Override
	public ProductVariantGroup convert(PersistableProductVariantGroup source, MerchantStore store,
			Language language) {
		Validate.notNull(source, "PersistableproductVariantGroup cannot be null");
		Validate.notNull(store, "MerchantStore cannot be null");
		Validate.notNull(language, "Language cannot be null");
		return this.merge(source, new ProductVariantGroup(), store, language);
	}

	@Override
	public ProductVariantGroup merge(PersistableProductVariantGroup source, ProductVariantGroup destination,
			MerchantStore store, Language language) {<FILL_FUNCTION_BODY>}
	
	private ProductVariant instance(ProductVariant instance, ProductVariantGroup group, MerchantStore store) {
		
		instance.setProductVariantGroup(group);
		return instance;

	}

}

		
		Validate.notNull(source, "PersistableproductVariantGroup cannot be null");
		Validate.notNull(store, "MerchantStore cannot be null");
		Validate.notNull(language, "Language cannot be null");
		Validate.notNull(source.getproductVariants(), "Product instances cannot be null");	
		
		if(destination == null) {
			destination = new ProductVariantGroup();
		}
		
		destination.setId(source.getId());
		
		
		List<ProductVariant> productVariants = productVariantService.getByIds(source.getproductVariants(), store);
		
		for(ProductVariant p : productVariants) {
			p.setProductVariantGroup(destination);
		}

		//images are not managed from this object
		if(source.getId() != null) {
			List<ProductVariantImage> images = productVariantImageService.listByProductVariantGroup(source.getId(), store);
			destination.setImages(images);
		}
		destination.setMerchantStore(store);
		destination.setProductVariants(new HashSet<ProductVariant>(productVariants));
		return destination;
	
<no_super_class>