Ejemplo n.º 1
0
 public function create()
 {
     Order::createOrder();
     Customer::updateNotes();
     OrderDetail::createOrderDetail();
     Cart::deleteCartAfterCheckout();
     parent::redirectTo('indexHome');
 }
 public function updateAction()
 {
     $input = $this->_params;
     unset($input['controller']);
     unset($input['action']);
     $transaction = \models\Customer::find($input['id']);
     foreach ($input as $key => $value) {
         $transaction->{$key} = $value;
     }
     $transaction->updated_at = date("Y-m-d H:i:s");
     if ($transaction->update()) {
         $verify = new system\library\Verify("", "", "", $input);
         //return $customer; //success
     } else {
         throw new \Exception("Transaction could not be updated");
         //return "error"; //unsuccessful
     }
 }
Ejemplo n.º 3
0
 public function flashAny($init, $id = null)
 {
     $req = $this->app->request();
     self::$errors = array();
     $idData = explode('/', $_SERVER['REQUEST_URI']);
     $idAny = end($idData);
     if (filter_var($idAny, FILTER_VALIDATE_INT) === false) {
         if (Customer::countCustomer($req->post('email'))->fetchColumn() == 1) {
             self::$errors[] = 'That email already exists.';
         }
     }
     if (count(self::$errors) > 0) {
         $this->app->flash('errors', self::$errors);
         $this->app->flash('tmpAddress', $req->post('address'));
         $this->app->flash('tmpEmail', $req->post('email'));
         $this->app->flash('tmpName', $req->post('name'));
         $this->app->flash('tmpNotes', $req->post('notes'));
         $this->app->flash('tmpPhone', $req->post('phone'));
         if ($init == 'add') {
             parent::redirectTo('addCustomer');
         } elseif ($init == 'adminAdd') {
             parent::redirectTo('adminAddCustomer');
         } else {
             self::$url = $this->app->urlFor('editCustomer', array('id' => $id));
             $this->app->redirect(self::$url);
         }
     }
 }
Ejemplo n.º 4
0
 public function store()
 {
     if (empty($_SESSION)) {
         session_start();
     }
     empty($_SESSION['old']) ?: ($_SESSION['old'] = []);
     empty($_SESSION['error']) ?: ($_SESSION['error'] = []);
     $rules = ['email' => FILTER_VALIDATE_EMAIL, 'number' => ['filter' => FILTER_CALLBACK, 'options' => function ($nb) {
         if (preg_match('/[0-9]{16}/', $nb)) {
             return (int) $nb;
         }
         return false;
     }], 'address' => FILTER_SANITIZE_STRING];
     $sanitize = filter_input_array(INPUT_POST, $rules);
     var_dump($sanitize);
     $error = false;
     if (!$sanitize['email']) {
         $error = true;
         $_SESSION['error']['email'] = "Email Invalid";
     }
     if (!$sanitize['number']) {
         $error = true;
         $_SESSION['error']['number'] = "Blue Card number Invalid";
     }
     if (!$sanitize['address']) {
         $error = true;
         $_SESSION['error']['address'] = "You must give your address";
     }
     if ($error) {
         $_SESSION['old']['email'] = $sanitize['email'];
         $_SESSION['old']['address'] = $sanitize['address'];
         $this->redirect(url('cart'));
     }
     try {
         \Connect::$pdo->beginTransaction();
         $history = new History();
         $customer = new Customer();
         $customer->create(['email' => $sanitize['email'], 'number' => $sanitize['number'], 'addess' => $sanitize['address']]);
         $customerId = \Connect::$pdo->LastInsertID;
         $storage = $this->cart->all();
         $products = [];
         foreach ($storage as $id => $total) {
             $p = new Product();
             $stmt = $p->find($id);
             $history->create(['product_id' => $id, 'price' => (double) $stmt->price, 'total' => $total, 'quantity' => $total / $stmt->price, 'commandet_at' => date('Y-m-d h:i:s')]);
             $this->cart->reset();
             $this->redirect(url());
         }
         \Connect::$pdo->commit();
     } catch (\PDOException $e) {
         \Connect::$pdo->rollback();
     }
 }
