public function action_create()
 {
     if (Input::method() == 'POST') {
         $val = Model_Customer::validate('create');
         if ($val->run()) {
             $customer = Model_Customer::forge(array('name' => Input::post('name'), 'email' => Input::post('email'), 'phone' => Input::post('phone'), 'address' => Input::post('address'), 'website' => Input::post('website')));
             if ($customer and $customer->save()) {
                 Session::set_flash('success', e('Added customer #' . $customer->id . '.'));
                 Response::redirect('admin/customers');
             } else {
                 Session::set_flash('error', e('Could not save customer.'));
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $this->template->title = "Customers";
     $this->template->content = View::forge('admin/customers/create');
 }
Example #2
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;
 }