/** * Persist product (Add or update) * * @param Product $product * @param $tags * @return Product */ private function persistProduct(Product $product, $tags) { $tags = $this->tagManager->splitTagNames($tags); foreach ($tags as $tag) { $singleTag = $this->tagManager->loadOrCreateTag(trim($tag)); $this->tagManager->addTag($singleTag, $product); } $this->entityManager->persist($product); $this->entityManager->flush(); $this->tagManager->saveTagging($product); return $product; }