Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Optimize checking if product is in stock in template
Marcin Gębalac96b234474fd
diff --git a/saleor/product/templates/product/details.html b/saleor/product/templates/product/details.htmlindex 0ccb2a99bd..4efdba300a 100644--- a/saleor/product/templates/product/details.html+++ b/saleor/product/templates/product/details.html@@ -23,48 +23,50 @@{{ product }}</h1>- {% if product.is_in_stock %}- {% with price_range=product|discounted_price_range:request.discounts undiscounted=product.get_price_range %}- {% with discount=undiscounted.min_price|price_difference:price_range.min_price %}- <p class="lead" itemprop="offers" itemscope itemtype="http://schema.org/Offer"- {% if undiscounted.min_price != price_range.min_price %}- <span class="price undiscounted">{% price_range undiscounted %}</span>- <br>- <span class="price">{% price_range price_range %}</span>- <br>- <small class="label label-success">{% trans "You save" %} {% gross discount %}</small>- {% else %}- <span class="price">{% price_range price_range %}</span>- {% endif %}- </p>+ {% with in_stock=product.is_in_stock %}+ {% if in_stock %}+ {% with price_range=product|discounted_price_range:request.discounts undiscounted=product.get_price_range %}+ {% with discount=undiscounted.min_price|price_difference:price_range.min_price %}+ <p class="lead" itemprop="offers" itemscope itemtype="http://schema.org/Offer"+ {% if undiscounted.min_price != price_range.min_price %}+ <span class="price undiscounted">{% price_range undiscounted %}</span>+ <br>+ <span class="price">{% price_range price_range %}</span>+ <br>+ <small class="label label-success">{% trans "You save" %} {% gross discount %}</small>+ {% else %}+ <span class="price">{% price_range price_range %}</span>+ {% endif %}+ </p>+ {% endwith %}{% endwith %}- {% endwith %}- {% endif %}+ {% endif %}- <hr>+ <hr>- <div class="visible-xs">- <img class="img-responsive" src="{{ product.images.first.image.thumbnail.750x750 }}" alt="">+ <div class="visible-xs">+ <img class="img-responsive" src="{{ product.images.first.image.thumbnail.750x750 }}" alt="">- <hr>- </div>+ <hr>+ </div>- {% if product.is_in_stock %}- {% block orderform %}- <form role="form" class="product-form form-vertical" method="post" action=".">- {% csrf_token %}- {{ form|as_vertical_form }}+ {% if in_stock %}+ {% block orderform %}+ <form role="form" class="product-form form-vertical" method="post" action=".">+ {% csrf_token %}+ {{ form|as_vertical_form }}- <div class="form-group">- <button class="btn btn-lg btn-block btn-primary">- {% trans "Add to cart" %}- </button>- </div>- </form>- {% endblock %}- {% else %}- <p class="alert alert-warning">{% trans "This product is currently <strong>unavailable</strong>." %}</p>- {% endif %}+ <div class="form-group">+ <button class="btn btn-lg btn-block btn-primary">+ {% trans "Add to cart" %}+ </button>+ </div>+ </form>+ {% endblock %}+ {% else %}+ <p class="alert alert-warning">{% trans "This product is currently <strong>unavailable</strong>." %}</p>+ {% endif %}+ {% endwith %}<hr>