add delele product function
							parent
							
								
									6105e0f7b3
								
							
						
					
					
						commit
						3bb49dc15d
					
				| 
						 | 
					@ -105,12 +105,15 @@
 | 
				
			||||||
        function updateProductsInLocalStorage(){
 | 
					        function updateProductsInLocalStorage(){
 | 
				
			||||||
            localStorage.setItem("products", JSON.stringify(objProducts));
 | 
					            localStorage.setItem("products", JSON.stringify(objProducts));
 | 
				
			||||||
            $('#count-products-in-bag').text(objProducts.length);
 | 
					            $('#count-products-in-bag').text(objProducts.length);
 | 
				
			||||||
 | 
					            $('#list-products-in-bag').html('');
 | 
				
			||||||
            if(objProducts.length > 0) {
 | 
					            if(objProducts.length > 0) {
 | 
				
			||||||
                $('#count-products-in-bag').show();
 | 
					                $('#count-products-in-bag').show();
 | 
				
			||||||
                $.get($('meta[name="get-contents"]').attr('content')+"/"+objProducts.join(","), function(response, status){
 | 
					                let ids = objProducts.map(obj => obj.id);
 | 
				
			||||||
                    $('#list-products-in-bag').html('');
 | 
					                $.get($('meta[name="get-contents"]').attr('content')+"/"+ids.join(","), function(response, status){
 | 
				
			||||||
                    response.contents.forEach(function(item){
 | 
					                    response.contents.forEach(function(item){
 | 
				
			||||||
                        $('#list-products-in-bag').append(`
 | 
					                        let objProductInfo = objProducts.find(obj => obj.id == item.id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        let elementProduct = `
 | 
				
			||||||
                        <tr>
 | 
					                        <tr>
 | 
				
			||||||
                            <td class="text-start">
 | 
					                            <td class="text-start">
 | 
				
			||||||
                                <img class="rounded img-fluid" src="https://picsum.photos/120/120">
 | 
					                                <img class="rounded img-fluid" src="https://picsum.photos/120/120">
 | 
				
			||||||
| 
						 | 
					@ -120,26 +123,40 @@
 | 
				
			||||||
                                <br>
 | 
					                                <br>
 | 
				
			||||||
                                <small class="text-success">sofort verfügbar</small>
 | 
					                                <small class="text-success">sofort verfügbar</small>
 | 
				
			||||||
                                <br>
 | 
					                                <br>
 | 
				
			||||||
                                <select class="form-select form-select-sm" style="width:125px;" aria-label="Default select example">
 | 
					                                <select class="form-select form-select-sm select-quantity" style="width:125px;" aria-label="Default select example">`;
 | 
				
			||||||
                                    <option selected value="1">Anzahl: 1</option>
 | 
					                                for(let i = 1; i <= 5; i++){
 | 
				
			||||||
                                    <option value="2">Anzahl: 2</option>
 | 
					                                    if(objProductInfo.quantity == i) elementProduct += `<option selected value="${i}">Anzahl: ${i}</option>`;
 | 
				
			||||||
                                    <option value="3">Anzahl: 3</option>
 | 
					                                    else elementProduct += `<option value="${i}">Anzahl: ${i}</option>`;
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
 | 
					                                elementProduct += `
 | 
				
			||||||
                                    </select>
 | 
					                                    </select>
 | 
				
			||||||
                                <a href="" class="text-muted small text-decoration-none">Löschen</a>
 | 
					                               <button data-id="${item.id}" class="btn-remove-product text-muted small text-decoration-none" style="padding: 0; border: none; background: transparen;">Löschen</button>
 | 
				
			||||||
                            </td>
 | 
					                            </td>
 | 
				
			||||||
                            <td class="align-middle text-end">18,00€</td>
 | 
					                            <td class="align-middle text-end">18,00€</td>
 | 
				
			||||||
                        </tr>`);
 | 
					                        </tr>`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        $('#list-products-in-bag').append(elementProduct);
 | 
				
			||||||
                    });
 | 
					                    });
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            }else $('#count-products-in-bag').hide();
 | 
					            }else $('#count-products-in-bag').hide();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        function addToBag(productId){
 | 
					        function addToBag(productId){
 | 
				
			||||||
            if(objProducts.indexOf(productId) == -1) objProducts.push(productId+':'+1);
 | 
					            if(objProducts.indexOf(productId) == -1) objProducts.push({id: productId, quantity: 1});
 | 
				
			||||||
            updateProductsInLocalStorage();
 | 
					            updateProductsInLocalStorage();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        $(window).on('load', function(){
 | 
					        $(window).on('load', function(){
 | 
				
			||||||
            if(localStorage.getItem("products") != null) objProducts = JSON.parse(localStorage.getItem("products"));
 | 
					            if(localStorage.getItem("products") != null) objProducts = JSON.parse(localStorage.getItem("products"));
 | 
				
			||||||
            updateProductsInLocalStorage();
 | 
					            updateProductsInLocalStorage();
 | 
				
			||||||
 | 
					            $(document).on('click', '.btn-remove-product', function(){
 | 
				
			||||||
 | 
					                let objProductInfo = objProducts.find(obj => obj.id == $(this).attr('data-id'));
 | 
				
			||||||
 | 
					                let productId = $(this).attr('data-id');
 | 
				
			||||||
 | 
					                let index = objProducts.indexOf(objProductInfo);
 | 
				
			||||||
 | 
					                if(index != -1) objProducts.splice(index, 1);
 | 
				
			||||||
 | 
					                updateProductsInLocalStorage();
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            $(document).on('change', '.select-quantity', function(){
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    </script>
 | 
					    </script>
 | 
				
			||||||
    @yield('scripts')
 | 
					    @yield('scripts')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue