def get_cart_from_request(request, cart_queryset=Cart.objects.all()):
 discounts = request.discounts
 if request.user.is_authenticated():
  cart = get_user_cart(request.user, cart_queryset)
  user = request.user
 else:
  token = request.get_signed_cookie(Cart.COOKIE_NAME, default=None)
  cart = get_anonymous_cart_from_token(token, cart_queryset)
  user = None
 if (cart is not None):
  cart.discounts = discounts
  return cart
 else:
  return Cart(user=user, discounts=discounts)

def get_cart_from_request ( request , cart_queryset = Cart . objects . all ( ) ) : discounts = request . discounts if request . user . is_authenticated ( ) : cart = get_user_cart ( request . user , cart_queryset ) user = request . user else : token = request . get_signed_cookie ( Cart . COOKIE_NAME , default = None ) cart = get_anonymous_cart_from_token ( token , cart_queryset ) user = None if ( cart is not None ) : cart . discounts = discounts return cart else : return Cart ( user = user , discounts = discounts )
get cart from database or return unsaved cart :type cart_queryset: saleor .