public function addCategoryToProduct(ProductInterface $product, CategoryInterface $category, $main = false)
{
if ($this->findOneBy(array('category' => $category, 'product' => $product))) {
return;
}
//
// if (null !== $category->getType() && self::CATEGORY_PRODUCT_TYPE !== $category->getType()) {
// // Should we throw an exception instead?
// $category->setType(self::CATEGORY_PRODUCT_TYPE);
// $this->categoryManager->save($category);
// }
$productCategory = $this->create();
$productCategory->setProduct($product);
$productCategory->setCategory($category);
$productCategory->setEnabled(true);
$productCategory->setMain($main);
$product->addProductCategory($productCategory);
$this->save($productCategory);
}