title: How to add a suffix to an order number in Ruby
body: <p>I have a Ruby file that automatically turns customer orders from an eCommerce site into a CSV file. Different CSV files are printed according to different product vendors.  </p>
  
  <p>I need to add a suffix to the end of the order numbers for different vendors. For example, for a vendor named "Electric Styles", I need to add an <code>-ES</code> to the end of their order numbers. So future order numbers like <code>12345</code> should become <code>12345-ES</code>.</p>
  
  <p>I believe I may have to add an <code>if</code>/<code>else</code> statement to the csvgen.rb file, Something like: </p>
  
  <pre><code>if(vendor = Electric styles){order-number-ES}
  </code></pre>
  
  <p>Not sure how to do this.</p>
  
  <p><a href="https://i.stack.imgur.com/tVfOu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tVfOu.png" alt="enter image description here"></a></p>
  
  <p>process2 file:</p>
  
  <pre><code> This script processes the CSV files, it is executed when a CSV is detected in the Dropbox folder by run.rb 
  # The ~/Dropbox/ORDERS/ARCHIVE/RUNNING/running.csv file contains all orders.
  
  # Electric Styles
  cat ~/Dropbox/*.csv | head -1 &gt; ~/Dropbox/ORDERS/ElectricStyles.csv
  grep -i -E "Electric Styles" *.csv &gt;&gt; ~/Dropbox/ORDERS/ElectricStyles.csv
  
  awk -F, '{$14=$14*0.0352739619;print}' OFS=, ~/Dropbox/ORDERS/ElectricStyles.csv | awk -F, '{$14=$14==int($14)?int($14):int($14)+1}1' OFS=, | sponge ~/Dropbox/ORDERS/ElectricStyles.csv
  
  cp ~/Dropbox/ORDERS/ElectricStyles.csv ~/Dropbox/ORDERS/ElectricStyles.$now.csv
  rm ~/Dropbox/ORDERS/ElectricStyles.csv
  cp ~/Dropbox/ORDERS/ElectricStyles*.csv ~/Dropbox/ORDERS/ElectricStyles/
  cat ~/Dropbox/ORDERS/ElectricStyles/*.csv | sort -u -r &gt; ~/Dropbox/ORDERS/ElectricStyles/RUNNING/running.csv
  </code></pre>
  
  <p>run.rb file:</p>
  
  <pre><code>#!/usr/bin/env ruby
  `dropbox start`
  while 1 == 1 do
    csvexists = !Dir.glob('/root/Dropbox/*.csv').empty?
    sleep(10)
    `proftpd`
    if csvexists == true
          sleep(10)
      `/root/Dropbox/process2`
    else
    end
  end
  </code></pre>
  
  <p>csvgen.rb file:</p>
  
  <pre><code>csvgen.rb
  #!/usr/bin/ruby
  require 'mechanize'
  require 'json'
  require 'csv'
  
  def every_n_seconds(n)
    loop do
      before = Time.now
      yield
      interval = n-(Time.now-before)
      sleep(interval) if interval &gt; 0
    end
  end
  
  every_n_seconds(86400) do
  
  web    = Mechanize.new
  auth   = web.auth('xxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxx', domain = 'xxxxxxxxxxxx.myshopify.com')
  count  = /\:(\d*)/.match(web.get("https://xxxxxxxxxxxx.myshopify.com/admin/orders/count.json").body).to_s.gsub(':','').to_i
  pages  = count / 250 + 1
  orders = []
  
  catch :oldorder do 
    pages.times do |page|
      puts page
      order   = JSON.parse(web.get("https://xxxxxxxxxxx.myshopify.com/admin/orders.json?fields=order_number,created_at,shipping_address,shipping_lines,line_items&amp;page=#{page}&amp;limit=250").body)['orders']
      order.each do |order|
        date  = DateTime.iso8601(order["created_at"]).strftime('%m/%d/%Y')
        today = Date.today.strftime('%m/%d/%Y')
        yestr = Date.today.prev_day.strftime('%m/%d/%Y')
        throw :oldorder if date.to_s != today.to_s &amp;&amp; date.to_s != yestr.to_s
        # throw :oldorder if order["order_number"] &lt; 10000
        cust,ord,ord1 = [],[],[]
        unless order["shipping_lines"] == []
          cust &lt;&lt; order["order_number"]
          cust &lt;&lt; order["shipping_address"]["first_name"]
          cust &lt;&lt; order["shipping_address"]["last_name"]
          cust &lt;&lt; order["shipping_address"]["address1"]
          cust &lt;&lt; order["shipping_address"]["address2"]
          cust &lt;&lt; order["shipping_address"]["city"]
          cust &lt;&lt; order["shipping_address"]["province_code"]
          cust &lt;&lt; order["shipping_address"]["zip"]
          cust &lt;&lt; order["shipping_address"]["country_code"]
          order["line_items"].each do |product|
            ord1 = product["title"],
                   product["variant_title"],
                   product["quantity"],
                   product["vendor"],
                   product["grams"],
                   order["shipping_lines"].first["code"],
                   product["sku"],
                   date
            ord &lt;&lt; cust + ord1
          end
          ord.each do |o|
            orders &lt;&lt; o
          end
        end
      end
    end
  end
  
  puts orders.count
  
  `echo "Order Number,Shipping Address First Name,Shipping Address Last Name,Shipping Address Address 1,Shipping Address Address 2,Shipping Address City,Shipping Address Province code,Shipping Address Postal Code,Shipping Address Country code,Product Title,Product Variant Title,Product Quantity,Brand,Product Weight,Shipping Method,Product SKU,Created at" &gt; /root/Dropbox/file.csv`
  
  orders.each do |o|
    CSV.open("/root/Dropbox/file.csv", "a+:UTF-8") do |csv|
      csv &lt;&lt; o
    end
  end
  
  end
  </code></pre>