Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update templates/cart.html
Browse files- templates/cart.html +35 -1
    	
        templates/cart.html
    CHANGED
    
    | @@ -162,7 +162,7 @@ | |
| 162 | 
             
                                    <div>{{ suggestion.Name }}</div>
         | 
| 163 | 
             
                                    <div class="text-muted">₹{{ suggestion.Price__c }}</div>
         | 
| 164 | 
             
                                </div>
         | 
| 165 | 
            -
                                <button class="add-back-button" onclick=" | 
| 166 | 
             
                            </div>
         | 
| 167 | 
             
                            {% endfor %}
         | 
| 168 | 
             
                        </div>
         | 
| @@ -416,6 +416,40 @@ | |
| 416 | 
             
                        })
         | 
| 417 | 
             
                        .catch(err => console.error('Error adding suggestion:', err));
         | 
| 418 | 
             
                    }
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 419 |  | 
| 420 |  | 
| 421 |  | 
|  | |
| 162 | 
             
                                    <div>{{ suggestion.Name }}</div>
         | 
| 163 | 
             
                                    <div class="text-muted">₹{{ suggestion.Price__c }}</div>
         | 
| 164 | 
             
                                </div>
         | 
| 165 | 
            +
                                <button class="add-back-button" onclick="addToCartSuggestion('{{ suggestion.Name }}', '{{ suggestion.Price__c }}', '{{ suggestion.Image1__c }}', '{{ suggestion.Id }}')">Add</button>
         | 
| 166 | 
             
                            </div>
         | 
| 167 | 
             
                            {% endfor %}
         | 
| 168 | 
             
                        </div>
         | 
|  | |
| 416 | 
             
                        })
         | 
| 417 | 
             
                        .catch(err => console.error('Error adding suggestion:', err));
         | 
| 418 | 
             
                    }
         | 
| 419 | 
            +
                    function addToCartSuggestion(itemName, itemPrice, itemImage, itemId) {
         | 
| 420 | 
            +
                        const customerEmail = "{{ customer_email }}"; // Get customer email from session
         | 
| 421 | 
            +
             | 
| 422 | 
            +
                        // Create the data object to send to the server
         | 
| 423 | 
            +
                        const data = {
         | 
| 424 | 
            +
                            item_name: itemName,
         | 
| 425 | 
            +
                            item_price: itemPrice,
         | 
| 426 | 
            +
                            item_image: itemImage,
         | 
| 427 | 
            +
                            item_id: itemId,
         | 
| 428 | 
            +
                            addons: [], // Default to empty, you can adjust if needed
         | 
| 429 | 
            +
                            instructions: "", // Default to empty, you can adjust if needed
         | 
| 430 | 
            +
                            customer_email: customerEmail
         | 
| 431 | 
            +
                        };
         | 
| 432 | 
            +
             | 
| 433 | 
            +
                        // Send the data to the backend via a POST request
         | 
| 434 | 
            +
                        fetch('/cart/add_suggestion_to_cart', {
         | 
| 435 | 
            +
                            method: 'POST',
         | 
| 436 | 
            +
                            headers: {
         | 
| 437 | 
            +
                                'Content-Type': 'application/json'
         | 
| 438 | 
            +
                            },
         | 
| 439 | 
            +
                            body: JSON.stringify(data)
         | 
| 440 | 
            +
                        })
         | 
| 441 | 
            +
                        .then(response => response.json())
         | 
| 442 | 
            +
                        .then(data => {
         | 
| 443 | 
            +
                            if (data.success) {
         | 
| 444 | 
            +
                                alert('Item added to cart!');
         | 
| 445 | 
            +
                                location.reload(); // Reload to update the cart view
         | 
| 446 | 
            +
                            } else {
         | 
| 447 | 
            +
                                alert('Error adding item to cart: ' + data.error);
         | 
| 448 | 
            +
                            }
         | 
| 449 | 
            +
                        })
         | 
| 450 | 
            +
                        .catch(err => console.error('Error adding item:', err));
         | 
| 451 | 
            +
                    }
         | 
| 452 | 
            +
             | 
| 453 |  | 
| 454 |  | 
| 455 |  |