Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

ADMIN UI - Use svg for missing image (#11296)

Matthew Kennedy73571eb2d6c0
diff --git a/backend/app/assets/images/noimage/backend-missing-image.svg b/backend/app/assets/images/noimage/backend-missing-image.svg
new file mode 100644
index 0000000000..5642c39ef1
--- /dev/null
+++ b/backend/app/assets/images/noimage/backend-missing-image.svg
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-image" viewBox="0 0 16 16">
+ <path d="M6.002 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/>
+ <path d="M2.002 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2h-12zm12 1a1 1 0 0 1 1 1v6.5l-3.777-1.947a.5.5 0 0 0-.577.093l-3.71 3.71-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12V3a1 1 0 0 1 1-1h12z"/>
+</svg>
diff --git a/backend/app/assets/stylesheets/spree/backend/shared/_base.scss b/backend/app/assets/stylesheets/spree/backend/shared/_base.scss
index 29263e4b1f..d277a59a31 100644
--- a/backend/app/assets/stylesheets/spree/backend/shared/_base.scss
+++ b/backend/app/assets/stylesheets/spree/backend/shared/_base.scss
@@ -28,6 +28,54 @@ figure.admin-img-holder {
}
}
+div.admin-product-image-container {
+ border: 1px solid $gray-500;
+ background-color: #fefefe;
+ border-radius: $border-radius;
+ overflow: hidden;
+ display: flex;
+ justify-content: center;
+ margin: auto;
+
+ img {
+ max-width: 100%;
+ height: auto;
+ align-self: center;
+ transform: scale(1.6);
+ }
+
+ svg {
+ color: $gray-600;
+ align-self: center;
+ }
+
+ &.mini-img {
+ border-radius: $border-radius / 2;
+ width: 24px;
+ height: 24px;
+ }
+
+ &.small-img {
+ border-radius: $border-radius;
+ width: 50px;
+ height: 50px;
+ }
+
+ &.product-img {
+ border-width: 2px;
+ border-radius: $border-radius * 2;
+ width: 100px;
+ height: 100px;
+ }
+
+ &.large-img {
+ border-width: 3px;
+ border-radius: $border-radius * 3;
+ width: 300px;
+ height: 300px;
+ }
+}
+
.js-remove-promo-rule-option-value {
color: $primary !important;
&:hover {
diff --git a/backend/app/views/spree/admin/images/index.html.erb b/backend/app/views/spree/admin/images/index.html.erb
index 88a7b57b1a..40e5c2810d 100644
--- a/backend/app/views/spree/admin/images/index.html.erb
+++ b/backend/app/views/spree/admin/images/index.html.erb
@@ -41,7 +41,9 @@
<% end %>
</td>
<td class="image">
- <%= link_to image_tag(main_app.url_for(image.url(:mini))), main_app.rails_blob_url(image.attachment) %>
+ <div class="admin-product-image-container small-img">
+ <%= link_to image_tag(main_app.url_for(image.url(:mini))), main_app.rails_blob_url(image.attachment) %>
+ </div>
</td>
<% if has_variants %>
<td><%= options_text_for(image) %></td>
diff --git a/backend/app/views/spree/admin/orders/_line_items.html.erb b/backend/app/views/spree/admin/orders/_line_items.html.erb
index 5babb89ceb..95b2c16dd3 100644
--- a/backend/app/views/spree/admin/orders/_line_items.html.erb
+++ b/backend/app/views/spree/admin/orders/_line_items.html.erb
@@ -20,7 +20,7 @@
<% order.line_items.each do |item| %>
<tr class="line-item" id="line-item-<%= item.id %>">
<td class="line-item-image image text-center">
- <%= link_to mini_image(item.variant), edit_admin_product_path(item.variant.product) %>
+ <%= link_to small_image(item.variant), edit_admin_product_path(item.variant.product) %>
</td>
<td class="line-item-name text-center">
<%= link_to item.name, edit_admin_product_path(item.variant.product) %>
diff --git a/backend/app/views/spree/admin/orders/_shipment_manifest.html.erb b/backend/app/views/spree/admin/orders/_shipment_manifest.html.erb
index 4fb7b75b6d..9ac946066f 100644
--- a/backend/app/views/spree/admin/orders/_shipment_manifest.html.erb
+++ b/backend/app/views/spree/admin/orders/_shipment_manifest.html.erb
@@ -1,7 +1,7 @@
<% shipment.manifest.each do |item| %>
<tr class="stock-item" data-item-quantity="<%= item.quantity %>">
<td class="item-image image text-center">
- <%= link_to mini_image(item.variant), edit_admin_product_path(item.variant.product) %>
+ <%= link_to small_image(item.variant), edit_admin_product_path(item.variant.product) %>
</td>
<td class="item-name">
diff --git a/backend/app/views/spree/admin/products/_autocomplete.js.erb b/backend/app/views/spree/admin/products/_autocomplete.js.erb
index c286988cf0..f232f01434 100644
--- a/backend/app/views/spree/admin/products/_autocomplete.js.erb
+++ b/backend/app/views/spree/admin/products/_autocomplete.js.erb
@@ -17,9 +17,13 @@
</nav>
<div class='image'>
{{#if image }}
- <img src='{{image}}' alt='{{ product.attributes.name }}' class='thumbnail rounded border border' />
+ <div class="admin-product-image-container small-img">
+ <img src='{{image}}' alt='{{ product.attributes.name }}' class='thumbnail rounded border border' />
+ </div>
{{ else }}
- <img src='<%= image_path("noimage/small.png") %>' alt='{{product.name }}' class='thumbnail' />
+ <div class="admin-product-image-container small-img">
+ <%= inline_svg_tag "noimage/backend-missing-image.svg", class: "noimage", size: "60%*60%" %>
+ </div>
{{/if}}
</div>
<div class="p-0 pt-1 text-center product-info">
diff --git a/backend/app/views/spree/admin/products/index.html.erb b/backend/app/views/spree/admin/products/index.html.erb
index 1d657150ee..3aa1a38ed1 100644
--- a/backend/app/views/spree/admin/products/index.html.erb
+++ b/backend/app/views/spree/admin/products/index.html.erb
@@ -68,7 +68,7 @@
<tr <%== "style='color: red;'" if product.deleted? %> id="<%= spree_dom_id product %>" data-hook="admin_products_index_rows" class="<%= cycle('odd', 'even') %>">
<td scope="row" class="image">
<%= link_to edit_admin_product_path(product) do %>
- <%= mini_image product %>
+ <%= small_image product %>
<% end %>
</td>
<td><%= link_to product.try(:name), edit_admin_product_path(product) %></td>
diff --git a/backend/app/views/spree/admin/users/items.html.erb b/backend/app/views/spree/admin/users/items.html.erb
index 678c9e1040..243ca05c9c 100644
--- a/backend/app/views/spree/admin/users/items.html.erb
+++ b/backend/app/views/spree/admin/users/items.html.erb
@@ -27,7 +27,7 @@
<tr class="stock-item" data-item-quantity="<%= item.quantity %>">
<td class="order-completed-at"><%= order_time(order.completed_at) if order.completed_at %></td>
<td class="item-image">
- <%= mini_image(item.variant) %>
+ <%= small_image(item.variant) %>
</td>
<td class="item-name">
<%= item.name %>
diff --git a/backend/app/views/spree/admin/variants/_autocomplete.js.erb b/backend/app/views/spree/admin/variants/_autocomplete.js.erb
index 4488c186b0..1d0b3facbd 100644
--- a/backend/app/views/spree/admin/variants/_autocomplete.js.erb
+++ b/backend/app/views/spree/admin/variants/_autocomplete.js.erb
@@ -2,9 +2,13 @@
<div class='variant-autocomplete-item media align-items-center'>
<figure class='variant-image media-left mb-0 mr-3'>
{{#if variant.image }}
- <img src='{{variant.image}}' class="thumbnail mb-0" />
+ <div class="admin-product-image-container small-img">
+ <img src='{{variant.image}}' class="thumbnail mb-0" />
+ </div>
{{ else }}
- <img src='<%= image_path("noimage/mini.png") %>' class="thumbnail mb-0" />
+ <div class="admin-product-image-container small-img">
+ <%= inline_svg_tag "noimage/backend-missing-image.svg", class: "noimage", size: "60%*60%" %>
+ </div>
{{/if}}
</figure>
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index b5856ed6c8..1345239f7b 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -246,11 +246,13 @@ module Spree
options = options.first || {}
options[:alt] ||= product.name
image_path = default_image_for_product_or_variant(product)
- if image_path.present?
- create_product_image_tag image_path, product, options, style
- else
- image_tag "noimage/#{style}.png", options
- end
+ img = if image_path.present?
+ create_product_image_tag image_path, product, options, style
+ else
+ inline_svg_tag "noimage/backend-missing-image.svg", class: "noimage", size: "60%*60%"
+ end
+
+ content_tag(:div, img, class: "admin-product-image-container #{style}-img")
end
end
diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb
index 3f01b32af0..04e58a6dc1 100644
--- a/core/spec/helpers/base_helper_spec.rb
+++ b/core/spec/helpers/base_helper_spec.rb
@@ -128,6 +128,7 @@ describe Spree::BaseHelper, type: :helper do
styles[:very_strange] = '1x1'
styles.merge!(foobar: '2x2')
end
+ allow_any_instance_of(described_class).to receive(:inline_svg_tag).and_return('<svg></svg>')
end
it 'does not raise errors when style exists' do