/** * @param integer $productId */ public function addLog($productId) { $cartLog = new CartLog(); $cartLog->setSelectionDatetime(new \DateTime()); $cartLog->setProduct($this->productRepository->find($productId)); $this->entityManager->persist($cartLog); $this->entityManager->flush(); }