public static function search($db, $search_string, $pagination, $records_per_page) { $all_words = preg_match('#^(\'|").+\\1$#', $search_string) == 1 ? true : false; $search_result = array('accepted_words' => array(), 'ignored_words' => array(), 'all_words' => $all_words, 'query' => $search_string, 'products' => array()); if (empty($search_string)) { return $search_result; } $delimiters = ',.; '; $word = strtok($search_string, $delimiters); while ($word) { if (strlen($word) < FT_MIN_WORD_LEN) { $search_result['ignored_words'][] = $word; } else { $search_result['accepted_words'][] = $word; } $word = strtok($delimiters); } if (count($search_result['accepted_words']) == 0) { return $search_result; } $words = ''; if ($all_words) { $words = implode(' +', $search_result['accepted_words']); } else { $words = implode(' ', $search_result['accepted_words']); } $search_result['products'] = \Data\ProductsRepository::search($db, $words, $all_words, $pagination, $records_per_page); return $search_result; }
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)); } }
</table> <input type="submit" value="Update Quantities"> <a href="<?php echo $this->url('/'); ?> "><input type="button" value="Continue Shopping"></a> <a href="<?php echo $this->url('/shop/wishlist?action=clear'); ?> "><input type="button" value="Clear"></a> </div><!--end:alltotal--> </div><!--end:contentbox--> </form> <?php $recommended_products = \Data\ProductsRepository::get_recommended_products($db, $wish_list['ids']); ?> <?php if (isset($recommended_products) && count($recommended_products)) { ?> <div class="relatedprod"> <h4>Customers who bought this also bought:</h4> <?php foreach ($recommended_products as $rp) { ?> <div class="entry"> <div class="da-thumbs"> <div class="div-related"> <img src="<?php echo $this->uploads_small($rp['image']); ?>
} if (isset($data['product_id']) && filter_var($data['product_id'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $message = strip_tags($data['message']); $result = \Data\ProductsRepository::review_product($db, $data['product_id'], $data['rating'], $message, $data['name'], $data['email']); if ($result) { $app->flash('info', 'Your review has been added. Thank you for reviewing our products.'); $app->redirect($app->view()->url('/products/' . $data['category'] . '/' . $data['product_id'] . '#review-form')); } else { $app->error(new \Exception('Your review could not be processed due to a system error. We apologize for the inconvenience.')); } } }); $app->post('/products/load_more', function () use($app, $db) { $data = $app->request()->post(); if (isset($data['page'], $data['id'])) { $page = $data['page']; $id = $data['id']; $reviews = \Data\ProductsRepository::get_review($db, $id, $page); if ($reviews) { foreach ($reviews as $review) { echo '<div class="feedback">'; echo '<div>'; echo '<h4>' . $review['reviewer_name'] . '</h4>'; echo '<span>' . $review['review_date'] . '</span>'; echo '<p>' . $review['review'] . '</p>'; echo '</div>'; echo '</div>'; } } } });
<?php $app->get('/', function () use($app, $db) { $random_products = \Data\ProductsRepository::get_random_products($db); $new_arrival = \Data\ProductsRepository::get_new_arrival($db); $app->render('home.php', array('page_title' => 'Home', 'random_products' => $random_products, 'new_arrival' => $new_arrival, 'current' => 'home')); }); $app->get('/home/about', function () use($app) { $app->render('home/about.php', array('page_title' => 'About Us', 'current' => 'about')); }); $app->get('/home/return', function () use($app) { $app->render('home/return.php', array('page_title' => 'Return Policy', 'current' => 'policies')); }); $app->get('/home/payment', function () use($app) { $app->render('home/payment.php', array('page_title' => 'Payment Policy', 'current' => 'policies')); }); $app->get('/home/shipping', function () use($app) { $app->render('home/shipping.php', array('page_title' => 'Shipping Policy', 'current' => 'policies')); }); $app->get('/home/privacy', function () use($app) { $app->render('home/privacy.php', array('page_title' => 'Privacy Policy', 'current' => 'policies')); }); $app->get('/home/contact', function () use($app) { $flash = $app->view()->getData('flash'); $errors = isset($flash['errors']) ? $flash['errors'] : array(); $app->render('home/contact.php', array('page_title' => 'Contact', 'errors' => $errors, 'current' => 'contact')); }); $app->post('/home/contact', function () use($app, $config) { include BASE_URI . DS . 'routes' . DS . 'validators' . DS . 'contact.php'; $data = $app->request()->post(); $errors = validate($data);
public static function get_kit_products($db, $id) { $query = ' SELECT p2.id, p2.name, p2.description, p2.image, p2.stock, p2.price, sales.price AS sale_price, ak.quantity as quantity, IF(DATEDIFF(NOW(), p2.created) < 30, true, false) as is_new, IF(pa.product_id IS NULL, 0, 1) AS has_attributes FROM products p1 INNER JOIN accessories_kits AS ak ON p1.id=ak.kit_id INNER JOIN products p2 ON ak.accessory_id = p2.id INNER JOIN sales ON (sales.product_id=p2.id AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL))) LEFT OUTER JOIN product_attribute pa ON p2.id = pa.product_id WHERE p1.id = :id GROUP BY p2.id UNION SELECT p2.id, p2.name, p2.description, p2.image, p2.stock, p2.price, sales.price AS sale_price, ek.quantity as quantity, IF(DATEDIFF(NOW(), p2.created) < 30, true, false) as is_new, IF(pa.product_id IS NULL, 0, 1) AS has_attributes FROM products p1 INNER JOIN eliquids_kits AS ek ON p1.id=ek.kit_id INNER JOIN products p2 ON ek.eliquid_id = p2.id INNER JOIN sales ON (sales.product_id=p2.id AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL))) LEFT OUTER JOIN product_attribute pa ON p2.id = pa.product_id WHERE p1.id = :id GROUP BY p2.id '; $stmt = $db->prepare($query); $stmt->execute(array('id' => $id)); $products = $stmt->fetchAll(); if ($products) { foreach ($products as &$p) { if ($p['has_attributes'] == 1) { $p['attributes'] = \Data\ProductsRepository::get_product_attributes($db, $p['id']); } else { $p['attributes'] = null; } } } return $products; }
<?php $best_sellers = \Data\ProductsRepository::get_best_sellers($db); ?> <aside class="sidebar"> <div class="side"> <h4>Bestsellers</h4> <?php if (isset($best_sellers) && count($best_sellers)) { ?> <?php foreach ($best_sellers as $b) { ?> <div class="entry"> <div class="da-thumbs"> <div class="div-bestsellers"> <img src="<?php echo $this->uploads_thumb($b['image']); ?> " alt=""> <article class="da-animate da-slideFromRight" style="display: block;"> <p><a href="<?php echo $this->url('/products/' . $b['cname'] . '/' . $b['id']); ?> " class="link"></a></p> </article> </div> </div> <h3><a href="<?php echo $this->url('/products/' . $b['cname'] . '/' . $b['id']);