Hello,
I am working on Magento open source (Community Version). API to integrate Magento with third party application.
I would like to know can i add multiple products to a particular category using API.
Hi @tatyanabog2b46 ,
protected $categoryLinkManagement;
private function getCategoryLinkManagement()
{
if (null === $this->categoryLinkManagement) {
$this->categoryLinkManagement = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Catalog\Api\CategoryLinkManagementInterface');
}
return $this->categoryLinkManagement;
}
You can use below code
$categoryIds = [1];
$this->getCategoryLinkManagement()->assignProductToCategories(
$product->getSku(),
$categoryIds
);
Problem Solved? Accept as Solution!
Hope it helps!
Thanks