cancel
Showing results for 
Search instead for 
Did you mean: 

method to save the product in product catalog

Former Member
0 Kudos

I have create a method in hybris which take the product details and i have save in hybris DB

IS there any method which is inbuilt in hybris.

My code:

@Autowired ModelService modelService;

 @Resource
 private CatalogVersionService catalogVersionService;
 
 private CatalogVersionModel catVersion1;

public void createProduct(String productName, String productDescription, String catVersion, String productHtml, String bundleReference, String controllerScript) throws Exception {

             catVersion1 = catalogVersionService.getCatalogVersion("cms_Catalog", "Staged");
         System.out.println(catVersion1);

         DynamicProductModel dynamicProductModel = new DynamicProductModel();
         //dynamicProductModel.getName("productName");
         dynamicProductModel.setDescription(productDescription);
         dynamicProductModel.setCatalogVersion(catVersion1);
         dynamicProductModel.setGeneratedHtml(productHtml);
         dynamicProductModel.setBundleReference(bundleReference);
         dynamicProductModel.setControllerScript(controllerScript);

         DynamicProductModel dynamicProductModelCreate = modelService.create(DynamicProductModel.class);
         // CatalogVersionModel
         CatalogVersionModel catalogVersionModel = new CatalogVersionModel();
         // catalogVersionModel.setCatalog(new CatalogModel().set);

         // dynamicProductModel.setCatalogVersion(new CatalogVersionModel()
         // );
         modelService.save(dynamicProductModelCreate);
     }
     
 


Please let me known where i went wrong. You can send me the updated code after changing the code

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Just DynamicProductModel dynamicProductModel = new DynamicProductModel(); remove this and replace with DynamicProductModel dynamicProductModelCreate = modelService.create(DynamicProductModel.class); and below remove this line DynamicProductModel dynamicProductModelCreate = modelService.create(DynamicProductModel.class);

I hope it will work.

Thanks Raushan