GithubHelp home page GithubHelp logo

spark-solutions / spree_shopify_importer Goto Github PK

View Code? Open in Web Editor NEW
2.0 12.0 0.0 4.74 MB

Migrate your Shopify store to Spree

License: BSD 3-Clause "New" or "Revised" License

Ruby 99.83% JavaScript 0.09% CSS 0.09%

spree_shopify_importer's Introduction

Build Status Code Climate Test Coverage

Spree Shopify Importer

The Spree Shopify Importer gem allows you to easily import data from Shopify store to Spree application. It's compatible with Spree 4 and above.

Behind-the-scenes, this extension is using Shopify API gem.

Currently, it's in version 0.1.0. It has been tested with thousands of real life orders, but we welcome new pull requests!

Installation

  1. Add this extension to your Gemfile with this:
gem 'spree_shopify_importer', github: 'spark-solutions/spree_shopify_importer'
gem 'spree_auth_devise'
  1. Install the gem using Bundler:
bundle install
  1. Copy & run migrations:
bundle exec rails g spree_shopify_importer:install
  1. Restart your server:

If your server was running, restart it so that it can find the assets properly.

  1. Setup credentials and change default values if needed.

Getting Started

We are recommending using sidekiq for background processing with this stack of gems:

gem 'sidekiq'
gem 'sidekiq-limit_fetch'
gem 'sidekiq-unique-jobs'

We also recommend having a limit 2 for import queue, due to API limit. Default queue name is default but it can be changed in Spree::AppConfiguration under shopify_import_queue key.

Default values

All default values are saved in Spree::AppConfiguration

  • ShopifyAPI credentials - used for api authorization.
    • shopify_api_key - nil
    • shopify_password - nil
    • shopify_shop_domain - nil
    • shopify_token - nil
    • shopify_api_version - nil
  • Import Rescue Limit - used for retrying API errors, for example API limit hit.
    • shopify_rescue_limit - 5
  • Import Queue Name
    • shopify_import_queue - 'default'

Import

Currently, you need to have access to the console to start the import.

  1. To start import, in console run:

With default values

 SpreeShopifyImporter::Invoker.new.import!

or with credentials.

 SpreeShopifyImporter::Invoker.new(credentials).import!

Where credentials could have two formats:

    {
      api_key: 'api_key', 
      password: 'password',
      shop_domain: 'shop_domain',
      api_version: 'api_version'
    }

or

    {
      token: 'token',
      shop_domain: 'shop_domain'
    }

Import Model

  1. SpreeShopifyImporter::DataFeed - this model contains copy of JSON imported from shopify and association to spree object.

Import Services

Import services are divided into four main parts. Each of them could be customized.

  1. Data Fetchers are services which are fetching products, users, orders and collections from Shopify.

  2. Importers are services which are saving Shopify data feeds (as shadow copy of import), and starting a create or update action for spree object.

  3. Data Savers are services which are saving spree objects, each of them has a parser method which can be overridden to change update/create attributes and associations.

  4. Data Parsers are services which are changing Shopify data to spree data.

Send reset password links to users

If your application uses devise as authentication system you can run next worker:

SpreeShopifyImporter::Users::ResetPasswordJob.new.perform(Spree::User.all)

or find users that you need using where and then run worker:

users_to_reset = Spree::User.where(id: [1, 2, 3, 4])
SpreeShopifyImporter::Users::ResetPasswordJob.new.perform(users_to_reset)

It's important to pass relation not array into worker.

Testing

To run all the tests for the build, clone the repo and run:

bundle exec rake

This will generate a dummy app for testing, run rubocop style checker and rspec tests.

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

require 'spree_shopify_importer/factories'

Contributing

We welcome new pull requests!

License

Spree Shopify Importer is copyright © 2015-2019 Spark Solutions Sp. z o.o.. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About Spark Solutions

Spark Solutions

Spree Shopify Importer is maintained and funded by Spark Solutions Sp. z o.o. The names and logos are trademarks of Spark Solutions Sp. z o.o.

We are passionate about open source software. We are available for hire.

spree_shopify_importer's People

Contributors

argonus avatar vfonic avatar kgorazd avatar joaray avatar pszyszkaspark avatar damianlegawiec avatar jeniaefimov avatar mafi88 avatar

Stargazers

 avatar  avatar

Watchers

 avatar Bogusław Tolarz avatar James Cloos avatar Szymon Iwacz avatar Olga Leonteva avatar Mateusz Jan Mateja avatar  avatar Seb avatar Mike Faber avatar Dardan Lladrovci avatar  avatar Aleksandar Petrushev avatar

spree_shopify_importer's Issues

Rspec problems

Investigate the problem with VCR in tests:

  • integration_spec.rb
  • delivery_profile_spec.rb

Order #1002 differences

Order #1002 is partially fulfilled and has 2 products in Shopify. In Spree Order view, that Order has only 1 product.

Fix taxes in imported orders

Before, taxes were just imported from order ("fake" tax_category and tax_rate were created during order import process). Since tax_category and tax_rate are imported from Shopify, we have to implement a connection between them and order taxes (for each line_item, not just for whole order - like it was).

Import shipments

  1. Now shipments are imported as "Shopify fulfillments" since it is logic analog of shipment
  2. In Shopify fulfillment is created after shipping, in Spree shipment is created on address phase of order (or similarly) and just has a suitable state (firstly pending, after payment -> ready, and so on), though.
  3. That's why shipments in importer should be created apart of fulfillment (maybe based on line_items, or per order with line_items - to consider and verify) and just take the state from fulfillment.

Error when importing orders with pending payment

Retro steps:

  1. open console of the shop (locally or on Heroku)
  2. set credentials and connect with Shopify API:
    api_key = ... password = ... shop_domain = ... api_version = ...

credentials = { api_key: api_key, password: password, shop_domain: shop_domain, api_version: api_version }
SpreeShopifyImporter::Connections::Client.instance.get_connection(credentials)

  1. Try to import an order with pending payment e.g. 1035:

resource = ShopifyAPI::Order.find(1995375247459) SpreeShopifyImporter::Importers::OrderImporter.new(resource.attributes.to_json).import!

  1. observe the error:

ActiveRecord::RecordInvalid (Validation failed: State is invalid, Payment State is not included in the list)

Fix all # TODO:

Before implementing new features I think it's a time to fix problems of past

`bundle exec rake` breaks with missing 'sqlite3' gem

When I run: bundle exec rake, the task fails because there's no sqlite3 gem set as dependency, but sqlite3 is set as default gem.

@Argonus can you help me resolve this? You mentioned that sqlite is not fully supported? Should we use postgres (or mysql) as default or just add back sqlite3 as dev dependency?

Collect constants in one place

Now, we have a mess with a constants in this gem, I think the best way is:

  • create a folder app/constants
  • create few modules inside an app
  • move some strings to constants into this module
  • in code reviews check that all strings are constants and located in correct place

Fix import of delivery_profile

Delivery_profiles should be imported for each variant or a product if there is no variant (when it is a master variant).

Rubocop

  • add more rubocop rules (we can check .rubocop.yml of any of the big and great projects)
  • start to fix files that are in .rubocop_todo.yml
  • add rule RSpec/LetSetup

Handling temp_passwords for imported Users

We import users but we don’t import passwords. Users need to have the possibility to login to spree after import, so we have to send them temporary passwords after whole import is completed

Why we store OptionType and OptionValue with lowercase name?

I just noticed that we always downcase option types and option values. On this way we're losing some information from Shopify and make the resulting options always presented/stored in downcase.

I think we should store the options in the same case as they come from Shopify.

/cc @Argonus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.