def post(self, request, *args, **kwargs): title = request.POST.get("title", "") basket = request.basket if not request.customer: return JsonResponse({"ok": False}, status=403) if not title: return JsonResponse( { "ok": False, "error": force_text(_("Please enter a basket title.")) }, status=400) if basket.is_empty: return JsonResponse( { "ok": False, "error": force_text(_("Can't save an empty basket.")) }, status=400) saved_basket = StoredBasket( shop=basket.shop, customer=basket.customer, orderer=basket.orderer, creator=real_user_or_none(basket.creator), currency=basket.currency, prices_include_tax=basket.prices_include_tax, persistent=True, title=title, data=basket.storage.load(basket=basket), product_count=basket.smart_product_count) saved_basket.save() saved_basket.products.set(set(basket.product_ids)) return JsonResponse({"ok": True}, status=200)
def post(self, request, *args, **kwargs): title = request.POST.get("title", "") basket = request.basket if not request.customer: return JsonResponse({"ok": False}, status=403) if not title: return JsonResponse({"ok": False, "error": force_text(_("Please enter a basket title."))}, status=400) if basket.product_count == 0: return JsonResponse({"ok": False, "error": force_text(_("Cannot save an empty basket."))}, status=400) saved_basket = StoredBasket( shop=basket.shop, customer=basket.customer, orderer=basket.orderer, creator=real_user_or_none(basket.creator), currency=basket.currency, prices_include_tax=basket.prices_include_tax, persistent=True, title=title, data=basket.storage.load(basket=basket), product_count=basket.product_count) saved_basket.save() saved_basket.products = set(basket.product_ids) return JsonResponse({"ok": True}, status=200)
def _get_stored_basket(self, basket): request = basket.request basket_get_kwargs = request.session.get(self._get_session_key(basket)) stored_basket = None if basket_get_kwargs: stored_basket = StoredBasket.objects.filter( deleted=False, **basket_get_kwargs).first() if not stored_basket: if basket_get_kwargs: request.session.pop(self._get_session_key(basket), None) stored_basket = StoredBasket( shop=basket.shop, currency=basket.currency, prices_include_tax=basket.prices_include_tax, ) return stored_basket