Exemple #1
0
 /**
  * Creates a seller contact.
  *
  * @param int $seller_id Seller ID.
  *
  * @return void
  */
 public function post_index($seller_id = null)
 {
     $validator = \Validation_Contact::create('seller');
     if (!$validator->run()) {
         throw new HttpBadRequestException($validator->errors());
     }
     $data = $validator->validated();
     $contact = \Service_Contact::create($data);
     if (!$contact) {
         throw new HttpServerErrorException();
     }
     if (!\Service_Contact::link($contact, \Seller::active(), \Arr::get($data, 'primary', false))) {
         throw new HttpServerErrorException();
     }
     $this->response($contact);
 }
Exemple #2
0
 /**
  * POST create action.
  * 
  * @return void
  */
 public function post_create()
 {
     $this->get_create();
     $contact = new Model_Contact();
     $contact->populate(Input::post());
     $validator = Validation_Contact::create('seller');
     if (!$validator->run()) {
         Session::set_alert('error', __('form.error'));
         $this->view->errors = $validator->error();
         return;
     }
     $data = $validator->validated();
     $data['first_name'] = '';
     $data['last_name'] = '';
     if (!($new_contact = Service_Contact::create($data))) {
         Session::set_alert('error', 'There was an error creating the contact.');
         return;
     }
     Service_Contact::link($new_contact, Seller::active());
     Session::set_alert('success', 'The contact has been created.');
     Response::redirect('settings/contacts');
 }