feat: implement shopping cart feature with user authentication support
All checks were successful
Build and Push Docker Image / build (push) Successful in 42s
All checks were successful
Build and Push Docker Image / build (push) Successful in 42s
- Added `Cart` and `CartItem` models with migrations for managing user-specific carts and items - Developed services for cart-related operations: adding, removing, and updating cart items - Built specialized templates (`cart.html`) and styled them with new CSS assets (`cart.css`) - Enabled real-time UI updates via AJAX in shopping cart interactions (`cart.js`) - Modified header to dynamically display cart link with user authentication awareness - Added Leaflet-based interactive map to the contacts page and integrated CSS/JS dependencies - Expanded tests for cart functionality, item detail page cart integration, and contacts page maps
This commit is contained in:
20
static/js/cart.js
Normal file
20
static/js/cart.js
Normal file
@@ -0,0 +1,20 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.querySelectorAll('[data-cart-decrement]').forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
const quantity = Number(button.dataset.currentQuantity || '0');
|
||||
const removeForm = document.getElementById(button.dataset.removeFormId);
|
||||
const updateForm = document.getElementById(button.dataset.updateFormId);
|
||||
|
||||
if (quantity <= 1) {
|
||||
if (window.confirm('Удалить товар из корзины?') && removeForm) {
|
||||
removeForm.submit();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (updateForm) {
|
||||
updateForm.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user