Reputation: 1
I'm using the code below to remove the product from catelog - skincare ,
var name=pdict.categoryName;
var category=CatalogMgr.getCategory('skincare');
if(category && category.products.length){
for each(var product in category.products){
if(!product.custom.productBadge1){
var assignments = product.getCategoryAssignments();
for(var i=0;i<assignments.length;i++)
{
if(assignments[i].category.ID=='skincare'){
//TO DO remove product from category
}
}
}
}
}
which API to be used here
Upvotes: -1
Views: 292
Reputation: 1
To remove a product from a category via Demandware (SFCC) API:
dw.catalog.CategoryMgr.getCategory(categoryID)
to get the category object.dw.catalog.ProductMgr.getProduct(productID)
to get the product object.category.removeProduct(product)
to remove the product from the category.dw.system.Transaction.wrap()
.Example:
output:
const Transaction = require('dw/system/Transaction');
const CategoryMgr = require('dw/catalog/CategoryMgr');
const ProductMgr = require('dw/catalog/ProductMgr');
Transaction.wrap(() => {
const category = CategoryMgr.getCategory('categoryID');
const product = ProductMgr.getProduct('productID');
if (category && product) {
category.removeProduct(product);
}
});
Upvotes: 0
Reputation: 1
Well, one possible way is, you can write an XML to remove the assignment and import it manually or through a job. This can be the worst-case scenario.
Upvotes: 0