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

How can multiple categories be removed from Product using impex?

Former Member
1,290

How can multiple categories be removed from Product using impex something like:

 REMOVE CategoryProductRelation;target[unique=true](code,$catalogVersion);source[unique=true](code,$catalogVersion)
 ;xyz;cat1,cat2,cat3


Thanks!!

Accepted Solutions (1)

Accepted Solutions (1)

arvind-kumar_avinash
Active Contributor

You can use batchmode=true as folllows:

 REMOVE CategoryProductRelation[batchmode=true];target[unique=true](code,$catalogVersion);source(code,$catalogVersion)
 ;xyz;cat1,cat2,cat3

For example, the following script removes categories, 576 and brand_10 for product, 1934794 using :

 $productCatalog=electronicsProductCatalog
 $productCatalogName=Electronics Product Catalog
 $catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]
 
 REMOVE CategoryProductRelation[batchmode=true];target[unique=true](code,$catalogVersion);source(code,$catalogVersion)
 ;1934794;576,brand_10

You can verify the result by executing the following Flexible Search query:

 SELECT {p:code}, {c:code} FROM
 {
    Product as p JOIN CategoryProductRelation as rel
    ON {p:PK} = {rel:target}
    JOIN Category AS c
    ON {rel:source} = {c:PK}
 } 
 WHERE {p:code}='1934794' AND {p:catalogVersion}=({{ SELECT {PK} FROM {catalogVersion} WHERE {catalog}=({{SELECT {PK} FROM {catalog} WHERE {id}='electronicsProductCatalog'}}) AND {version}='Staged' }})

Answers (1)

Answers (1)

geffchang
Active Contributor
0 Likes

Remove it 1 line each.

 REMOVE CategoryProductRelation;target(code,$catalogVersion)[unique=true];source(code,$catalogVersion)[unique=true]
 
 ;xyz;cat1
 ;xyz;cat2
 ;xyz;cat3
geffchang
Active Contributor
0 Likes

Don't forget to Upvote and Accept, if it works for you. :)

former_member1320010
Participant
0 Likes

With this impex do you get product and category available for next sync ?

geffchang
Active Contributor
0 Likes

Unfortunately, NO, because changing the categories this way doesn't change the modified time of the Product. So, it will not sync. There are cases where you want to do this.

In cases where you want the sync to work, it's better to update via Product type. i.e. UPDATE Product;supercategories...