Small cart quantity fixes
parent
abc5de8ff6
commit
c674f86576
|
@ -2,3 +2,4 @@ node_modules/
|
||||||
data/
|
data/
|
||||||
config/settings.json
|
config/settings.json
|
||||||
.vscode
|
.vscode
|
||||||
|
**.DS_Store
|
6
app.js
6
app.js
|
@ -249,6 +249,12 @@ app.use((req, res, next) => {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Ran on all routes
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
res.setHeader('Cache-Control', 'no-cache, no-store');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
// setup the routes
|
// setup the routes
|
||||||
app.use('/', index);
|
app.use('/', index);
|
||||||
app.use('/', customer);
|
app.use('/', customer);
|
||||||
|
|
|
@ -142,6 +142,10 @@ $(document).ready(function (){
|
||||||
cartUpdate(qtyElement);
|
cartUpdate(qtyElement);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).on('click', '.btn-delete-from-cart', function(e){
|
||||||
|
deleteFromCart($(e.target));
|
||||||
|
});
|
||||||
|
|
||||||
$(document).on('click', '.orderFilterByStatus', function(e){
|
$(document).on('click', '.orderFilterByStatus', function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
window.location = '/admin/orders/bystatus/' + $('#orderStatusFilter').val();
|
window.location = '/admin/orders/bystatus/' + $('#orderStatusFilter').val();
|
||||||
|
@ -457,6 +461,10 @@ $(document).ready(function (){
|
||||||
$(document).on('click', '.product-add-to-cart', function(e){
|
$(document).on('click', '.product-add-to-cart', function(e){
|
||||||
var productOptions = getSelectedOptions();
|
var productOptions = getSelectedOptions();
|
||||||
|
|
||||||
|
if(parseInt($('#product_quantity').val()) < 0){
|
||||||
|
$('#product_quantity').val(0);
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/product/addtocart',
|
url: '/product/addtocart',
|
||||||
|
@ -682,12 +690,12 @@ function slugify(str){
|
||||||
}
|
}
|
||||||
|
|
||||||
function cartUpdate(element){
|
function cartUpdate(element){
|
||||||
if($(element).val() < 1){
|
if($(element).val() > 0){
|
||||||
deleteFromCart($(element));
|
|
||||||
}else{
|
|
||||||
if($(element).val() !== ''){
|
if($(element).val() !== ''){
|
||||||
updateCart();
|
updateCart();
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
$(element).val(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,11 +708,7 @@ function updateCart(){
|
||||||
itemQuantity: $(this).val(),
|
itemQuantity: $(this).val(),
|
||||||
productId: $(this).attr('data-id')
|
productId: $(this).attr('data-id')
|
||||||
};
|
};
|
||||||
if($(this).val() < 0){
|
|
||||||
deleteFromCart($(this));
|
|
||||||
}else{
|
|
||||||
cartItems.push(item);
|
cartItems.push(item);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// update cart on server
|
// update cart on server
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -219,6 +219,11 @@ router.post('/product/addtocart', (req, res, next) => {
|
||||||
const db = req.app.db;
|
const db = req.app.db;
|
||||||
let productQuantity = req.body.productQuantity ? parseInt(req.body.productQuantity) : 1;
|
let productQuantity = req.body.productQuantity ? parseInt(req.body.productQuantity) : 1;
|
||||||
|
|
||||||
|
// Don't allow negative quantity
|
||||||
|
if(productQuantity < 0){
|
||||||
|
productQuantity = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// setup cart object if it doesn't exist
|
// setup cart object if it doesn't exist
|
||||||
if(!req.session.cart){
|
if(!req.session.cart){
|
||||||
req.session.cart = [];
|
req.session.cart = [];
|
||||||
|
|
|
@ -39,6 +39,9 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<span class="pull-right">
|
||||||
|
<button class="btn btn-sm btn-danger btn-delete-from-cart" data-id="{{this.productId}}" type="button"><i class="fa fa-trash" data-id="{{this.productId}}" aria-hidden="true"></i></button>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -25,17 +25,19 @@
|
||||||
{{#each this.options}} {{#if @last}} {{this}} {{else}} {{this}} / {{/if}} {{/each}}
|
{{#each this.options}} {{#if @last}} {{this}} {{else}} {{this}} / {{/if}} {{/each}}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
<div class="col s12 no-pad-left">
|
<div class="col s12 no-pad-left">
|
||||||
<span class="col s2">
|
<span class="col s2">
|
||||||
<button class="btn waves-effect waves-light blue darken-3 btn-qty-minus" type="button">-</button>
|
<button class="btn waves-effect waves-light blue darken-3 btn-qty-minus" type="button">-</button>
|
||||||
</span>
|
</span>
|
||||||
<div class="input-field col s8">
|
<div class="input-field col s5">
|
||||||
<input type="number" class="cart-product-quantity text-center" data-id="{{this.productId}}" id="{{@key}}" maxlength="2" value="{{this.quantity}}">
|
<input type="number" class="cart-product-quantity text-center" data-id="{{this.productId}}" id="{{@key}}" maxlength="2" value="{{this.quantity}}">
|
||||||
</div>
|
</div>
|
||||||
<span class="col s2">
|
<span class="col s3">
|
||||||
<button class="btn waves-effect waves-light blue darken-3 btn-qty-add" type="button">+</button>
|
<button class="btn waves-effect waves-light blue darken-3 btn-qty-add" type="button">+</button>
|
||||||
</span>
|
</span>
|
||||||
|
<span class="col s1">
|
||||||
|
<button class="btn waves-effect waves-light red darken-3 btn-delete-from-cart" data-id="{{this.productId}}" type="button"><i class="fa fa-trash" data-id="{{this.productId}}" aria-hidden="true"></i></button>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -25,17 +25,19 @@
|
||||||
{{#each this.options}} {{#if @last}} {{this}} {{else}} {{this}} / {{/if}} {{/each}}
|
{{#each this.options}} {{#if @last}} {{this}} {{else}} {{this}} / {{/if}} {{/each}}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
<div class="col s12 no-pad-left">
|
<div class="col s12 no-pad-left">
|
||||||
<span class="col s2">
|
<span class="col s2">
|
||||||
<button class="btn waves-effect waves-light black btn-qty-minus" type="button">-</button>
|
<button class="btn waves-effect waves-light black btn-qty-minus" type="button">-</button>
|
||||||
</span>
|
</span>
|
||||||
<div class="input-field col s8">
|
<div class="input-field col s5">
|
||||||
<input type="number" class="cart-product-quantity text-center" data-id="{{this.productId}}" id="{{@key}}" maxlength="2" value="{{this.quantity}}">
|
<input type="number" class="cart-product-quantity text-center" data-id="{{this.productId}}" id="{{@key}}" maxlength="2" value="{{this.quantity}}">
|
||||||
</div>
|
</div>
|
||||||
<span class="col s2">
|
<span class="col s3">
|
||||||
<button class="btn waves-effect waves-light black btn-qty-add" type="button">+</button>
|
<button class="btn waves-effect waves-light black btn-qty-add" type="button">+</button>
|
||||||
</span>
|
</span>
|
||||||
|
<span class="col s1">
|
||||||
|
<button class="btn waves-effect waves-light red darken-3 btn-delete-from-cart" data-id="{{this.productId}}" type="button"><i class="fa fa-trash" data-id="{{this.productId}}" aria-hidden="true"></i></button>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue