Skip to content

How to update product position of a product in a specific category of specific store view in magento 2.4.4

I have a multi-store website and have more than 30 categories. I have a requirement like updating the product position.

For example, I have a category ‘XYZ’ which contains more than 500+ products available. this category is enabled for default scope and other store view scopes such as ‘A’, ‘B’, and ‘C'(I’m taking A, B, and C as an example of different store views).

So I want to update the product position of every product in the ‘XYZ’ category only for the ‘B’ store view (while updating, other store view product positions should not be changed).

I have tried using the repository/category model object to update the product position for a specific store view, but it takes so long if we are updating almost 100 products.

I also tried setProductsPosition($productPosition) method to update the product, but this is updating the product position for all the store views.

Does anyone have any idea how to update the product position only for a specific category of a specific store view?