prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  tracking.es6:30-33: Send `purchase` event to YA and GA...
  The puzzle `504-30170dc3` from #504 has to be resolved:
  
  https://github.com/fidals/shopelectro/blob/4e607fb856842b43192511b1b4eaff19d2052b9a/front/js/shared/tracking.es6#L30-L33
  
  The puzzle was created by Artemiy on 17-Aug-18. 
  
  Estimate: 60 minutes,     
  
  If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is _removed_ from the source code. Here is more about [PDD](http://www.yegor256.com/2009/03/04/pdd.html) and [about me](http://www.yegor256.com/2017/04/05/pdd-in-action.html).
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `shopelectro/views/ecommerce.py`
  Content:
  ```
  1 from django.conf import settings
  2 from django.http import HttpResponse, JsonResponse
  3 from django.shortcuts import get_object_or_404, render
  4 from django.views.decorators.http import require_POST
  5 
  6 from ecommerce import mailer, views as ec_views
  7 from pages.models import CustomPage
  8 
  9 from shopelectro.cart import SECart
  10 from shopelectro.forms import OrderForm
  11 from shopelectro.models import Product, Order
  12 
  13 
  14 # ECOMMERCE VIEWS
  15 class OrderPage(ec_views.OrderPage):
  16     order_form = OrderForm
  17     cart = SECart
  18 
  19     def get_context_data(self, request, **kwargs):
  20         return {
  21             **super(OrderPage, self).get_context_data(request, **kwargs),
  22             'page': CustomPage.objects.get(slug='order'),
  23         }
  24 
  25 
  26 class AddToCart(ec_views.AddToCart):
  27     cart = SECart
  28     product_model = Product
  29     order_form = OrderForm
  30 
  31 
  32 class RemoveFromCart(ec_views.RemoveFromCart):
  33     cart = SECart
  34     product_model = Product
  35     order_form = OrderForm
  36 
  37 
  38 class ChangeCount(ec_views.ChangeCount):
  39     cart = SECart
  40     product_model = Product
  41     order_form = OrderForm
  42 
  43 
  44 class FlushCart(ec_views.FlushCart):
  45     product_model = Product
  46     order_form = OrderForm
  47 
  48 
  49 class OrderSuccess(ec_views.OrderSuccess):
  50     order = Order
  51 
  52 
  53 @require_POST
  54 def one_click_buy(request):
  55     """
  56     Handle one-click-buy.
  57 
  58     Accept XHR, save Order to DB, send mail about it
  59     and return 200 OK.
  60     """
  61     SECart(request.session).clear()
  62 
  63     cart = SECart(request.session)
  64     product = get_object_or_404(Product, id=request.POST['product'])
  65     cart.add(product, int(request.POST['quantity']))
  66     order = Order(phone=request.POST['phone'])
  67     order.set_positions(cart)
  68     ec_views.save_order_to_session(request.session, order)
  69     mailer.send_order(
  70         subject=settings.EMAIL_SUBJECTS['one_click'],
  71         order=order,
  72         to_customer=False,
  73     )
  74     return HttpResponse('ok')
  75 
  76 
  77 @require_POST
  78 def order_call(request):
  79     """Send email about ordered call."""
  80     phone, time, url = ec_views.get_keys_from_post(
  81         request, 'phone', 'time', 'url')
  82 
  83     mailer.send_backcall(
  84         subject=settings.EMAIL_SUBJECTS['call'],
  85         phone=phone,
  86         time=time,
  87         url=url,
  88     )
  89 
  90     return HttpResponse('ok')
  91 
  92 
  93 class YandexOrder(OrderPage):
  94 
  95     def post(self, request):
  96         cart = self.cart(request.session)
  97         form = self.order_form(request.POST.dict())
  98 
  99         if not form.is_valid():
  100             return render(request, self.template, {'cart': cart, 'form': form})
  101 
  102         order = form.save()
  103         order.set_positions(cart)
  104         ec_views.save_order_to_session(request.session, order)
  105 
  106         # Took form fields from Yandex docs https://goo.gl/afKfsz
  107         response_data = {
  108             'yandex_kassa_link': settings.YANDEX_KASSA_LINK,  # Required
  109             'shopId': settings.SHOP['id'],  # Required
  110             'scid': settings.SHOP['scid'],  # Required
  111             'shopSuccessURL': settings.SHOP['success_url'],
  112             'shopFailURL': settings.SHOP['fail_url'],
  113             'customerNumber': order.id,  # Required
  114             'sum': order.total_price,  # Required
  115             'orderNumber': order.fake_order_number,
  116             'cps_phone': order.phone,
  117             'cps_email': order.email,
  118             'paymentType': request.POST.get('payment_type'),
  119         }
  120 
  121         return JsonResponse(response_data)
  122
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/shopelectro/views/ecommerce.py b/shopelectro/views/ecommerce.py
  --- a/shopelectro/views/ecommerce.py
  +++ b/shopelectro/views/ecommerce.py
  @@ -1,4 +1,5 @@
   from django.conf import settings
  +from django.core import serializers
   from django.http import HttpResponse, JsonResponse
   from django.shortcuts import get_object_or_404, render
   from django.views.decorators.http import require_POST
  @@ -47,7 +48,20 @@
   
   
   class OrderSuccess(ec_views.OrderSuccess):
  -    order = Order
  +    order = Order.objects.all().prefetch_related('positions')
  +
  +    def get_context_data(self, **kwargs):
  +        context = super().get_context_data(**kwargs)
  +        positions_json = serializers.serialize(
  +            'json',
  +            context['order'].positions.all(),
  +            fields=['name', 'quantity', 'price'],
  +        )
  +
  +        return {
  +            **context,
  +            'positions_json': positions_json,
  +        }
   
   
   @require_POST
  
verification_info: {"golden_diff": "diff --git a/shopelectro/views/ecommerce.py b/shopelectro/views/ecommerce.py\n--- a/shopelectro/views/ecommerce.py\n+++ b/shopelectro/views/ecommerce.py\n@@ -1,4 +1,5 @@\n from django.conf import settings\n+from django.core import serializers\n from django.http import HttpResponse, JsonResponse\n from django.shortcuts import get_object_or_404, render\n from django.views.decorators.http import require_POST\n@@ -47,7 +48,20 @@\n \n \n class OrderSuccess(ec_views.OrderSuccess):\n-    order = Order\n+    order = Order.objects.all().prefetch_related('positions')\n+\n+    def get_context_data(self, **kwargs):\n+        context = super().get_context_data(**kwargs)\n+        positions_json = serializers.serialize(\n+            'json',\n+            context['order'].positions.all(),\n+            fields=['name', 'quantity', 'price'],\n+        )\n+\n+        return {\n+            **context,\n+            'positions_json': positions_json,\n+        }\n \n \n @require_POST\n", "issue": "tracking.es6:30-33: Send `purchase` event to YA and GA...\nThe puzzle `504-30170dc3` from #504 has to be resolved:\n\nhttps://github.com/fidals/shopelectro/blob/4e607fb856842b43192511b1b4eaff19d2052b9a/front/js/shared/tracking.es6#L30-L33\n\nThe puzzle was created by Artemiy on 17-Aug-18. \n\nEstimate: 60 minutes,     \n\nIf you have any technical questions, don't ask me, submit new tickets instead. The task will be \"done\" when the problem is fixed and the text of the puzzle is _removed_ from the source code. Here is more about [PDD](http://www.yegor256.com/2009/03/04/pdd.html) and [about me](http://www.yegor256.com/2017/04/05/pdd-in-action.html).\n", "before_files": [{"content": "from django.conf import settings\nfrom django.http import HttpResponse, JsonResponse\nfrom django.shortcuts import get_object_or_404, render\nfrom django.views.decorators.http import require_POST\n\nfrom ecommerce import mailer, views as ec_views\nfrom pages.models import CustomPage\n\nfrom shopelectro.cart import SECart\nfrom shopelectro.forms import OrderForm\nfrom shopelectro.models import Product, Order\n\n\n# ECOMMERCE VIEWS\nclass OrderPage(ec_views.OrderPage):\n    order_form = OrderForm\n    cart = SECart\n\n    def get_context_data(self, request, **kwargs):\n        return {\n            **super(OrderPage, self).get_context_data(request, **kwargs),\n            'page': CustomPage.objects.get(slug='order'),\n        }\n\n\nclass AddToCart(ec_views.AddToCart):\n    cart = SECart\n    product_model = Product\n    order_form = OrderForm\n\n\nclass RemoveFromCart(ec_views.RemoveFromCart):\n    cart = SECart\n    product_model = Product\n    order_form = OrderForm\n\n\nclass ChangeCount(ec_views.ChangeCount):\n    cart = SECart\n    product_model = Product\n    order_form = OrderForm\n\n\nclass FlushCart(ec_views.FlushCart):\n    product_model = Product\n    order_form = OrderForm\n\n\nclass OrderSuccess(ec_views.OrderSuccess):\n    order = Order\n\n\n@require_POST\ndef one_click_buy(request):\n    \"\"\"\n    Handle one-click-buy.\n\n    Accept XHR, save Order to DB, send mail about it\n    and return 200 OK.\n    \"\"\"\n    SECart(request.session).clear()\n\n    cart = SECart(request.session)\n    product = get_object_or_404(Product, id=request.POST['product'])\n    cart.add(product, int(request.POST['quantity']))\n    order = Order(phone=request.POST['phone'])\n    order.set_positions(cart)\n    ec_views.save_order_to_session(request.session, order)\n    mailer.send_order(\n        subject=settings.EMAIL_SUBJECTS['one_click'],\n        order=order,\n        to_customer=False,\n    )\n    return HttpResponse('ok')\n\n\n@require_POST\ndef order_call(request):\n    \"\"\"Send email about ordered call.\"\"\"\n    phone, time, url = ec_views.get_keys_from_post(\n        request, 'phone', 'time', 'url')\n\n    mailer.send_backcall(\n        subject=settings.EMAIL_SUBJECTS['call'],\n        phone=phone,\n        time=time,\n        url=url,\n    )\n\n    return HttpResponse('ok')\n\n\nclass YandexOrder(OrderPage):\n\n    def post(self, request):\n        cart = self.cart(request.session)\n        form = self.order_form(request.POST.dict())\n\n        if not form.is_valid():\n            return render(request, self.template, {'cart': cart, 'form': form})\n\n        order = form.save()\n        order.set_positions(cart)\n        ec_views.save_order_to_session(request.session, order)\n\n        # Took form fields from Yandex docs https://goo.gl/afKfsz\n        response_data = {\n            'yandex_kassa_link': settings.YANDEX_KASSA_LINK,  # Required\n            'shopId': settings.SHOP['id'],  # Required\n            'scid': settings.SHOP['scid'],  # Required\n            'shopSuccessURL': settings.SHOP['success_url'],\n            'shopFailURL': settings.SHOP['fail_url'],\n            'customerNumber': order.id,  # Required\n            'sum': order.total_price,  # Required\n            'orderNumber': order.fake_order_number,\n            'cps_phone': order.phone,\n            'cps_email': order.email,\n            'paymentType': request.POST.get('payment_type'),\n        }\n\n        return JsonResponse(response_data)\n", "path": "shopelectro/views/ecommerce.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.core import serializers\nfrom django.http import HttpResponse, JsonResponse\nfrom django.shortcuts import get_object_or_404, render\nfrom django.views.decorators.http import require_POST\n\nfrom ecommerce import mailer, views as ec_views\nfrom pages.models import CustomPage\n\nfrom shopelectro.cart import SECart\nfrom shopelectro.forms import OrderForm\nfrom shopelectro.models import Product, Order\n\n\n# ECOMMERCE VIEWS\nclass OrderPage(ec_views.OrderPage):\n    order_form = OrderForm\n    cart = SECart\n\n    def get_context_data(self, request, **kwargs):\n        return {\n            **super(OrderPage, self).get_context_data(request, **kwargs),\n            'page': CustomPage.objects.get(slug='order'),\n        }\n\n\nclass AddToCart(ec_views.AddToCart):\n    cart = SECart\n    product_model = Product\n    order_form = OrderForm\n\n\nclass RemoveFromCart(ec_views.RemoveFromCart):\n    cart = SECart\n    product_model = Product\n    order_form = OrderForm\n\n\nclass ChangeCount(ec_views.ChangeCount):\n    cart = SECart\n    product_model = Product\n    order_form = OrderForm\n\n\nclass FlushCart(ec_views.FlushCart):\n    product_model = Product\n    order_form = OrderForm\n\n\nclass OrderSuccess(ec_views.OrderSuccess):\n    order = Order.objects.all().prefetch_related('positions')\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        positions_json = serializers.serialize(\n            'json',\n            context['order'].positions.all(),\n            fields=['name', 'quantity', 'price'],\n        )\n\n        return {\n            **context,\n            'positions_json': positions_json,\n        }\n\n\n@require_POST\ndef one_click_buy(request):\n    \"\"\"\n    Handle one-click-buy.\n\n    Accept XHR, save Order to DB, send mail about it\n    and return 200 OK.\n    \"\"\"\n    SECart(request.session).clear()\n\n    cart = SECart(request.session)\n    product = get_object_or_404(Product, id=request.POST['product'])\n    cart.add(product, int(request.POST['quantity']))\n    order = Order(phone=request.POST['phone'])\n    order.set_positions(cart)\n    ec_views.save_order_to_session(request.session, order)\n    mailer.send_order(\n        subject=settings.EMAIL_SUBJECTS['one_click'],\n        order=order,\n        to_customer=False,\n    )\n    return HttpResponse('ok')\n\n\n@require_POST\ndef order_call(request):\n    \"\"\"Send email about ordered call.\"\"\"\n    phone, time, url = ec_views.get_keys_from_post(\n        request, 'phone', 'time', 'url')\n\n    mailer.send_backcall(\n        subject=settings.EMAIL_SUBJECTS['call'],\n        phone=phone,\n        time=time,\n        url=url,\n    )\n\n    return HttpResponse('ok')\n\n\nclass YandexOrder(OrderPage):\n\n    def post(self, request):\n        cart = self.cart(request.session)\n        form = self.order_form(request.POST.dict())\n\n        if not form.is_valid():\n            return render(request, self.template, {'cart': cart, 'form': form})\n\n        order = form.save()\n        order.set_positions(cart)\n        ec_views.save_order_to_session(request.session, order)\n\n        # Took form fields from Yandex docs https://goo.gl/afKfsz\n        response_data = {\n            'yandex_kassa_link': settings.YANDEX_KASSA_LINK,  # Required\n            'shopId': settings.SHOP['id'],  # Required\n            'scid': settings.SHOP['scid'],  # Required\n            'shopSuccessURL': settings.SHOP['success_url'],\n            'shopFailURL': settings.SHOP['fail_url'],\n            'customerNumber': order.id,  # Required\n            'sum': order.total_price,  # Required\n            'orderNumber': order.fake_order_number,\n            'cps_phone': order.phone,\n            'cps_email': order.email,\n            'paymentType': request.POST.get('payment_type'),\n        }\n\n        return JsonResponse(response_data)\n", "path": "shopelectro/views/ecommerce.py"}]}