-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecommended.php
47 lines (45 loc) · 1.94 KB
/
recommended.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require __DIR__ . '/vendor/autoload.php';
$mongoClient = (new MongoDB\Client);
$db = $mongoClient->perfumefest;
$search_string = filter_input(INPUT_POST, 'topKeyword', FILTER_SANITIZE_STRING);
// checking if no keywords was stored then will echo back default recommended items
// of the current season
if ($search_string == "") {
$findCriteria = [
'$text' => ['$search' => "valentine"]
];
$cursor = $db->Products->find($findCriteria, ['limit' => 4]);
echo ' <p>Recommended</p>';
echo ' <div id="suggesteds">';
foreach ($cursor as $product) {
echo ' <div class="perfume-data">';
echo ' <div class="item-picture"><img class="item-img" src="./' . $product['img_url'] . '" alt=""></div>';
echo ' <div class="item-name">' . $product['Name'] . '</div>';
echo ' <div class="item-size">' . $product['size'] . '</div>';
echo ' <div class="item-price">£' . $product['Price'] . '</div>';
echo ' <button class="addbtn" >Add to Cart</button>
</div>';
}
echo ' </div>';
// perfomring an indexed search on the top keyword searched by user
} else {
$findCriteria = [
'$text' => ['$search' => $search_string]
];
//Find only 4 products that has search criteria
$cursor = $db->Products->find($findCriteria, ['limit' => 4]);
// echoing back all items in a grid
echo ' <p>Recommended</p>';
echo ' <div id="suggesteds">';
foreach ($cursor as $product) {
echo ' <div class="perfume-data">';
echo ' <div class="item-picture"><img class="item-img" src="./' . $product['img_url'] . '" alt=""></div>';
echo ' <div class="item-name">' . $product['Name'] . '</div>';
echo ' <div class="item-size">' . $product['size'] . '</div>';
echo ' <div class="item-price">£' . $product['Price'] . '</div>';
echo ' <button class="addbtn" >Add to Cart</button>
</div>';
}
echo ' </div>';
}