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

How to insert a Keyword and relate it to a product via impex?

richpa
Explorer
0 Likes
1,325

I have a requirement to insert keywords and relate them to products via impex, but the syntax on the relation is unknown to me. This is the IMPEX

 $productCatalog=testProductCatalog
 $catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]
 $lang=Language(isocode)[default='en']
 $keyword=Keyword
 $products=target(code, $catalogVersion)[unique=true]
 $keywords=source($keyword, $lang, $catalogVersion)
 
 INSERT_UPDATE Keyword;$catalogVersion;$keyword;$lang
 ;;TestKeyword;en;
 
 INSERT_UPDATE Product2KeywordRelation;$keywords;$products;
 ;TestKeyword;TestProduct;

The Keyword imports fine, but I cannot get the Product2KeywordRelation to import. This is the error that is displayed:

,,,,item reference TestKeyword for attribute Language.isocode does not provide enough values at position 1;TestKeyword;TestProduct;

Can anyone help me get the proper syntax?

Accepted Solutions (1)

Accepted Solutions (1)

richpa
Explorer

I figured out that the solution is the colon character. It is used to separate entries when one needs to pass multiple parameters into the same impex method. Here is a working solution to insert a keyword and then link it to a product via impex:

 $productCatalog=testProductCatalog
 $productCV=catalogVersion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]
 $lang=Language(isocode)[default='en']
 $products=target(code, $productCV)[unique=true]
 $keywords=source(Keyword, $lang, $productCV)[unique=true]
 
 INSERT_UPDATE Keyword;keyword[unique=true];$lang;$productCV
 ;TestKey;en;;
 
 INSERT_UPDATE Product2KeywordRelation;$keywords;$products;$lang
 ;TestKey:en;TestProduct;

Answers (2)

Answers (2)

richpa
Explorer
0 Likes
muralikakkirenikb

Per the catalog-items.xml, Product2KeywordRelation is a many to many relationship, so you should be able to add multiple keywords on a product. Just do each one on separate lines as you have in your example.

former_member650979
Discoverer
0 Likes

richpa

If I have to add multiple keywords in a product, how can I do that ?

INSERT_UPDATE Keyword;keyword[unique=true];$lang;$productCV

;test1;de;;

;test2;de;;

INSERT_UPDATE Product2KeywordRelation;$keywords;$products;$lang

;test1:de;product_code1;

;test2:de;product_code1;