Skip to content

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

Anonymize search payload for order/user in demo mode (#9841)

Maciej Korycinski8de7ca21d6b1
diff --git a/saleor/plugins/anonymize/plugin.py b/saleor/plugins/anonymize/plugin.py
index 08d586ac0c..1542a89412 100644
--- a/saleor/plugins/anonymize/plugin.py
+++ b/saleor/plugins/anonymize/plugin.py
@@ -4,7 +4,9 @@ from django.utils import timezone
from django.utils.crypto import get_random_string
from faker import Faker
+from ...account import search
from ...core.anonymize import obfuscate_address
+from ...order.search import prepare_order_search_document_value
from ..base_plugin import BasePlugin
from . import obfuscate_order
@@ -46,6 +48,7 @@ class AnonymizePlugin(BasePlugin):
def order_created(self, order: "Order", previous_value: Any):
order = obfuscate_order(order)
+ order.search_document = prepare_order_search_document_value(order)
order.save()
def customer_created(self, customer: "User", previous_value: Any) -> Any:
@@ -54,4 +57,7 @@ class AnonymizePlugin(BasePlugin):
timestamp = str(timezone.now())
email = f"{hash(timestamp + get_random_string(5))}@anonymous-demo-email.com"
customer.email = email
+ customer.search_document = search.prepare_user_search_document_value(
+ customer, attach_addresses_data=False
+ )
customer.save()