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

Add product into category by impex

Former Member
0 Likes
2,318

Hi experts,

I'm trying to add a product into category with this impex. But my problem is this impex remove the already assigned categories. I need to add the category into the product without deleting the rest of them. Is it possible??

 $productCatalog=xxxxxxProductCatalog
 $productCatalogName=xxxxx Product Catalog
 $catalogVersion = catalogversion(catalog(id[default = $productCatalog]), version[default = 'Staged'])[unique = true, default = $productCatalog:Staged]
 $supercategories = supercategories(code, $catalogVersion)
  
  UPDATE Product;code[unique=true];$supercategories;$catalogVersion
  ;000000000000302848;0032


Thanks a lot!

Accepted Solutions (1)

Accepted Solutions (1)

0 Likes

Hello,

yes, you can do this by slightly modifying your header. Just add [mode=append] to $supercategories, like this:

 UPDATE Product;code[unique=true];$supercategories[mode=append];$catalogVersion

Answers (1)

Answers (1)

andyfletcher
Active Contributor
0 Likes

Rather than using [mode=append] on the supercategories attribute, which creates duplicate relationships if you run the same impex multiple times, I prefer to create the relationship itself directly, which allows you to mark both source and target as unique and avoid duplicates.

e.g.

 INSERT_UPDATE CategoryProductRelation;source(code,$catalogVersion)[unique=true];target(code,$catalogVersion)[unique=true]
 ;category1;product1
 ;category2;product1
 ;category1;product2
former_member633554
Active Participant
0 Likes

This is the better answer.

Former Member
0 Likes

Thanks! you are right!