def fb_add_order(request, store_slug, product_slug): shop = plata.shop_instance() product = get_object_or_404(Product, slug=product_slug, store__slug=store_slug) if request.method == "POST": form = OrderItemForm(data=request.POST) if form.is_valid(): order = shop.order_from_request(request,create=True) stock_change = product.stock_change(order) quantity = form.cleaned_data["quantity"] if quantity > stock_change: data = {"success":False,"product_slug":product.slug} '''messages.error(request, "I can only make %d more %ss today" %(product.items_in_stock, product.name)) return render(request, "imly_product_detail.html", {"object":product, "form":form})''' return HttpResponse(simplejson.dumps(data),mimetype="application/json") order.modify_item(product, relative=form.cleaned_data["quantity"]) try: messages.success(request,"The cart has been updated") except ValidationError, e: if e.code == "order_sealed": pass else: raise #return redirect("plata_shop_cart") data = {"success":True,"count":order.items.count(),"product":product.name.lower(),"product_slug":product.slug, "items_in_stock":product.items_in_stock - quantity,"store":product.store.name.lower(),"quantity":quantity,"image":product.image_thumbnail_mini.url} return HttpResponse(simplejson.dumps(data),mimetype="application/json")
return render(request, "imly_product_detail.html", {"object":product, "form":form})''' return HttpResponse(simplejson.dumps(data),mimetype="application/json") order.modify_item(product, relative=form.cleaned_data["quantity"]) try: messages.success(request,"The cart has been updated") except ValidationError, e: if e.code == "order_sealed": pass else: raise #return redirect("plata_shop_cart") data = {"success":True,"count":order.items.count(),"product":product.name.lower(),"product_slug":product.slug, "items_in_stock":product.items_in_stock - quantity,"store":product.store.name.lower(),"quantity":quantity,"image":product.image_thumbnail_mini.url} return HttpResponse(simplejson.dumps(data),mimetype="application/json") else: form = OrderItemForm() return render(request, "fb_product_detail.html", {"object":product, "form":form}) def fb_one_step_checkout(request): shop = plata.shop_instance() order = shop.order_from_request(request) if order: order.data["from_facebook"] = True #to check whether refering page is from facebook or imly #store = order.storeorder_set.get(order=order).store page_info=request.fb_session.signed_request['page'] #page = Page.objects.get(pk=page_info['id']) store = Store.objects.get(page=page_info["id"]) try: store_order = order.storeorder_set.get(store=store).store_items