Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Display variant image instead of products'

Pacu223cc54f28b4e
diff --git a/saleor/product/models.py b/saleor/product/models.py
index ce7570276a..ee422daf99 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -269,6 +269,9 @@ class ProductVariant(models.Model):
return smart_text(product_display)
def get_first_image(self):
+ images = list(self.images.all())
+ if images:
+ return images[0].image
return self.product.get_first_image()
def get_ajax_label(self, discounts=None):
diff --git a/templates/checkout/index.html b/templates/checkout/index.html
index 593ec56b83..9499112124 100644
--- a/templates/checkout/index.html
+++ b/templates/checkout/index.html
@@ -42,8 +42,8 @@
<div class="row">
<div class="col-7 cart__line__product">
<a class="link--clean" href="{{ line.variant.get_absolute_url }}">
- <img class="lazyload lazypreload" data-src="{% get_thumbnail line.variant.product.images.first.image method="crop" size=60 %}"
- data-srcset="{% get_thumbnail line.variant.product.images.first.image method="crop" size=60 %} 1x, {% get_thumbnail line.variant.product.images.first.image method="crop" size=120 %} 2x"
+ <img class="lazyload lazypreload" data-src="{% get_thumbnail line.variant.get_first_image method="crop" size=60 %}"
+ data-srcset="{% get_thumbnail line.variant.get_first_image method="crop" size=60 %} 1x, {% get_thumbnail line.variant.get_first_image method="crop" size=120 %} 2x"
alt="">
<p>{{ line.variant.product.translated }}<br><small>{{ line.variant.translated }}</small></p>
</a>
diff --git a/templates/order/_ordered_items_table.html b/templates/order/_ordered_items_table.html
index afdfe2bf54..8a0ad28b5a 100644
--- a/templates/order/_ordered_items_table.html
+++ b/templates/order/_ordered_items_table.html
@@ -3,7 +3,7 @@
{% load i18n_address_tags %}
{% load placeholder %}
{% load price from taxed_prices %}
-{% load product_first_image from product_images %}
+{% load get_thumbnail from product_images %}
{% if order.user == user %}
<div class="order-details__addresses">
@@ -50,8 +50,8 @@
<div class="row">
<div class="col-md-8">
<a class="link--clean" href="{% if line.variant %}{{ line.variant.get_absolute_url }}{% endif %}">
- <img data-src="{% product_first_image line.variant.product size=60 method="crop" %}"
- data-srcset="{% product_first_image line.variant.product size=60 method="crop" %} 1x, {% product_first_image line.variant.product size=120 method="crop" %} 2x"
+ <img data-src="{% get_thumbnail line.variant.get_first_image size=60 method="crop" %}"
+ data-srcset="{% get_thumbnail line.variant.get_first_image size=60 method="crop" %} 1x, {% get_thumbnail line.variant.get_first_image size=120 method="crop" %} 2x"
class="float-left lazyload lazypreload"
src="{% placeholder size=60 %}">
<span class="order-details__product__description">{{ line.translated_product_name|default:line.product_name }}</span>