59 lines
1.3 KiB
Plaintext
59 lines
1.3 KiB
Plaintext
<div class="review-box">
|
|
<h3>Customer Reviews</h3>
|
|
|
|
<form id="review-form">
|
|
<input type="hidden" name="productId" value="{{ product.id }}" />
|
|
|
|
<input type="text" name="name" placeholder="Your name" required />
|
|
<textarea name="review" placeholder="Write your review" required></textarea>
|
|
|
|
<button type="submit">Submit Review</button>
|
|
</form>
|
|
|
|
<div id="reviews-list"></div>
|
|
</div>
|
|
|
|
<script>
|
|
const productId = "{{ product.id }}";
|
|
|
|
async function loadReviews() {
|
|
const response = await fetch(`/apps/reviews?productId=${productId}`);
|
|
const reviews = await response.json();
|
|
|
|
const container = document.getElementById("reviews-list");
|
|
container.innerHTML = "";
|
|
|
|
reviews.forEach(r => {
|
|
container.innerHTML += `
|
|
<div style="border:1px solid #ddd; padding:10px; margin:10px 0;">
|
|
<strong>${r.name}</strong>
|
|
<p>${r.review}</p>
|
|
</div>
|
|
`;
|
|
});
|
|
}
|
|
|
|
document.getElementById("review-form").addEventListener("submit", async function(e) {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(this);
|
|
|
|
await fetch("/apps/reviews", {
|
|
method: "POST",
|
|
body: formData
|
|
});
|
|
|
|
this.reset();
|
|
loadReviews();
|
|
});
|
|
|
|
loadReviews();
|
|
</script>
|
|
|
|
{% schema %}
|
|
{
|
|
"name": "Reviews",
|
|
"target": "section",
|
|
"settings": []
|
|
}
|
|
{% endschema %} |