cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Impex scripting - passing variables in value line

knallapati
Explorer
0 Kudos
1,959

My requirement is to import product and generate product code via decorator. And then use the generated product code to pass as base product to the variant product impex. I am trying below script but the value line doesn't seem to honor the variables. Is there any work around for this scenario? this seems to be very common scenario but couldn't find any examples.

Product Impexes

INSERT_UPDATE  Product; code[unique=true][cellDecorator=com.decorators.ProductCodeCellDecorator]	;	$approved	;	$catalogVersion	;	name[lang=$lang]
	;		;		;		;	Test Product Name	;

"#% $Code = impex.getLastImportedItem().getCOde();"
#% System.out.println($Code);

INSERT_UPDATE  ProductVariant; code[unique=true][translator=com.translators.ProductVariantCodeTranslator];	$approved	;$catalogVersion  ;$baseProduct	;
	;		;		;		;	$Code	;

I can print $code in System out but It's failing in the variant product value line for baseproduct. 
Has anyone have come across this scenario? 

Accepted Solutions (1)

Accepted Solutions (1)

romitchhabra
Participant

You can try by storing the product in a variable after the product value line

"#% $baseProduct = impex.getLastImportedItem()"

And then try to import product variant with a blank or some dummy baseProduct through impex and then call the script to set/change the base product

impex.getLastImportedItem().setBaseProduct($baseProduct);

There may be some syntax issue in the above code, but I hope it is clear what I am trying to suggest.

knallapati
Explorer

Thank you Romit, your comment helped me resolve the issue. Here is the script for my product model just in case anyone else looking for it. We need to pass existing base product as it's mandatory.

INSERT_UPDATE  Product; code[unique=true][cellDecorator=com.decorators.ProductCodeCellDecorator]	;	$approved	;	$catalogVersion	;	name[lang=$lang]
"#% afterEach: 
				$importedProduct = impex.getLastImportedItem();
				$importedProductCode = impex.getLastImportedItem().getCode();
";	
	;		;		;		;	Test Product Name	;

INSERT_UPDATE  ProductVariant; code[unique=true][translator=com.translators.ProductVariantCodeTranslator];	$approved	;$catalogVersion  ;$baseProduct	;
"#% afterEach:  
				impex.getLastImportedItem().setCode($importedProductCode + ""-"" + 		impex.getLastImportedItem().getCode());
				impex.getLastImportedItem().setBaseProduct($importedProduct);
				de.hybris.platform.core.Registry.getApplicationContext().getBean(""productUtils"").registerVariantProduct($importedProduct, ""OPTION"", impex.getLastImportedItem());				
";
	;		;		;		;	<existing base product code>	;

Answers (0)