function add_to_wish_list($app, $db, $params) { if (isset($params['id'], $params['attributes'])) { $pid = filter_var($params['id'], FILTER_VALIDATE_INT, array('min_range' => 1)) ? $params['id'] : NULL; if (empty($params['attributes']) || $params['attributes'] === '0') { // product don't have attributes $attributes = NULL; } elseif ($params['attributes'] === '1') { // product needs attributes $app->flash('info', 'You need to choose the attributes of your product before adding it to your Wish List.'); $category = \Data\ProductsRepository::get_category($db, $pid); $app->redirect($app->view()->url('/products/' . $category . '/' . $pid)); } else { // actual attributes string $attributes = $params['attributes']; } } if (isset($pid, $params['action']) && $params['action'] == 'add') { $stmt = \Data\WishListRepository::add_to_wish_list($db, $_SESSION['user_id'], $pid, 1, $attributes); $app->flash('info', 'Your Wish List have been updated. A new product have been added.'); $app->redirect($app->view()->url('/shop/wishlist')); } elseif (isset($pid, $params['action']) && $params['action'] == 'remove') { $stmt = \Data\WishListRepository::remove_from_wish_list($db, $_SESSION['user_id'], $pid, $attributes); $app->flash('info', 'Your Wish List have been updated. The selected product have been removed.'); $app->redirect($app->view()->url('/shop/wishlist')); } elseif (isset($pid, $params['action'], $params['qty']) && $params['action'] == 'move') { $qty = filter_var($params['qty'], FILTER_VALIDATE_INT, array('min_range' => 1)) ? $params['qty'] : 1; $stmt = \Data\WishListRepository::remove_from_wish_list($db, $_SESSION['user_id'], $pid, $attributes); $stmt = \Data\CartRepository::add_to_cart($db, $_SESSION['user_id'], $pid, $qty, $attributes); $app->flash('info', 'Your Wish List have been updated. The product selected have been moved to your Cart.'); $app->redirect($app->view()->url('/shop/wishlist')); } elseif (isset($params['action']) && $params['action'] == 'clear') { $stmt = \Data\WishListRepository::clear_wish_list($db, $_SESSION['user_id']); $app->flash('info', 'Your Wish List have been updated. Your Wish List is now empty.'); $app->redirect($app->view()->url('/shop/wishlist')); } else { // show Wish List $wish_list_items = \Data\WishListRepository::get_wish_list_contents($db, $_SESSION['user_id']); $wish_list = NULL; if ($wish_list_items && count($wish_list_items)) { $wish_list = \Helpers\Util::parse_wish_list_items($wish_list_items); } $app->view()->set_template('layouts/basic.php'); $app->render('shop/wishlist.php', array('page_title' => 'Your WishList', 'wish_list' => $wish_list)); } }
public static function update_wish_list($db, $uid, $pid, $qty, $attributes) { if ($qty > 0) { if ($attributes == NULL) { $query = 'UPDATE wishlists SET quantity=:qty, date_modified=NOW() WHERE user_id=:uid AND product_id=:pid AND attributes IS NULL;'; } else { $query = 'UPDATE wishlists SET quantity=:qty, date_modified=NOW() WHERE user_id=:uid AND product_id=:pid AND attributes=:attributes;'; } $stmt = $db->prepare($query); if ($attributes == NULL) { $stmt->execute(array('uid' => $uid, 'pid' => $pid, 'qty' => $qty)); } else { $stmt->execute(array('uid' => $uid, 'pid' => $pid, 'qty' => $qty, 'attributes' => $attributes)); } return $stmt; } elseif ($qty == 0) { return \Data\WishListRepository::remove_from_wish_list($db, $uid, $pid, $attributes); } }
$app->view()->set_template('layouts/basic.php'); $app->render('session/login.php', array('page_title' => $app->view()->tr('pages.login'), 'errors' => $errors)); }); $app->post('/session/login', $require_ssl, function () use($app, $db) { include BASE_URI . DS . 'routes' . DS . 'validators' . DS . 'login.php'; $data = $app->request()->post(); $errors = validate($data); if ($errors) { $app->flash('error', $app->view()->tr('session.login.errors')); $app->redirect($app->view()->url_secure('/session/login')); } $user = \Data\UserRepository::get_user_by_email_and_password($db, $data['email'], $data['password']); if ($user) { \Data\CartRepository::clear_cart($db, $_SESSION['user_id']); // remove past items \Data\WishListRepository::clear_wish_list($db, $_SESSION['user_id']); // remove past items if ($user['type'] == 'admin') { session_regenerate_id(true); $_SESSION['admin'] = true; } $_SESSION['user_id'] = $user['id']; $_SESSION['username'] = $user['username']; $_SESSION['logged_in'] = true; $app->flash('info', 'Welcome to our store ' . $user['username'] . '. Enjoy!'); $app->redirect($app->view()->url('/')); } else { $app->flash('error', $app->view()->tr('session.login.match.error')); $app->redirect($app->view()->url_secure('/session/login')); } });