Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change function name
Adam Bogdał5d7b506eb8ac
diff --git a/saleor/cart/test_cart.py b/saleor/cart/test_cart.pyindex b98248a2af..1a001af94a 100755--- a/saleor/cart/test_cart.py+++ b/saleor/cart/test_cart.py@@ -12,7 +12,8 @@ from satchless.item import InsufficientStockfrom . import Cart, SessionCartfrom . import formsfrom .forms import ReplaceCartLineForm, ReplaceCartLineFormSet-from ..cart.utils import has_available_products, remove_unavailable_products+from ..cart.utils import (+ contains_unavailable_products, remove_unavailable_products)from ..product.models import (ProductVariant, Product)@@ -167,18 +168,18 @@ def test_session_cart_returns_correct_prices():assert cart_price == sessioncart_price-def test_cart_has_unavailable_products():+def test_cart_contains_unavailable_products():cart = Cart(session_cart=SessionCart())cart.add(non_stocked_variant, quantity=100)cart.add(stocked_variant, quantity=12, check_quantity=False)- assert not has_available_products(cart)+ assert contains_unavailable_products(cart)-def test_cart_has_available_products():+def test_cart_contains_only_available_products():cart = Cart(session_cart=SessionCart())cart.add(non_stocked_variant, quantity=100)cart.add(stocked_variant, quantity=10, check_quantity=False)- assert has_available_products(cart)+ assert not contains_unavailable_products(cart)def test_cart_contains_products_on_stock():diff --git a/saleor/cart/utils.py b/saleor/cart/utils.pyindex 1c174217cc..c4943bab96 100644--- a/saleor/cart/utils.py+++ b/saleor/cart/utils.py@@ -1,12 +1,12 @@from satchless.item import InsufficientStock-def has_available_products(cart):+def contains_unavailable_products(cart):try:[item.product.check_quantity(item.quantity) for item in cart]except InsufficientStock:- return False- return True+ return True+ return Falsedef remove_unavailable_products(cart):diff --git a/saleor/cart/views.py b/saleor/cart/views.pyindex edde22ec37..b9c210231e 100755--- a/saleor/cart/views.py+++ b/saleor/cart/views.py@@ -7,13 +7,14 @@ from django.utils.translation import ugettext as _from .forms import ReplaceCartLineFormSetfrom . import Cart-from ..cart.utils import has_available_products, remove_unavailable_products+from ..cart.utils import (+ contains_unavailable_products, remove_unavailable_products)def index(request):cart = Cart.for_session_cart(request.cart, discounts=request.discounts)cart_partitioner = cart.partition()- if not has_available_products(cart):+ if contains_unavailable_products(cart):msg = _('Sorry. We don\'t have that many items in stock. ''Quantity was set to maximum available for now.')messages.warning(request, msg)diff --git a/saleor/checkout/views.py b/saleor/checkout/views.pyindex 4bf288ffc5..68125c9f95 100644--- a/saleor/checkout/views.py+++ b/saleor/checkout/views.py@@ -3,11 +3,11 @@ from django.shortcuts import redirectfrom . import Checkoutfrom ..cart import Cart-from ..cart.utils import has_available_products+from ..cart.utils import contains_unavailable_productsdef details(request, step):- if not request.cart or not has_available_products(+ if not request.cart or contains_unavailable_products(Cart.for_session_cart(request.cart, discounts=request.discounts)):return redirect('cart:index')checkout = Checkout(request)