public function getId() { if ($this->__isInitialized__ === false) { return (int) $this->_identifier["id"]; } $this->__load(); return parent::getId(); }
/** * Compares this with another Product object * @param Product $other * @return boolean */ public function equals(Product $other) { return $this->getId() === $other->getId(); }
public function getId() { $this->_load(); return parent::getId(); }
/** * @param Product $product the product to update * @return boolean true on success * @throws NotFoundException if not found */ public function update($product) { $productId = $product->getId(); if ($productId === null || $productId === 0) { $this->logger->error(__METHOD__ . ": Can't update a non-existing product (id: {$productId})"); return false; } $repository = $this->getRepository(); if ($repository == null) { $this->logger->error(__METHOD__ . ": No repository, impossible to proceed."); return false; } /** @var Product $dbOne */ $dbOne = $repository->find($productId); if ($dbOne === null) { throw new NotFoundException("Product (id: {$productId}) was not found, impossible to update."); } $dbOne->setDescription($product->getDescription())->setName($product->getName())->setTags($product->getTags()); $em = $this->getEntityManager(); if ($em == null) { $this->logger->error(__METHOD__ . ": No entity manager, impossible to proceed."); return false; } try { $em->persist($dbOne); $em->flush(); return true; } catch (ORMInvalidArgumentException $ex) { $this->logger->error(__METHOD__ . ": (" . $ex->getCode() . ") " . $ex->getMessage()); return false; } }