Search code examples
demandware

Demandware: Find Product's Category Position?


I'm updating a data feed export, which links a Product to a given Category. I want to also include that product's merchandising position within that category, which currently exists in Business Manger, and is used to control sorting on Product listing pages:

Screenshot of Business Manger highlighting field in question

I'm digging through the API docs, and the logical place for this information to be exposed in in dw.catalog.CategoryAssignment, but it's not there. I'm currently inferring the position by essentially doing this:

// assume var product, category
var position = category.products.firstIndex(p => p.ID == product.ID);

However, this tells me where the Product got sorted to, not what the actual Position value is within Demandware. It works for now as an expedient hack, but I really want to replace it with something that pulls the actual value from DW.

Where in the Commerce Cloud API can I find the merchandising position for a given Product in a given Category?


Solution

  • It took some digging, but I managed to find that the "Position" field for Products in the BM is stored as Product.searchPlacement. To find it, you have to look in Category.products, find the Product you want, and grab the searchPlacement property of that product.

    In effect, I used:

    // assume var product, category
    var position = category.products.find(p => p.ID == product.ID).searchPlacement;
    

    For Products that don't have a Position assigned in the Business Manager, searchPlacement is 0. Otherwise, it reflects the value entered in the BM.