/** * Saves the address to the database. * * @param \MusicBox\Entity\Like $address */ public function save($address) { $addressData = array('user_id' => $address->getUserId(), 'street' => $address->getStreet(), 'street2' => $address->getStreet2(), 'city' => $address->getCity(), 'state' => $address->getState(), 'zip' => $address->getZip(), 'billing' => $address->getType()); if ($address->getId()) { try { $this->db->update('addresses', $addressData, array('address_id' => $address->getId())); } catch (\Exception $e) { return false; } } else { // The address is new, note the creation timestamp. try { $this->db->insert('addresses', $addressData); // Get the id of the newly created address and set it on the entity. $id = $this->db->lastInsertId(); $address->setAddressId($id); } catch (\Exception $e) { dump($e); exit; return false; } } }