Module: Admin::BarcodeHelper

Included in:
Spree::Admin::BarcodeController
Defined in:
app/helpers/admin/barcode_helper.rb

Instance Method Summary collapse

Instance Method Details

#append_barcode_to_pdf_for_variant(variant, pdf = empty_pdf) ⇒ Object



23
24
25
26
27
28
29
30
# File 'app/helpers/admin/barcode_helper.rb', line 23

def append_barcode_to_pdf_for_variant(variant, pdf = empty_pdf)
  [ variant.name, variant.options_text, ( variant.price.to_s + current_symbol ) ].each { |item| pdf.text( item ) }
  
  barcode = get_barcode(variant)
  pdf.image( StringIO.new( barcode.to_png(:xdim => 5)) , :width => 50.mm , :height => 10.mm, :margin => 2.mm) if barcode
  pdf.text(' ')
  pdf
end

#current_symbolObject



13
14
15
16
# File 'app/helpers/admin/barcode_helper.rb', line 13

def current_symbol
  @currency = Spree::Config[:currency]
  @currency == 'NGN' ? 'N' : Money::Currency.table.select { |key, value| value.has_value?(@currency) }.values[0][:symbol]
end

#empty_pdf(layout = {}) ⇒ Object



8
9
10
11
# File 'app/helpers/admin/barcode_helper.rb', line 8

def empty_pdf(layout = {})
  layout = { :width => 54, :height => 31, :margin => 1 }.merge(layout)
  pdf = Prawn::Document.new( :page_size => [ layout[:width].mm , layout[:height].mm ] , :margin => layout[:margin].mm )
end

#get_barcode(variant) ⇒ Object



18
19
20
21
# File 'app/helpers/admin/barcode_helper.rb', line 18

def get_barcode(variant)
  code = variant.sku
  return code ? ::Barby::Code128B.new( code  ) : code
end

#product_barcode_urlObject



4
5
6
# File 'app/helpers/admin/barcode_helper.rb', line 4

def product_barcode_url
  "/admin/barcode/code/#{@product.id}"
end