public function saveItem($data) { $item = new Item_model(); $item->productCode = $data['productCode']; $item->description = $data['itemName']; $item->itemTypeId = $data['itemTypeId']; $item->categoryId = $data['categoryId']; $item->suggestedSellingPrice = $data['price']; $item->active = 1; $query = $this->db->get_where('Item', array('productCode' => $data['productCode'])); if ($query->num_rows() > 0) { throw new DuplicateRecordException('The product code ' . $data['productCode'] . ' already exists.'); } return $item->insert(); }