Small cart quantity fixes
							parent
							
								
									abc5de8ff6
								
							
						
					
					
						commit
						c674f86576
					
				|  | @ -1,4 +1,5 @@ | |||
| node_modules/ | ||||
| data/ | ||||
| config/settings.json | ||||
| .vscode | ||||
| .vscode | ||||
| **.DS_Store | ||||
							
								
								
									
										6
									
								
								app.js
								
								
								
								
							
							
						
						
									
										6
									
								
								app.js
								
								
								
								
							|  | @ -249,6 +249,12 @@ app.use((req, res, next) => { | |||
|     next(); | ||||
| }); | ||||
| 
 | ||||
| // Ran on all routes
 | ||||
| app.use((req, res, next) => { | ||||
|     res.setHeader('Cache-Control', 'no-cache, no-store'); | ||||
|     next(); | ||||
| }); | ||||
| 
 | ||||
| // setup the routes
 | ||||
| app.use('/', index); | ||||
| app.use('/', customer); | ||||
|  |  | |||
|  | @ -142,6 +142,10 @@ $(document).ready(function (){ | |||
|         cartUpdate(qtyElement); | ||||
|     }); | ||||
| 
 | ||||
|     $(document).on('click', '.btn-delete-from-cart', function(e){ | ||||
|         deleteFromCart($(e.target)); | ||||
|     }); | ||||
| 
 | ||||
|     $(document).on('click', '.orderFilterByStatus', function(e){ | ||||
|         e.preventDefault(); | ||||
|         window.location = '/admin/orders/bystatus/' + $('#orderStatusFilter').val(); | ||||
|  | @ -457,6 +461,10 @@ $(document).ready(function (){ | |||
|     $(document).on('click', '.product-add-to-cart', function(e){ | ||||
|         var productOptions = getSelectedOptions(); | ||||
| 
 | ||||
|         if(parseInt($('#product_quantity').val()) < 0){ | ||||
|             $('#product_quantity').val(0); | ||||
|         } | ||||
| 
 | ||||
|         $.ajax({ | ||||
|             method: 'POST', | ||||
|             url: '/product/addtocart', | ||||
|  | @ -682,12 +690,12 @@ function slugify(str){ | |||
| } | ||||
| 
 | ||||
| function cartUpdate(element){ | ||||
|     if($(element).val() < 1){ | ||||
|         deleteFromCart($(element)); | ||||
|     }else{ | ||||
|     if($(element).val() > 0){ | ||||
|         if($(element).val() !== ''){ | ||||
|             updateCart(); | ||||
|         } | ||||
|     }else{ | ||||
|         $(element).val(1); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | @ -700,11 +708,7 @@ function updateCart(){ | |||
|             itemQuantity: $(this).val(), | ||||
|             productId: $(this).attr('data-id') | ||||
|         }; | ||||
|         if($(this).val() < 0){ | ||||
|             deleteFromCart($(this)); | ||||
|         }else{ | ||||
|             cartItems.push(item); | ||||
|         } | ||||
|         cartItems.push(item); | ||||
|     }); | ||||
| 
 | ||||
|     // 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; | ||||
|     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
 | ||||
|     if(!req.session.cart){ | ||||
|         req.session.cart = []; | ||||
|  |  | |||
|  | @ -39,6 +39,9 @@ | |||
|                                             </span> | ||||
|                                         </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> | ||||
|                             </p> | ||||
|                         </div> | ||||
|  |  | |||
|  | @ -25,17 +25,19 @@ | |||
|                              {{#each this.options}} {{#if @last}} {{this}} {{else}} {{this}} / {{/if}} {{/each}} | ||||
|                         </p> | ||||
|                         <p> | ||||
| 
 | ||||
|                             <div class="col s12 no-pad-left"> | ||||
|                                 <span class="col s2"> | ||||
|                                     <button class="btn waves-effect waves-light blue darken-3 btn-qty-minus" type="button">-</button> | ||||
|                                 </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}}"> | ||||
|                                 </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> | ||||
|                                 </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> | ||||
|                         </p> | ||||
|                     </div> | ||||
|  |  | |||
|  | @ -25,17 +25,19 @@ | |||
|                              {{#each this.options}} {{#if @last}} {{this}} {{else}} {{this}} / {{/if}} {{/each}} | ||||
|                         </p> | ||||
|                         <p> | ||||
| 
 | ||||
|                             <div class="col s12 no-pad-left"> | ||||
|                                 <span class="col s2"> | ||||
|                                     <button class="btn waves-effect waves-light black btn-qty-minus" type="button">-</button> | ||||
|                                 </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}}"> | ||||
|                                 </div> | ||||
|                                 <span class="col s2"> | ||||
|                                 <span class="col s3"> | ||||
|                                     <button class="btn waves-effect waves-light black btn-qty-add" type="button">+</button> | ||||
|                                 </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> | ||||
|                         </p> | ||||
|                     </div> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue