mirror of
https://github.com/DerTyp7/shop-ejs-expressjs.git
synced 2025-10-28 20:12:11 +01:00
product.ejs fix, seller filter
This commit is contained in:
19
index.js
19
index.js
@@ -162,7 +162,7 @@ app.get("/account", authenticatedHandler, (req, res) => {
|
||||
app.get("/product/:productId", authNoRedirectHandler, (req, res) => {
|
||||
let productId = req.params.productId;
|
||||
|
||||
mysql_handler.con.query(`SELECT s.name AS sellerName, p.name AS productName, p.description AS productDescription, p.id AS id, price,quantity, delivery_time, p.categoryId
|
||||
mysql_handler.con.query(`SELECT s.name AS sellerName, p.name AS productName, p.description AS productDescription, p.id AS id, price,quantity, delivery_time
|
||||
FROM products AS p LEFT JOIN sellers AS s ON p.sellerId= s.id WHERE p.id=${productId}` , function(err, result){
|
||||
if(err) throw err;
|
||||
|
||||
@@ -172,7 +172,7 @@ app.get("/product/:productId", authNoRedirectHandler, (req, res) => {
|
||||
if(err) throw err;
|
||||
let reviews = JSON.parse(JSON.stringify(result));
|
||||
console.log(product)
|
||||
mysql_handler.con.query(`SELECT * FROM categories WHERE id IN (SELECT category_id FROM product_categories WHERE product_id = ${product.categoryId})`,function(err,result){
|
||||
mysql_handler.con.query(`SELECT * FROM categories WHERE id IN (SELECT category_id FROM product_categories WHERE product_id = ${product.id})`,function(err,result){
|
||||
if(err) throw err;
|
||||
let categories = JSON.parse(JSON.stringify(result));
|
||||
|
||||
@@ -217,7 +217,8 @@ app.get("/search/:query/",authNoRedirectHandler,(req, res) => {
|
||||
search: query,
|
||||
user: req.user,
|
||||
sort: req.query.sort ? req.query.sort : 0,
|
||||
Cat: req.query.cat ? req.query.cat : 0
|
||||
Cat: req.query.cat ? req.query.cat : 0,
|
||||
Brand: req.query.brand ? req.query.brand : 0
|
||||
}
|
||||
|
||||
mysql_handler.con.query("SELECT * FROM categories;",function(err, result) {
|
||||
@@ -225,12 +226,22 @@ app.get("/search/:query/",authNoRedirectHandler,(req, res) => {
|
||||
|
||||
dict.categories = JSON.parse(JSON.stringify(result));
|
||||
});
|
||||
mysql_handler.con.query("SELECT * FROM sellers;",function(err, result) {
|
||||
if(err) throw err;
|
||||
|
||||
dict.brands = JSON.parse(JSON.stringify(result));
|
||||
});
|
||||
|
||||
var catQuery = "";
|
||||
var cat = req.query.cat;
|
||||
if (typeof cat !== 'undefined' && cat != 0) {
|
||||
catQuery = " AND (SELECT COUNT(*) FROM product_categories c WHERE c.category_id = "+cat+" AND c.product_id = p.id)";
|
||||
}
|
||||
var brandQuery = "";
|
||||
var brand = req.query.brand;
|
||||
if (typeof brand !== 'undefined' && brand != 0) {
|
||||
brandQuery = " AND p.sellerid = "+brand;
|
||||
}
|
||||
|
||||
var sortQuery = "";
|
||||
var sort = req.query.sort;
|
||||
@@ -248,7 +259,7 @@ app.get("/search/:query/",authNoRedirectHandler,(req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
mysql_handler.con.query("SELECT *, (SELECT url FROM product_images i WHERE i.product_id = p.id LIMIT 1) as img, (SELECT AVG(rating) FROM reviews r WHERE r.productId = p.id) as rating FROM products p WHERE name LIKE ? "+catQuery+" "+sortQuery+";",["%"+query+"%"],function(err, result){
|
||||
mysql_handler.con.query("SELECT *, (SELECT url FROM product_images i WHERE i.product_id = p.id LIMIT 1) as img, (SELECT AVG(rating) FROM reviews r WHERE r.productId = p.id) as rating FROM products p WHERE name LIKE ? "+catQuery+" "+brandQuery+" "+sortQuery+";",["%"+query+"%"],function(err, result){
|
||||
if(err) throw err;
|
||||
|
||||
dict.products = JSON.parse(JSON.stringify(result));
|
||||
|
||||
@@ -13,7 +13,14 @@
|
||||
<option value="0">Kategorie: Alle</option>
|
||||
<% for(var i=0; i < categories.length; i++) { var cat = categories[i]; %>
|
||||
<option <%=Cat == cat.id ? "selected" : ""%> value="<%=cat.id%>">Kategorie: <%=cat.name %></option>
|
||||
<% } console.log(sort) %>
|
||||
<% } %>
|
||||
</select>
|
||||
|
||||
<select id="brand-select" class="center" onchange="updateFilters();">
|
||||
<option value="0">Hersteller: Alle</option>
|
||||
<% for(var i=0; i < brands.length; i++) { var brand = brands[i]; %>
|
||||
<option <%=Brand == brand.id ? "selected" : ""%> value="<%=brand.id%>">Hersteller: <%=brand.name %></option>
|
||||
<% } %>
|
||||
</select>
|
||||
|
||||
<select id="sort-select" class="right" onchange="updateFilters();">
|
||||
@@ -85,8 +92,9 @@
|
||||
<script type="text/javascript">
|
||||
var cat = document.getElementById("cat-select");
|
||||
var sort = document.getElementById("sort-select");
|
||||
var brand = document.getElementById("brand-select");
|
||||
function updateFilters() {
|
||||
window.open('/search/<%=search %>/?cat='+cat.value+'&sort='+sort.value,'_self')
|
||||
window.open('/search/<%=search %>/?cat='+cat.value+'&sort='+sort.value+'&brand='+brand.value,'_self')
|
||||
}
|
||||
|
||||
function openProduct(id, newWindow) {
|
||||
@@ -102,17 +110,6 @@
|
||||
flex-direction:unset !important;
|
||||
}
|
||||
|
||||
/* SEARCH INFO */
|
||||
.productsResInfDIV {
|
||||
position: relative;
|
||||
left: calc(10% + 10px);
|
||||
width: calc(80% - 20px);
|
||||
margin-top: 10px;
|
||||
}
|
||||
.noProductsH {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* PRODUCT COLUMN */
|
||||
.productDIV {
|
||||
font-size: 16px;
|
||||
@@ -187,16 +184,35 @@
|
||||
/* FILTERS */
|
||||
.filtersDIV {
|
||||
margin-top: 20px;
|
||||
position: relative;
|
||||
position: absolute;
|
||||
left: calc(10% + 10px);
|
||||
width: calc(80% - 20px);
|
||||
height: 30px;
|
||||
}
|
||||
.filtersDIV > .right {
|
||||
float: right;
|
||||
.filtersDIV > select {
|
||||
position: absolute;
|
||||
}
|
||||
.filtersDIV > .left{
|
||||
float: left;
|
||||
.filtersDIV > .right {
|
||||
right: 0;
|
||||
}
|
||||
.filtersDIV > .center {
|
||||
transform: translateX(-49%);
|
||||
left: 50%;
|
||||
}
|
||||
.filtersDIV > .left {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
/* SEARCH INFO */
|
||||
.productsResInfDIV {
|
||||
position: relative;
|
||||
left: calc(10% + 10px);
|
||||
width: calc(80% - 20px);
|
||||
margin-top: 50px;
|
||||
}
|
||||
.noProductsH {
|
||||
margin-top: 50px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* PRODUCTS GRID */
|
||||
|
||||
Reference in New Issue
Block a user