Hi,
I am trying to assign products to categories programmatically using Magento\Catalog\Api\CategoryLinkManagementInterface but its not working. I am calling a custom service code by calling a cron job.
Magento Version is 2.0.15
Please help.
Thanks in advance.
Hello,
private function getCategoryLinkManagement() { if (null === $this->categoryLinkManagement) { $this->categoryLinkManagement = \Magento\Framework\App\ObjectManager::getInstance() ->get('Magento\Catalog\Api\CategoryLinkManagementInterface'); } return $this->categoryLinkManagement; }
$this->getCategoryLinkManagement()->assignProductToCategories( $product->getSku(), $product->getCategoryIds() );
If above code then please mark as solution.
check save function