Giter VIP home page Giter VIP logo

spree_fx_currency's Introduction

SpreeFxCurrency

Build Status Code Climate

Spree currency converter. Use foreign exchange rates (relative to main currency) mannualy entered in admin area.

Extends spree-contrib/spree_multi_currency.

Adds FX Rates tab: FX Rates tab

FX Rates currencies based from general settings: General settings

Prices are calculated relative to product master price: Product

Prices are recalculated each time when product/variant is changing When FX Rate changes - all products prices are recalculated

Product prices: Product prices

Frontend product example:

Frontend example 1 Frontend example 2 Frontend example 3

FX Rates can be fetched from http://fixer.io/ (JSON API for foreign exchange rates and currency conversion) from the admin area

Installation

  1. Add this extension to your Gemfile with this line:
gem 'spree_fx_currency', github: 'itbeaver/spree_fx_currency', branch: '3-0-stable'

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_fx_currency:install
  1. Restart your server

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

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

Don't forget to run spree_multi_currency generator in spec/dummy directory

bundle exec rails g spree_multi_currency:install

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) 2016 Artem Russkikh, released under the New BSD License

spree_fx_currency's People

Contributors

artem-russkikh avatar misteral avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spree_fx_currency's Issues

Code duplication: variants and master variant

master why? why not use variants_including_master in process product.variants.each
https://github.com/spree/spree/blob/3-0-stable/core/app/models/spree/product.rb#L50

    def proccess_variants(product)
      product.variants.each do |variant|
        from_price = variant.price_in(from_currency.upcase)
        next if from_price.new_record?
        new_price = variant.price_in(to_currency.upcase)
        new_price.amount = from_price.amount * rate
        new_price.save if new_price.changed?
      end
    end

    def proccess_master(product)
      from_price = product.price_in(from_currency.upcase)

      return if from_price.new_record?

      new_price = product.price_in(to_currency.upcase)
      new_price.amount = from_price.amount * rate
      new_price.save if new_price.changed?
    end

Improve README

  • how to setup
  • what it does/adds
  • add screenshots
  • versions of spree supported
  • mention about fixer.io

Code duplication: fetching fixer

model/fx_rate.rb

   def self.fetch_fixer
      base = Spree::Config.currency
      symbols = pluck(:to_currency).map(&:upcase).join(',')
      uri = URI("http://api.fixer.io/latest?base=#{base}&symbols=#{symbols}")
      response = Net::HTTP.get(uri)
      parsed_response = JSON.parse(response)
      return false if parsed_response['rates'].blank?
      parsed_response['rates'].each do |currency, value|
        find_by(to_currency: currency).try(:update_attributes, rate: value)
      end
      true
    end

    def fetch_fixer
      base = from_currency.upcase
      symbol = to_currency.upcase
      uri = URI("http://api.fixer.io/latest?base=#{base}&symbols=#{symbol}")
      response = Net::HTTP.get(uri)
      parsed_response = JSON.parse(response)
      new_rate = parsed_response['rates'].try(:[], symbol)
      update_attributes(rate: new_rate)
    end

Fix rubocop offences

app/models/spree/fx_rate.rb:12:5: C: Assignment Branch Condition size for create_supported_currencies is too high. [19.65/15]
    def self.create_supported_currencies
    ^^^

Setup generator

Now rails g spree_fx_currency:install generator:

  • add javascripts
  • add stylesheets
  • add migrations
  • run migrations

It's no need for javascripts and stylesheets, for now it should be removed from generator

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.