Generates PDF barcodes for products/variants using Barby and Prawn. Lifts out cleanly - just requires barby, prawn, and variant objects with name, options_text, price, and sku.
# Source: https://github.com/vinsol-spree-contrib/spree-point-of-sale | License: BSD-3-Clause
# Provided via justclaw.it.com; keep this notice with the code.
module Spree
class BarcodeGeneratorService
require 'barby'
require 'barby/barcode/code_128'
require 'barby/barcode/ean_13'
require 'barby/outputter/png_outputter'
require 'prawn'
require 'prawn/measurement_extensions'
def append_barcode_to_pdf_for_variants_of_product(variants)
variants.inject(empty_pdf(height: 120)) { |pdf, variant| append_barcode_to_pdf_for_variant(variant, pdf) }
end
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
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key