Example #1
0
 /**
  * Saves an item into the database.
  *
  * @param \AmazonE\Domain\Item $item The item to save
  */
 public function save(Item $item)
 {
     $itemData = array('it_name' => $item->getName(), 'it_description' => $item->getDescription(), 'it_price' => $item->getPrice(), 'it_image' => $item->getImage(), 'subcat_id' => $item->getSubCategory()->getId());
     if ($item->getId()) {
         // The item has already been saved : update it
         $this->getDb()->update('t_items', $itemData, array('it_id' => $item->getId()));
     } else {
         // The item has never been saved : insert it
         $this->getDb()->insert('t_items', $itemData);
         // Get the id of the newly created item and set it on the entity.
         $id = $this->getDb()->lastInsertId();
         $item->setId($id);
     }
 }