ShopFelixGray / spree_mirakl_api

Spree Integration with Mirakl Marketplace

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SpreeMiraklApi

Spree intergration for Mirakl API. Currently only processes orders and brings them into the system and allows you to ship. Each Mirakl Store Requires a user to be assigned to it. All orders from that store will be placed under that user.

Installation

  1. Add this extension to your Gemfile with this line:
gem 'spree_mirakl_api', github: 'https://github.com/ShopFelixGray/spree_mirakl_api', branch: 'master'

The branch option is important: it must match the version of Spree you're using. For example, use 3-1-stable if you're using Spree 3-1-stable or any 3.1.x version.

  1. Install the gem using Bundler:
bundle install
  1. Copy & run migrations
bundle exec rails g spree_mirakl_api:install
  1. Restart your server

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

  1. Setup up Mirakl Payment Method

The gem uses a payment method that must be called Mirakl to process payments. After installing the gem please make a payment method of type Mirakl called Mirakl

TODOs

Shipping Mapper Currently cause we assume shipping is free refunds dont give shipping back We also need to update the return reasons UI to make it more spree like adjustment calculator

Setup Cron Jobs

To pull in the orders a cron job is required. There is 3 different services that should be run separately of each other.

  1. Mirakl::OrderProcessing.new(stores: Spree::MiraklStore.active)

This service gets all orders waiting acceptance and checks if they can be fully accepted. If one line item cant be meet the whole order is rejected. It also takes any orders ready to be shipped and builds the order in the spree store. An example worker for this would be

  service = Mirakl::OrderProcessing.new(stores: Spree::MiraklStore.active)
  unless service.call
    logger.debug service.errors
    Rollbar.error(Exception.new(service.errors.to_s))
  end
end

Service.errors will return an array of errors and call will return false if there is any errors

  1. Mirakl::UpdateInventory.new({store: store})

This service syncs a single stores inventory. It takes a single store because it is reused on index. It will use the spree call total_on_hand for a given sku to update Mirakls offerings. An example for a worker would be

  Spree::MiraklStore.active.each do |store|
    service = Mirakl::UpdateInventory.new({store: store})
    unless service.call
      raise Exception.new("Issue with updating inventory for store: #{store.shop_id}")
    end
  end
end

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_mirakl_api/factories'

Contributing

If you'd like to contribute, please take a look at the instructions for installing dependencies and crafting a good pull request.

Copyright (c) 2020 Mike Walters, released under the New BSD License

About

Spree Integration with Mirakl Marketplace

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


Languages

Language:Ruby 88.4%Language:HTML 9.3%Language:JavaScript 1.8%Language:CSS 0.5%