Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extend Checkout with metadata
Jakub Draganek336751416135
diff --git a/saleor/checkout/migrations/0020_auto_20190723_0722.py b/saleor/checkout/migrations/0020_auto_20190723_0722.pynew file mode 100644index 0000000000..c9a8fbaa09--- /dev/null+++ b/saleor/checkout/migrations/0020_auto_20190723_0722.py@@ -0,0 +1,33 @@+# Generated by Django 2.2.3 on 2019-07-23 12:22++import django.contrib.postgres.fields.jsonb+from django.db import migrations+import saleor.core.utils.json_serializer+++class Migration(migrations.Migration):++ dependencies = [("checkout", "0019_checkout_gift_cards")]++ operations = [+ migrations.AddField(+ model_name="checkout",+ name="meta",+ field=django.contrib.postgres.fields.jsonb.JSONField(+ blank=True,+ default=dict,+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,+ null=True,+ ),+ ),+ migrations.AddField(+ model_name="checkout",+ name="private_meta",+ field=django.contrib.postgres.fields.jsonb.JSONField(+ blank=True,+ default=dict,+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,+ null=True,+ ),+ ),+ ]diff --git a/saleor/checkout/models.py b/saleor/checkout/models.pyindex 8d2da91ae4..df689915db 100644--- a/saleor/checkout/models.py+++ b/saleor/checkout/models.py@@ -11,6 +11,7 @@ from django.utils.encoding import smart_strfrom django_prices.models import MoneyFieldfrom ..account.models import Address+from ..core.models import ModelWithMetadatafrom ..core.taxes import zero_moneyfrom ..core.weight import zero_weightfrom ..giftcard.models import GiftCard@@ -36,7 +37,7 @@ class CheckoutQueryset(models.QuerySet):) # noqa-class Checkout(models.Model):+class Checkout(ModelWithMetadata):"""A shopping checkout."""created = models.DateTimeField(auto_now_add=True)diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex fda94a8b7e..771f371a09 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -1,5 +1,6 @@import grapheneimport graphene_django_optimizer as gql_optimizer+from graphql_jwt.decorators import permission_requiredfrom django.conf import settingsfrom ...checkout import models@@ -12,7 +13,9 @@ from ...core.taxes.interface import (calculate_checkout_total,)from ..core.connection import CountableDjangoObjectType+from ..core.resolvers import resolve_meta, resolve_private_metafrom ..core.types.money import TaxedMoney+from ..core.types.meta import MetadataObjectTypefrom ..giftcard.types import GiftCardfrom ..payment.enums import PaymentGatewayEnumfrom ..shipping.types import ShippingMethod@@ -45,7 +48,7 @@ class CheckoutLine(CountableDjangoObjectType):return root.is_shipping_required()-class Checkout(CountableDjangoObjectType):+class Checkout(MetadataObjectType, CountableDjangoObjectType):available_shipping_methods = graphene.List(ShippingMethod,required=True,@@ -163,3 +166,12 @@ class Checkout(CountableDjangoObjectType):@staticmethoddef resolve_is_shipping_required(root: models.Checkout, _info):return root.is_shipping_required()++ @staticmethod+ @permission_required("order.manage_orders")+ def resolve_private_meta(root, _info):+ return resolve_private_meta(root, _info)++ @staticmethod+ def resolve_meta(root, _info):+ return resolve_meta(root, _info)