Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Copy checkout meta to new orders on completion

Dan Kolbman3f97960345e4
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index 012e7966ac..6dcf0808ee 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -754,6 +754,11 @@ def create_order(
# assign checkout payments to the order
checkout.payments.update(order=order)
+ # copy metadata from the checkout into the new order
+ order.meta = checkout.meta
+ order.private_meta = checkout.private_meta
+ order.save()
+
order_created(order=order, user=user)
# Send the order confirmation email
diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.py
index 9b6bb60e05..bface0f5e6 100644
--- a/tests/api/test_checkout.py
+++ b/tests/api/test_checkout.py
@@ -1162,6 +1162,10 @@ def test_checkout_complete(
checkout.shipping_address = address
checkout.shipping_method = shipping_method
checkout.billing_address = address
+ checkout.store_meta(namespace="PUBLIC", client="PLUGIN", item={"accepted": "true"})
+ checkout.store_private_meta(
+ namespace="PRIVATE", client="PLUGIN", item={"accepted": "true"},
+ )
checkout.save()
checkout_line = checkout.lines.first()
@@ -1193,6 +1197,8 @@ def test_checkout_complete(
order = Order.objects.first()
assert order.token == order_token
assert order.total.gross == total.gross - gift_current_balance
+ assert order.meta == checkout.meta
+ assert order.private_meta == checkout.private_meta
order_line = order.lines.first()
assert checkout_line_quantity == order_line.quantity