/spree_newsletter

Primary LanguageRubyBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

SpreeNewslatter

Introduction goes here.

Installation

Add spree_newslatter to your Gemfile:

gem 'spree_newslatter'

Bundle your dependencies and run the installation generator:

bundle
bundle exec rails g spree_newslatter:install

Testing

First bundle your dependencies, then run rake. rake will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using rake test_app.

bundle
bundle exec rake

When testing your applications integration with this extension you may use it's factories. Simply add this require statement to your spec_helper:

require 'spree_newslatter/factories'

Copyright (c) 2016 [name of extension creator], released under the New BSD License

Script to generate cvs

base =  Spree::Taxonomy.all.pluck :name
taxonomies = Spree::Taxon.where name: base
taxonomies.size

headers = taxonomies.pluck(:name)
lines = []

Spree::NewslatterUser.includes(:taxons).all.each do |user|
  line = "#{user.email},"

  taxonomies.each do |taxonomy|
    if user.taxons.pluck(:id).include?(taxonomy.id)
      line << "1"
    end
    line << ","
  end
  lines << line
end

headers_write = "Email,#{headers.join(",")}\n\r"
lines_write = "#{lines.join("\n\r")}\n\r"

filename = "public/emails.csv"

f = File.open(filename, 'w')
f.write headers_write
f.write lines_write
f.close