Commits

Chris Gregory committed adebf63

Fab deploy

  • Participants
  • Parent commits edab019

Comments (0)

Files changed (4)

db-development.sqlite3

Binary file modified.
         url(r'^$', 'home.views.index', name='root_path'),
         url(r'^design/$', 'home.views.design'),
         url(r'^welcome/$', 'home.views.welcome'),
+        url(r'^webhook/$', 'home.views.webhook'),
         url(r'^ajax/(?P<product_id>\d+)/(?P<variant_id>\d+)/$', 'home.views.ajax'),
 )
 import shopify
 from shopify_app.decorators import shop_login_required
 from django.http import HttpResponse
+from django.views.decorators.csrf import csrf_exempt
+from django.utils import simplejson as json
 
 def welcome(request):
     return render_to_response('home/welcome.html', {
     return render_to_response('home/design.html', {},
                               context_instance=RequestContext(request))
 
+@csrf_exempt
+def webhook(request):
+    response = HttpResponse()
+    if request.method == 'POST':
+        json_data = json.loads(request.raw_post_data)
+        line_items = json_data['line_items']
+        SHOP_NAME = "bamboletta"
+        API_PASSWORD = "3921846ab0948645fce4901a81685176"
+        session = shopify.Session(SHOP_NAME)
+        session.token = API_PASSWORD
+        shopify.ShopifyResource.activate_session(session)
+
+        for line_item in line_items:
+            product_id = line_item['product_id']
+            variant_id = line_item['variant_id']
+            variant = shopify.Variant(dict(product_id=product_id, id=variant_id, inventory_quantity=0, inventory_policy="deny"))
+            variant.save()
+
+        response.status_code = 200
+    else:
+        response.status_code = 500
+    return response
+
 
 def ajax(request, product_id, variant_id):
-
     SHOP_NAME = "bamboletta"
     API_PASSWORD = "3921846ab0948645fce4901a81685176"
-
     session = shopify.Session(SHOP_NAME)
     session.token = API_PASSWORD
     shopify.ShopifyResource.activate_session(session)
-
     variant = shopify.Variant(dict(product_id=product_id, id=variant_id, inventory_quantity=0, inventory_policy="deny"))
     variant.save()
     return HttpResponse(200)
         }
     }
 
-try:
-    import local_settings
-except ImportError:
-    pass
 
-    SITE_ID = 1
+
+SITE_ID = 1
 
 # If you set this to False, Django will make some optimizations so as not
 # to load the internationalization machinery.
         },
     }
 }
+
+try:
+    from local_settings import *
+except ImportError:
+    pass