예제 #1
0
 public function save(Gyuser_Model_Address $obj)
 {
     $data = array('client_id' => $obj->getClient_id(), 'street' => $obj->getStreet(), 'city' => $obj->getCity(), 'state' => $obj->getState(), 'country' => $obj->getCountry(), 'delivery_address' => $obj->getDelivery_address(), 'address_type' => $obj->getAddress_type(), 'zip_code' => $obj->getZip_code());
     $id = $obj->getId();
     $client_id = $obj->getClient_id();
     if ($id === null) {
         unset($data['id']);
         $id = $this->getDbTable()->insert($data);
     } else {
         unset($data['client_id']);
         //unset($data['delivery_address']);
         $this->getDbTable()->update($data, array('id = ?' => $id));
     }
     //if its default delivery address, update the rest
     //of the address not to be default delivery addresses
     if ($obj->getDelivery_address()) {
         $data = array('delivery_address' => 0);
         $id = $this->getDbTable()->update($data, array('id != ?' => $id, 'client_id = ?' => $client_id));
     }
     return $id;
 }