Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Merge branch 'master' into demo-store
Artur Smęt5321e479bad2
diff --cc saleor/cart/views.pyindex fcaea41f5d,2d3f9771b5..886ecf57e2--- a/saleor/cart/views.py+++ b/saleor/cart/views.py@@@ -71,11 -57,9 +71,11 @@@ def update(request, cart, variant_id)discounts=discounts)if form.is_valid():form.save()- response = {'productId': variant_id,+ response = {'variantId': variant_id,'subtotal': 0,- 'total': 0}+ 'total': 0,+ 'cart': cart.quantity,+ 'cart_length': len(cart)}updated_line = cart.get_line(form.cart_line.variant)if updated_line:response['subtotal'] = currencyfmt(diff --cc saleor/search/views.pyindex df8302e7b2,3a5c8ed5d7..73857c6963--- a/saleor/search/views.py+++ b/saleor/search/views.py@@@ -23,14 -23,11 +23,15 @@@ def search(request)if form.is_valid():visible_products = products_with_details(request.user)results = form.search(model_or_queryset=visible_products)+ results = products_with_availability(+ results, discounts=request.discounts,+ local_currency=request.currency)+ results = list(results)- page = paginate_results(results, request.GET, settings.PAGINATE_BY)+ query = form.cleaned_data.get('q', '')else:- page = form.no_query_found()- query = form.cleaned_data['q']+ results = []+ query = ''+ page = paginate_results(results, request.GET, settings.PAGINATE_BY)ctx = {'query': query,'results': page,diff --cc saleor/static/js/cart.jsindex 0000000000,f56425f05d..e69de29bb2mode 000000,100644..100644--- a/saleor/static/js/cart.js+++ b/saleor/static/js/cart.jsdiff --cc templates/cart/index.htmlindex d070445526,1f9d269618..f85def8259--- a/templates/cart/index.html+++ b/templates/cart/index.html@@@ -7,119 -7,105 +7,119 @@@{% block title %}{% trans "Your cart" %} — {{ block.super }}{% endblock %}{% block breadcrumb %}- {{ block.super }}-<li><a href="{% url 'cart:index' %}">{% trans "Cart" %}</a></li>+<ul class="breadcrumbs list-unstyled">+ <li><a href="/">{% trans "Home" %}</a></li>+ <li><a href="{% url 'cart:index' %}">{% trans "Cart" %}</a></li>+</ul>{% endblock breadcrumb %}-{% block stylesheet %}- {{ block.super }}- {% render_bundle 'cart' 'css' %}-{% endblock stylesheet %}--{% block footer_scripts %}- {{ block.super }}- {% render_bundle 'cart' 'js' %}-{% endblock footer_scripts %}-{% block content %}-{% if cart_lines %}- <table class="table table-striped cart" id="cart-items">- <thead>- <tr>- <th class="col-xs-5 col-sm-2 col-md-1">{% trans "Product" %}</th>- <th class="col-sm-5 hidden-xs"></th>- <th class="col-xs-6 col-sm-3 col-md-2">{% trans "Quantity" %}</th>- <th class="col-sm-1 hidden-xs text-right">{% trans "Price" %}</th>- <th class="col-xs-1 text-right">{% trans "Subtotal" %}</th>- </tr>- </thead>- <tfoot>- <tr>- <td class="hidden-xs" colspan="2"></td>- <td class="col-xs-9 col-md-9 text-right lead" colspan="2">{% trans "Total" %}:- <td class="col-xs-3 col-md-2 text-right lead">- <span class="cart-total" data-value="{% gross cart_total %}"{% if local_cart_total %} data-value-local="{% gross local_cart_total %}"{% endif %}>- {% spaceless %}- {% gross cart_total html=True %}- {% if local_cart_total %}- <br>- <small class="text-info">- ≈- {% gross local_cart_total html=True %}- </small>- {% endif %}- {% endspaceless %}- </span>- </td>- </tr>- </tfoot>- <tbody>- {% for line in cart_lines %}- <tr class="cart-item">- <td class="hidden-xs">- <a href="{{ line.variant.get_absolute_url }}">- {% if line.variant.product.images.first %}- <img class="cart-item-image" itemprop="image" src="{{ line.variant.product.images.first.image.crop.100x100 }}" alt="">- {% else %}- <img class="cart-item-image" src="{% static 'images/product-image-placeholder-small.png' %}" alt="">- {% endif %}- </a>- </td>- <td>- <a href="{{ line.variant.get_absolute_url }}">- {{ line.variant.product }} - {{ line.variant.display_variant }}- </a>- </td>- <td>- <div class="cart-item-amount">- <form role="form" action="{% url "cart:update-line" variant_id=line.variant.pk %}" method="post" class="form-cart">- <div class="input-group cart-item-quantity js-hidden{% if form.quantity.errors %} has-error{% endif %}">- {{ line.form.quantity }}- <span class="input-group-btn">- <button class="btn btn-info" type="submit">{% trans "Update" %}</button>- </span>- </div>- {% if line.form.quantity.errors %}- {% for error in form.quantity.errors %}- <span class="text-danger">{{ error }}</span>- {% endfor %}- {% endif %}- {% csrf_token %}- </form>-- <button type="submit" class="btn btn-link btn-sm cart-item-remove">- <span class="text-muted">{% trans "Remove from cart" %}</span>- </button>- </div>- </td>- <td class="text-right hidden-xs">{% gross line.get_price_per_item html=True %}</td>- <td class="text-right cart-item-subtotal" data-variant-id="{{ line.variant.pk }}">{% gross line.get_total html=True %}</td>- </tr>+<div class="alert alert-success hidden-xs-up remove-product-alert">+ {% trans "Product has been deleted from cart" %}+ <button type="button" class="close close-msg" aria-hidden="true">×</button>+</div>+<div class="cart">+ {% if cart_lines %}+ <div class="cart__table-header hidden-sm-down">+ <div class="row">+ <div class="col-md-6">+ <small>{% trans "Product" %}</small>+ </div>+ <div class="col-md-2">+ <small>{% trans "Quantity" %}</small>+ </div>+ <div class="col-md-2">+ <small>{% trans "Price" %}</small>+ </div>+ <div class="col-md-2">+ <small>{% trans "Delete" %}</small>+ </div>+ </div>+ </div>+ {% for line in cart_lines %}+ <div class="cart__line">+ <div class="row">+ <div class="col-md-6 col-xs-9 cart__line__product">+ <a href="{{ line.variant.get_absolute_url }}">+ {% if line.variant.product.images.first %}+ <img class="cart-item-image" itemprop="image" src="{{ line.variant.product.images.first.image.crop.60x60 }}" alt="">+ {% else %}+ <img class="cart-item-image" src="{% static 'images/product-image-placeholder-small.png' %}" alt="">+ {% endif %}- <h3>{{ line.variant.product }}++ <h3>{{ line.variant.product }}+ <br><small>{{ line.variant.display_variant }}</small></h3>+ </a>+ </div>+ <div class="cart__line__quantity col-md-2 col-xs-3">+ <form role="form" action="{% url "cart:update-line" variant_id=line.variant.pk %}" method="post" class="form-cart" >+ <div class="{% if form.quantity.errors %} has-error{% endif %}" tabindex="-1">+ {{ line.form.quantity }}+ </div>+ {% csrf_token %}+ </form>+ <small class="cart__line__quantity-error text-danger"></small>+ </div>+ <div class="cart-item-subtotal col-md-2 col-xs-8" data-product-id="{{ line.variant.pk }}">+ <h3 class="float-xs-left float-sm-right">{% gross line.get_total html=True %}</h3>+ </div>+ <div class="col-md-2 col-xs-4">+ <img class="cart-item-delete" src="{% static 'img/icon_delete.svg' %}">+ </div>+ </div>+ </div>+ {% endfor %}+ <div class="cart__total">+ <div class="row">+ <div class="col-xs-6">+ <h3>{% trans "Subtotal" %}</h3>+ <p>({% trans "Delivery claculated on checkout" %})</p>+ </div>+ <div class="col-md-2 offset-md-2 col-xs-6">+ <h3 class="cart-total" data-value="{% gross cart_total %}"{% if local_cart_total %} data-value-local="{% gross local_cart_total %}"{% endif %}>+ {% spaceless %}+ {% gross cart_total html=True %}+ {% if local_cart_total %}+ <br>+ <small class="text-info">+ ≈+ {% gross local_cart_total html=True %}+ </small>+ {% endif %}+ {% endspaceless %}+ </h3>+ </div>+ </div>+ </div>+ <div class="cart__checkout row">+ <div class="col-md-12">+ <a href="{% url "checkout:login" %}" class="btn primary float-md-right">{% trans "Checkout" %}</a>+ </div>+ </div>+ <div class="cart__delivery-info">+ <div class="deliveryform" data-csrf="{{ csrf_token }}">+ <h3>{% trans "Delivery options to" %} {{ country_form }}</h3>+ </div>+ <div class="col-md-5 ">+ <div class="cart__delivery-info__list row">+ <div class="col-xs-6 cart__delivery-info__method">- {% for option in default_country_options %}++ {% for option in default_country_options %}+ <p>{{ option.shipping_method__name }}</p>+ {% endfor %}+ </div>+ <div class="col-xs-6 cart__delivery-info__price">- {% for option in default_country_options %}++ {% for option in default_country_options %}+ <p>{% gross option.price %}</p>{% endfor %}- </tbody>- </table>- <div class="form-group">- <div>- <a href="{% url "checkout:index" %}" class="btn btn-primary btn-lg pull-right">{% trans "Proceed to checkout" %}</a>+ </div></div>+ </div></div>-{% else %}-<p>- {% trans 'Your cart is empty' %}-</p>-{% endif %}+ {% else %}+ <div class="cart__empty">+ <img src="{% static 'img/pirate_cart.png' %}" srcset="{% static 'img/pirate_cart.png' %} 1x, {% static 'img/pirate_cart2x.png' %} 2x">+ <h2>{% trans "There are no products in your shopping cart." %}</h2>+ <a href="/" class="btn primary">{% trans "Check out Our sales" %}</a>+ </div>+ {% endif %}+ </div>{% endblock content %}diff --cc tests/test_cart.pyindex 5d398171ff,9f5e6c54c8..7b1feedbf8--- a/tests/test_cart.py+++ b/tests/test_cart.py@@@ -8,9 -8,9 +8,11 @@@ from babeldjango.templatetags.babel impfrom django.contrib.auth.models import AnonymousUserfrom django.core.exceptions import ObjectDoesNotExistfrom mock import MagicMock, Mock++from saleor.cart.context_processors import cart_counterfrom satchless.item import InsufficientStock+ from prices import Price+from saleor.cart import forms, utilsfrom saleor.cart.models import Cart@@@ -530,5 -531,13 +539,13 @@@ def test_cart_summary_page(client, proddef test_cart_summary_page_empty_cart(client, request_cart):response = client.get('/cart/summary/')assert response.status_code == 200- content = response.content.decode('utf-8')- assert json.loads(content) == {}+ data = response.context+ assert data['quantity'] == 0+++ def test_total_with_discount(client, sale, request_cart, product_in_stock):+ sales = Sale.objects.all()+ variant = product_in_stock.variants.get()+ request_cart.add(variant, 1)+ line = request_cart.lines.first()+ assert line.get_total(discounts=sales) == Price(currency="USD", net=5)