Ejemplo n.º 5
0
 public function store()
 {
     $this->validToken('_token');
     if (empty($_SESSION)) {
         session_start();
     }
     empty($_SESSION['old']) ?: ($_SESSION['old'] = []);
     empty($_SESSION['error']) ?: ($_SESSION['error'] = []);
     $rules = ['email' => FILTER_VALIDATE_EMAIL, 'number' => ['filter' => FILTER_CALLBACK, 'options' => function ($nb) {
         if (iconv_strlen($nb) == 16 && (int) $nb != 0) {
             return (int) $nb;
         }
         return false;
     }], 'address' => FILTER_SANITIZE_STRING];
     $sanitize = filter_input_array(INPUT_POST, $rules);
     $error = false;
     $_SESSION['old']['email'] = $sanitize['email'];
     $_SESSION['old']['address'] = $sanitize['address'];
     if (!$sanitize['email']) {
         $_SESSION['error']['email'] = 'your email is invalid';
         $error = true;
     }
     if (!$sanitize['number']) {
         $_SESSION['error']['number'] = 'your number blue card is invalid';
         $error = true;
     }
     if (!$sanitize['address']) {
         $_SESSION['error']['address'] = 'you must given your address';
         $error = true;
     }
     if ($error) {
         $_SESSION['flashMessage'] = 'there was a problem';
         $this->redirect(url('cart'));
     }
     try {
         \Connect::$pdo->beginTransaction();
         $history = new History();
         $customer = new Customer();
         if ($c = $customer->where('number_card', '=', (string) $sanitize['number'])->get()->fetch()) {
             $customer->update($c->id, ['number_command' => 'number_command+1']);
             $customerId = $c->id;
         } else {
             $customer->create(['email' => $sanitize['email'], 'number_card' => $sanitize['number'], 'address' => $sanitize['address'], 'number_command' => 1]);
             $customerId = \Connect::$pdo->lastInsertId();
         }
         $products = $this->storage();
         foreach ($products as $name => $p) {
             $p['commanded_at'] = date('Y-m-d h:i:s');
             $p['customer_id'] = $customerId;
             $history->create($p);
         }
         \Connect::$pdo->commit();
         $_SESSION['flashMessage'] = 'thank you for your purchase, the team of Star Wars';
         $this->cart->reset();
         $this->redirect(url());
     } catch (\PDOException $e) {
         \Connect::$pdo->rollBack();
         $_SESSION['flashMessage'] = 'there has been a problem for your order, so sorry';
         $this->redirect(url('cart'));
     }
 }
Ejemplo n.º 6
0
 public function store()
 {
     if (!checked_token($_POST['_token'])) {
         $this->redirect(url('cart'));
     }
     //if(empty($_SESSION)) session_start();
     if (!empty($_SESSION['old'])) {
         $_SESSION['old'] = [];
     }
     if (!empty($_SESSION['error'])) {
         $_SESSION['error'] = [];
     }
     $rules = ['email' => FILTER_VALIDATE_EMAIL, 'number' => ['filter' => FILTER_CALLBACK, 'options' => function ($nb) {
         if (preg_match('/[0-9]{16}/', $nb)) {
             return $nb;
         }
         return false;
     }], 'adresse' => FILTER_SANITIZE_STRING];
     $sanitize = filter_input_array(INPUT_POST, $rules);
     //var_dump($sanitize);
     $error = false;
     if (!$sanitize['email']) {
         $error = true;
         $_SESSION['error']['email'] = 'your email is invalid';
     }
     if (!$sanitize['number']) {
         $error = true;
         $_SESSION['error']['number'] = 'your blue card number is invalid';
     }
     if (!empty($sanitize['adresse'])) {
         $error = true;
         $_SESSION['error']['adresse'] = 'you must give your address';
     }
     if ($error) {
         $_SESSION['old']['email'] = $sanitize['email'];
         $_SESSION['old']['adresse'] = $sanitize['adresse'];
         $this->redirect(url('cart'));
     }
     //transactionnelle PDO
     try {
         \Connect::$pdo->beginTransaction();
         $history = new History();
         $customer = new Customer();
         $customer->create(['email' => $sanitize['email'], 'number' => $sanitize['number'], 'adresse' => $sanitize['adresse']]);
         $customer_id = \Connect::$pdo->lastInsertId();
         $storage = $this->cart->all();
         foreach ($storage as $id => $total) {
             $p = new Product();
             // product du Model pas du Cart
             $stmt = $p->find($id);
             $history->create(['product_id' => $id, 'customer_id' => $customer_id, 'price' => (double) $stmt->price, 'total' => $total, 'quantity' => $total / $stmt->price, 'commanded_at' => date('Y-m-d h:i:s')]);
         }
         \Connect::$pdo->commit();
         $this->cart->reset();
         $this->redirect(url());
     } catch (\PDOException $e) {
         \Connect::$pdo->rollBack();
     }
 }
Ejemplo n.º 7
0
 public function indexAction()
 {
     $customer = new Customer();
     View::render('home/index', ['users' => (array) $customer->getCustomer(144), 'params' => $this->getUrlQueries()]);
 }