on ‎2018 May 30 10:14 AM
Hi all , i'm trying to access the catalogversionservice through groovy, yet this throws up errors. It works fine if it's not in a class.
The error i get is Script execution has failed [reason: java.lang.NullPointerException: Cannot invoke method getCatalogVersion() on null object]
import de.hybris.platform.catalog.model.CatalogVersionModel;
import de.hybris.platform.catalog.model.CatalogModel;
import de.hybris.platform.core.model.product.ProductModel;
import de.hybris.platform.product.ProductService;
import de.hybris.platform.catalog.CatalogVersionService;
import de.hybris.platform.catalog.model.classification.ClassAttributeAssignmentModel;
import de.hybris.platform.catalog.model.classification.ClassificationClassModel;
import de.hybris.platform.classification.features.*;
public class MainClass
{
def outputData()
{
CatalogVersionModel catalogVersion=catalogVersionService.getCatalogVersion("Maincat", "Staged");
ProductModel product1 = productService.getProductForCode(catalogVersion,"PROD_1");
}
}
new MainClass().outputData()
Request clarification before answering.
catalogVersionService is not in scope. It belongs to the implicit script class and is therefore not accessible from an instance of MainClass
You could do something like this to pass the catalogVersionService in when you construct the instance of MainClass
public class MainClass {
def catalogVersionService
def productService
def outputData() {
def catalogVersion = catalogVersionService.getCatalogVersion('Maincat', 'Staged')
def product1 = productService.getProductForCode(catalogVersion, 'PROD_1')
println product1.name
}
}
new MainClass(catalogVersionService: catalogVersionService, productService: productService).outputData()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This also works from within a method in a class.
CatalogVersionService catalogVersionService = (CatalogVersionService) Registry.getApplicationContext().getBean("catalogVersionService");
CatalogVersionModel catVersion = catalogVersionService.getCatalogVersion("Maincat", "Staged");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi , While using groovy , you can access the spring beans directly by their bean id. In your case , rather using defaultCatalogVersionService would probably do the trick.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Have you checked this document? https://help.hybris.com/6.4.0/hcd/8bec04a386691014938a9996a977d07f.html
Have you tried to get catalogVersionService by:
catalogVersionService = spring.getBean "catalogVersionService"
?
Regards
Lukasz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.