Fixes #129
parent
1b030dce27
commit
9079509c42
|
@ -662,8 +662,8 @@ function updateCartDiv(){
|
|||
// If the cart has contents
|
||||
if(cart){
|
||||
$('#cart-empty').empty();
|
||||
Object.keys(cart).forEach(function(productId){
|
||||
var item = cart[productId];
|
||||
Object.keys(cart).forEach(function(cartId){
|
||||
var item = cart[cartId];
|
||||
// Setup the product
|
||||
var productTotalAmount = numeral(item.totalItemPrice).format('0.00');
|
||||
var optionsHtml = '';
|
||||
|
@ -701,14 +701,21 @@ function updateCartDiv(){
|
|||
<div class="input-group-prepend">
|
||||
<button class="btn btn-primary btn-qty-minus" type="button">-</button>
|
||||
</div>
|
||||
<input type="number" class="form-control cart-product-quantity text-center" data-cartid="${productId}" data-id="${item.id}" maxlength="2" value="${item.quantity}">
|
||||
<input
|
||||
type="number"
|
||||
class="form-control cart-product-quantity text-center"
|
||||
data-cartid="${cartId}"
|
||||
data-id="${item.productId}"
|
||||
maxlength="2"
|
||||
value="${item.quantity}"
|
||||
>
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary btn-qty-add" type="button">+</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4 col-md-2 no-pad-left">
|
||||
<button class="btn btn-danger btn-delete-from-cart" data-cartid="${productId}" type="button"><i class="feather" data-feather="trash-2" data-cartid="${productId}"></i></button>
|
||||
<button class="btn btn-danger btn-delete-from-cart" data-cartid="${cartId}" type="button"><i class="feather" data-feather="trash-2" data-cartid="${cartId}"></i></button>
|
||||
</div>
|
||||
<div class="col-8 col-md-4 align-self-center text-right">
|
||||
<strong class="my-auto">${result.currencySymbol}${productTotalAmount}</strong>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -384,6 +384,12 @@ router.post('/product/updatecart', async (req, res, next) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const product = await db.products.findOne({ _id: getId(cartItem.productId) });
|
||||
if(!product){
|
||||
res.status(400).json({ message: 'There was an error updating the cart', totalCartItems: Object.keys(req.session.cart).length });
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate the quantity to update
|
||||
let productQuantity = cartItem.quantity ? cartItem.quantity : 1;
|
||||
if(typeof productQuantity === 'string'){
|
||||
|
@ -397,14 +403,8 @@ router.post('/product/updatecart', async (req, res, next) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const product = await db.products.findOne({ _id: getId(req.session.cart[cartItem.cartId].productId) });
|
||||
if(!product){
|
||||
res.status(400).json({ message: 'There was an error updating the cart', totalCartItems: Object.keys(req.session.cart).length });
|
||||
return;
|
||||
}
|
||||
|
||||
// If stock management on check there is sufficient stock for this product
|
||||
if(config.trackStock){
|
||||
if(config.trackStock && product.productStock){
|
||||
if(productQuantity > product.productStock){
|
||||
res.status(400).json({ message: 'There is insufficient stock of this product.', totalCartItems: Object.keys(req.session.cart).length });
|
||||
return;
|
||||
|
|
|
@ -77,7 +77,7 @@ test('[Success] Update cart', async t => {
|
|||
.expect(200);
|
||||
|
||||
const cartId = Object.keys(cart.body.cart)[0];
|
||||
const productId = cart.body.cart[cartId].id;
|
||||
const productId = cart.body.cart[cartId].productId;
|
||||
|
||||
const res = await g.request
|
||||
.post('/product/updatecart')
|
||||
|
|
|
@ -31,14 +31,20 @@
|
|||
<div class="input-group-prepend">
|
||||
<button class="btn btn-primary btn-qty-minus" type="button">-</button>
|
||||
</div>
|
||||
<input type="number" class="form-control cart-product-quantity text-center" data-cartid="{{../this.productId}}" data-id="{{../this.id}}" maxlength="2" value="{{../this.quantity}}">
|
||||
<input type="number"
|
||||
class="form-control cart-product-quantity text-center"
|
||||
data-cartid="{{@key}}"
|
||||
data-id="{{../this.productId}}"
|
||||
maxlength="2"
|
||||
value="{{../this.quantity}}"
|
||||
>
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary btn-qty-add" type="button">+</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4 col-md-2 no-pad-left">
|
||||
<button class="btn btn-danger btn-delete-from-cart" data-id="{{../this.productId}}" data-cartid="{{../this.productId}}" type="button">{{{feather 'trash-2'}}}</button>
|
||||
<button class="btn btn-danger btn-delete-from-cart" data-cartid="{{../this.productId}}" data-cartid="{{@key}}" type="button">{{{feather 'trash-2'}}}</button>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="col-12 col-md-8 no-pad-left mb-2"></div>
|
||||
|
|
Loading…
Reference in New Issue