Sendy woudln't be the Mailchimp killer without a proper Shopify integration. Here's a fork of ridem's Shopify gem, updated for a modern install of Ruby.
NB: The script always keep in sync Shopify's accepts_marketing field with Sendy's unsubscribed field. I added custom fields like country and order count as an example of what we can do with it.
First make sure that you have Ruby installed with the following gems:
activerecord
, protected_attributes_continued
, shopify_api
, yaml
, mysql2
If you install them with RVM then you'll get the needed depenedencies as well.
- Put those two files in the same folder, from which you will need to run the script (for instance
/home/ubuntu/tasks/
) - Edit them to match your config
- Make sure you set the right
custom_fields
variable line 30. If you don't have any custom field on your sendy install, make it an empty string.
Simply run ruby shopify_customers.rb
If you want to run this task periodically (e.g. every two hours), you can set up a cron task:
crontab -e
- Add those lines (note that we update the PATH to get the right ruby environment - that one corresponds to a standard rbenv install):
HOME=/home/ubuntu/tasks/
PATH=/home/ubuntu/.rbenv/plugins/ruby-build/bin:/home/ubuntu/.rbenv/shims:/home/ubuntu/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
0 */2 * * * ruby shopify_customers.rb > /dev/null 2>&1
minimal changes from the original:
changed line 3 above to:
require 'protected_attributes_continued'
so that it was compatible with my version of Rubyand the Shopify API now requires you to declare a version. Do that at line 22 like this:
ShopifyAPI::Base.api_version = '2021-07' # find the latest stable api_version here: https://shopify.dev/concepts/about-apis/versioning