diff --git a/db.sqlite3 b/db.sqlite3 index 00b641d..ab79a84 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/ecommerce/__pycache__/__init__.cpython-39.pyc b/ecommerce/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..8bd506f Binary files /dev/null and b/ecommerce/__pycache__/__init__.cpython-39.pyc differ diff --git a/ecommerce/__pycache__/settings.cpython-39.pyc b/ecommerce/__pycache__/settings.cpython-39.pyc new file mode 100644 index 0000000..368f931 Binary files /dev/null and b/ecommerce/__pycache__/settings.cpython-39.pyc differ diff --git a/ecommerce/__pycache__/urls.cpython-39.pyc b/ecommerce/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000..dfb8f74 Binary files /dev/null and b/ecommerce/__pycache__/urls.cpython-39.pyc differ diff --git a/ecommerce/__pycache__/wsgi.cpython-39.pyc b/ecommerce/__pycache__/wsgi.cpython-39.pyc new file mode 100644 index 0000000..d97fe6b Binary files /dev/null and b/ecommerce/__pycache__/wsgi.cpython-39.pyc differ diff --git a/ecommerce/settings.py b/ecommerce/settings.py index 10be8bd..0f179bd 100644 --- a/ecommerce/settings.py +++ b/ecommerce/settings.py @@ -125,6 +125,6 @@ os.path.join(BASE_DIR, 'static') ] -MEDIA_URL = 'static/image/' +MEDIA_URL = '/images/' -MEDIA_ROOT = os.path.join(BASE_DIR, 'static') \ No newline at end of file +MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images') \ No newline at end of file diff --git a/static/ecommerce/css/main.css b/static/ecommerce/css/main.css new file mode 100644 index 0000000..b4f5747 --- /dev/null +++ b/static/ecommerce/css/main.css @@ -0,0 +1,99 @@ +body{ + background-color: hsl(0, 0%, 98%); +} + +h1,h2,h3,h4,h5,h6{ + color:hsl(0, 0%, 30%); +} + +.box-element{ + box-shadow:hsl(0, 0%, 80%) 0 0 16px; + background-color: #fff; + border-radius: 4px; + padding: 10px; +} + +.thumbnail{ + width: 100%; + height: 200px; + -webkit-box-shadow: -1px -3px 5px -2px rgba(214,214,214,1); + -moz-box-shadow: -1px -3px 5px -2px rgba(214,214,214,1); + box-shadow: -1px -3px 5px -2px rgba(214,214,214,1); +} + +.product{ + border-radius: 0 0 4px 4px; +} + +.bg-dark{ + background-color: #4f868c!important; +} + +#cart-icon{ + width:25px; + display: inline-block; + margin-left: 15px; +} + +#cart-total{ + display: block; + text-align: center; + color:#fff; + background-color: red; + width: 20px; + height: 25px; + border-radius: 50%; + font-size: 14px; +} + +.col-lg-4, .col-lg-6, .col-lg-8, .col-lg-12{ + margin-top: 10px; +} + +.btn{ + border-radius: 0; +} + +.row-image{ + width: 100px; +} + +.form-field{ + width:250px; + display: inline-block; + padding: 5px; +} + +.cart-row{ + display: flex; + align-items: flex-stretch; + padding-bottom: 10px; + margin-bottom: 10px; + border-bottom: 1px solid #ececec; + +} + +.quantity{ + display: inline-block; + font-weight: 700; + padding-right:10px; + + +} + +.chg-quantity{ + width: 12px; + cursor: pointer; + display: block; + margin-top: 5px; + transition:.1s; +} + +.chg-quantity:hover{ + opacity: .6; +} + + +.hidden{ + display: none!important; +} \ No newline at end of file diff --git a/static/ecommerce/images/arrow-down.png b/static/ecommerce/images/arrow-down.png new file mode 100644 index 0000000..c3001d4 Binary files /dev/null and b/static/ecommerce/images/arrow-down.png differ diff --git a/static/ecommerce/images/arrow-up.png b/static/ecommerce/images/arrow-up.png new file mode 100644 index 0000000..058e679 Binary files /dev/null and b/static/ecommerce/images/arrow-up.png differ diff --git a/static/ecommerce/images/book.jpg b/static/ecommerce/images/book.jpg new file mode 100644 index 0000000..11c049b Binary files /dev/null and b/static/ecommerce/images/book.jpg differ diff --git a/static/ecommerce/images/cart.png b/static/ecommerce/images/cart.png new file mode 100644 index 0000000..3f8be4d Binary files /dev/null and b/static/ecommerce/images/cart.png differ diff --git a/static/ecommerce/images/headphones.jpg b/static/ecommerce/images/headphones.jpg new file mode 100644 index 0000000..84fa045 Binary files /dev/null and b/static/ecommerce/images/headphones.jpg differ diff --git a/static/ecommerce/images/placeholder.png b/static/ecommerce/images/placeholder.png new file mode 100644 index 0000000..5f64a71 Binary files /dev/null and b/static/ecommerce/images/placeholder.png differ diff --git a/static/ecommerce/images/shirt.jpg b/static/ecommerce/images/shirt.jpg new file mode 100644 index 0000000..971db45 Binary files /dev/null and b/static/ecommerce/images/shirt.jpg differ diff --git a/static/ecommerce/images/shoes.jpg b/static/ecommerce/images/shoes.jpg new file mode 100644 index 0000000..792cb31 Binary files /dev/null and b/static/ecommerce/images/shoes.jpg differ diff --git a/static/ecommerce/images/sourcecode.jpg b/static/ecommerce/images/sourcecode.jpg new file mode 100644 index 0000000..8cc9ac9 Binary files /dev/null and b/static/ecommerce/images/sourcecode.jpg differ diff --git a/static/ecommerce/images/watch.jpg b/static/ecommerce/images/watch.jpg new file mode 100644 index 0000000..841ecb8 Binary files /dev/null and b/static/ecommerce/images/watch.jpg differ diff --git a/static/ecommerce/js/cart.js b/static/ecommerce/js/cart.js new file mode 100644 index 0000000..e24f823 --- /dev/null +++ b/static/ecommerce/js/cart.js @@ -0,0 +1,63 @@ +var updateBtns = document.getElementsByClassName('update-cart') + +for (i = 0; i < updateBtns.length; i++) { + updateBtns[i].addEventListener('click', function(){ + var productId = this.dataset.product + var action = this.dataset.action + console.log('productId:', productId, 'Action:', action) + console.log('USER:', user) + + if (user == 'AnonymousUser'){ + addCookieItem(productId, action) + }else{ + updateUserOrder(productId, action) + } + }) +} + +function updateUserOrder(productId, action){ + console.log('User is authenticated, sending data...') + + var url = '/update_item/' + + fetch(url, { + method:'POST', + headers:{ + 'Content-Type':'application/json', + 'X-CSRFToken':csrftoken, + }, + body:JSON.stringify({'productId':productId, 'action':action}) + }) + .then((response) => { + return response.json(); + }) + .then((data) => { + location.reload() + }); +} + +function addCookieItem(productId, action){ + console.log('User is not authenticated') + + if (action == 'add'){ + if (cart[productId] == undefined){ + cart[productId] = {'quantity':1} + + }else{ + cart[productId]['quantity'] += 1 + } + } + + if (action == 'remove'){ + cart[productId]['quantity'] -= 1 + + if (cart[productId]['quantity'] <= 0){ + console.log('Item should be deleted') + delete cart[productId]; + } + } + console.log('CART:', cart) + document.cookie ='cart=' + JSON.stringify(cart) + ";domain=;path=/" + + location.reload() +} \ No newline at end of file diff --git a/store/__pycache__/__init__.cpython-39.pyc b/store/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..e5edfe5 Binary files /dev/null and b/store/__pycache__/__init__.cpython-39.pyc differ diff --git a/store/__pycache__/admin.cpython-39.pyc b/store/__pycache__/admin.cpython-39.pyc new file mode 100644 index 0000000..9db3d83 Binary files /dev/null and b/store/__pycache__/admin.cpython-39.pyc differ diff --git a/store/__pycache__/apps.cpython-39.pyc b/store/__pycache__/apps.cpython-39.pyc new file mode 100644 index 0000000..5a26802 Binary files /dev/null and b/store/__pycache__/apps.cpython-39.pyc differ diff --git a/store/__pycache__/models.cpython-39.pyc b/store/__pycache__/models.cpython-39.pyc new file mode 100644 index 0000000..632eaf6 Binary files /dev/null and b/store/__pycache__/models.cpython-39.pyc differ diff --git a/store/__pycache__/urls.cpython-39.pyc b/store/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000..33bb94b Binary files /dev/null and b/store/__pycache__/urls.cpython-39.pyc differ diff --git a/store/__pycache__/utils.cpython-39.pyc b/store/__pycache__/utils.cpython-39.pyc new file mode 100644 index 0000000..fc3c528 Binary files /dev/null and b/store/__pycache__/utils.cpython-39.pyc differ diff --git a/store/__pycache__/views.cpython-39.pyc b/store/__pycache__/views.cpython-39.pyc new file mode 100644 index 0000000..9c9db17 Binary files /dev/null and b/store/__pycache__/views.cpython-39.pyc differ diff --git a/store/migrations/__pycache__/0001_initial.cpython-39.pyc b/store/migrations/__pycache__/0001_initial.cpython-39.pyc new file mode 100644 index 0000000..e385779 Binary files /dev/null and b/store/migrations/__pycache__/0001_initial.cpython-39.pyc differ diff --git a/store/migrations/__pycache__/0002_product_image.cpython-39.pyc b/store/migrations/__pycache__/0002_product_image.cpython-39.pyc new file mode 100644 index 0000000..1641813 Binary files /dev/null and b/store/migrations/__pycache__/0002_product_image.cpython-39.pyc differ diff --git a/store/migrations/__pycache__/__init__.cpython-39.pyc b/store/migrations/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..a546305 Binary files /dev/null and b/store/migrations/__pycache__/__init__.cpython-39.pyc differ diff --git a/store/templates/store/cart.html b/store/templates/store/cart.html index 5d79a9d..1edd8dd 100644 --- a/store/templates/store/cart.html +++ b/store/templates/store/cart.html @@ -31,11 +31,11 @@
Total
{% for item in items %} -
-
-

{{item.product.name}}

-

${{item.product.price|floatformat:2}}

-
+
+
+

{{item.product.name}}

+

${{item.product.price|floatformat:2}}

+

{{item.quantity}}

diff --git a/store/templates/store/store.html b/store/templates/store/store.html index e61c142..e5cd1b7 100644 --- a/store/templates/store/store.html +++ b/store/templates/store/store.html @@ -9,7 +9,7 @@
{{product.name}}

- + View

${{product.price}}

diff --git a/store/urls.py b/store/urls.py index 2fa4042..3c73923 100644 --- a/store/urls.py +++ b/store/urls.py @@ -1,5 +1,5 @@ from django.urls import path - +from django.contrib.staticfiles.urls import staticfiles_urlpatterns from . import views urlpatterns = [ @@ -10,4 +10,5 @@ path('update_item/', views.updateItem, name="update_item"), path('process_order/', views.processOrder, name="process_order"), -] \ No newline at end of file +] +urlpatterns += staticfiles_urlpatterns() \ No newline at end of file