1

I want to attach images to email from products Spreecommerce. But following code doestn't work.

../app/views/order_mailer/confirm_email.html.erb

<% for item in @order.line_items %>

# I'm not sure this product.image containts images. And it doesn't work =(
<%= image_tag image.attachment.url(:product), :itemprop => "image" %>

<%=item.variant.sku %> <%=item.variant.product.name%>
<%= variant_options(item.variant) %>(<%=item.quantity%>) @ <%= number_to_currency item.price %>
<%= number_to_currency(item.price * item.quantity) %>
<% end %>
<%= number_to_currency @order.total %>

More understandable on the following picture.

Can you ask a solution to add image.products to confirmation email?

itsnikolay
  • 17,415
  • 4
  • 65
  • 64

2 Answers2

2

You need to do something like:

<%= image_tag "#{root_url}#{image.attachment.url(:product)}", :itemprop => "image" %>

You're getting a relative image path, not an absolute url.

GeekOnCoffee
  • 1,155
  • 5
  • 15
2

./app/views/order_mailer/confirm_email.html.erb

<%= link_to image_tag('http://mysite.com' + item.variant.images.first.attachment.url(:small)), item.variant.product %>

Add this line in item block and you'll get image in confirmation email.

itsnikolay
  • 17,415
  • 4
  • 65
  • 64