Aula 49 – Loja Online – Django – Processo de Checkout
Aula 49 – Loja Online – Django – Processo de Checkout
Voltar para página principal do blog
Todas as aulas desse curso
Aula 48 Aula 50
Se gostarem do conteúdo dêem um joinha 👍 na página do Código Fluente no
Facebook
Esse é o link do código fluente no Pinterest
Meus links de afiliados:
Hostinger
Digital Ocean
One.com
Melhore seu NETWORKING
https://digitalinnovation.one/
Participe de comunidades de desenvolvedores:
Fiquem a vontade para me adicionar ao linkedin.
E também para me seguir no https://github.com/toticavalcanti.
Código final da aula:
https://github.com/toticavalcanti
Toti:
https://www.youtube.com/channel/UCUEtjLuDpcOvR3mIUr-viOA
Backing track / Play-along:
https://www.youtube.com/channel/UCT3TryVMqTqYBjf5g5WAHfA
Código Fluente
https://www.youtube.com/channel/UCgn-O-88XBAwdG9gUWkkb0w
Putz!
https://www.youtube.com/channel/UCZXop2-CECwyFYmHbhnAkAw
Aula 49 – Loja Online – Django – Processo de Checkout
O processo de checkout envolve algumas coisas.
Processo de Checkout
1 – Carrinho ==> Checkout View
- Login/Register
- Shipping Address
- Billing Info
- Billing Address
- Credit Card / Payment
2 – Billing App / Component
- Billing Profile
- User or Email (Guest Email)
- Generate Payment Processor Token (Stripe or Braintree)
3 – Orders / Invoices Components
- Connecting the Billing Profile
- Shipping / Billing Address
- Cart
- Status — Shipped? Cancelled?
Orders
Vamos começar criando o componente Orders, isto é, o app Orders.
Com o ambiente ativado entre na mesma pasta onde tá o manage.py e execute:
python manage.py startapp orders
O carrinho(Cart) prepara o pedido(Order), o Order é o que vai ser manipulado pelo backend.
Vamos registrar o componente orders na lista INSTALED_APPS no e_commerce/e_commerce/settings.py
e_commerce/e_commerce/settings.py
"""
Django settings for e_commerce project.
Generated by 'django-admin startproject' using Django 2.1.4.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'xjmv-0^l__duq4-xp54m94bsf02lx4&1xka_ykd_(7(5#9^1o^'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#our apps
'carts',
'orders',
'products',
'search',
'tags',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'e_commerce.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'e_commerce.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static_local")
]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn", "static_root")
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn", "media_root")
Abra o e_commerce/orders/models.py e coloque o conteúdo abaixo.
e_commerce/orders/models.py
from django.db import models
from carts.models import Cart
ORDER_STATUS_CHOICES = (
('created', 'Criado'),
('paid', 'Pago'),
('shipped', 'Enviado'),
('refunded', 'Devolvido'),
)
class Order(models.Model):
order_id = models.CharField(max_length = 120, blank = True)
# billing_profile = ?
# shipping_address = ?
# billing_address
cart = models.foreignKey(Cart, on_delete=models.CASCADE, null = True)
status = models.CharField(max_length = 120, default = 'created', choices = ORDER_STATUS_CHOICES )
shipping_total = models.DecimalField(default = 5.99, max_digits = 100, decimal_places = 2)
# Order total = models.DecimalField(default = 0.00, max_digits = 100, decimal_places = 2)
def __str__(self):
return self.order_id
Agora rode o makemigrations
python manage.py makemigrations
E depois o migrate
python manage.py migrate
Abra o e_commerce/orders/admin.py e modifique para que fique assim:
e_commerce/orders/admin.py
from django.contrib import admin
from .models import Order
admin.site.register(Order)
Agora acesse http://127.0.0.1:8000/admin
Veja que agora o Orders aparece no painel admin.