예제 #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);
 }
예제 #2
0
 /**
  * Creates a new seller.
  *
  * @param string $name The name of the seller.
  * @param array  $data Optional data.
  *
  * @return Model_Seller
  */
 public static function create($name, array $data = array())
 {
     if (!($contact_data = Arr::get($data, 'contact'))) {
         return false;
     }
     $seller = Model_Seller::forge();
     $seller->name = $name;
     $seller->populate($data);
     try {
         $seller->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     $contact = Service_Contact::create($contact_data);
     if (!$contact || !Service_Contact::link($contact, $seller, true)) {
         return false;
     }
     return $seller;
 }
예제 #3
0
 /**
  * Creates a new customer.
  *
  * @param Model_Seller  $seller The seller the customer belongs to.
  * @param array         $data   Optional data.
  *
  * @return Model_Customer
  */
 public static function create(Model_Seller $seller, array $data = array())
 {
     if (!($contact_data = Arr::get($data, 'contact'))) {
         return false;
     }
     $customer = Model_Customer::forge();
     $customer->seller = $seller;
     $customer->populate($data);
     try {
         $customer->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     $contact = Service_Contact::create($contact_data);
     if (!$contact || !Service_Contact::link($contact, $customer, true)) {
         return false;
     }
     Service_Event::trigger('customer.create', $customer->seller, $customer->to_array());
     return $customer;
 }
예제 #4
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');
 }