Coder Social home page Coder Social logo

cshenoy / spree-add-ons Goto Github PK

View Code? Open in Web Editor NEW

This project forked from somecodemonkey/spree-add-ons

0.0 2.0 0.0 293 KB

Allows custom add ons to be added to spree line items.

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

Ruby 79.06% JavaScript 3.18% CSS 1.64% HTML 16.11%

spree-add-ons's Introduction

SpreeAddOns

This gem provides the ability to create custom addons for line_items. For example a product can have gift wrapping and/or packaging. A Spree::AddOn has one Spree::Calculator. Options for calculators can be added via app.config.spree.calculators.add_ons << Spree::Calculator::FlatRate.

A line item can have any number of add ons as long as they are defined on the product and active. In the event an add on is deleted the line_item and order are marked invalid and appropriate errors are applied.

To create a line item or update one with add ons POST/PATCH with options as follows:

{
    line_item: {
    ...
    options: {
            add_on_ids: [1,3]
        }
    }
}

To remove all add ons or a specific one DELETE with options to /api/orders/:number/line_item/:line_item_id/remove_add_ons

{
    line_item: {
    ...
    options: {
            add_on_ids: [1] // Removes add on 1
            // alternatively you could update with a stringified array
        }
    }
}

or omit options to remove all add ons

{
    line_item: {
    ...
    }
}

To create a new add on simply inherit from Spree::AddOn

    class Spree::OtherAddOn < Spree::AddOn
        # what is shown when selecting the type in admin
        def self.display_name
            'Other Add On'
        end
    end

This Spree::OtherAddOn will then be available in /admin/add_ons when creating a new add_on.

Spree::LineItem json has been extended to include

// add_ons currently attached to the line_item
add_ons: [
    {
        id: 1,
        name: Some Add on
        ...
    }
],
// add_ons that can be added to this line_item
available_add_ons: [
    {
        id: 1,
        name: Some add on
        ...
    },
    {
        id: 4,
        name: Some Other add on
        ...
    }
]

Installation

Add spree_add_ons to your Gemfile:

gem 'spree_add_ons'

Bundle your dependencies and run the installation generator:

bundle
bundle exec rails g spree_add_ons:install

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

Copyright (c) 2015 Darby Perez, released under the New BSD License

spree-add-ons's People

Contributors

cshenoy avatar deodad avatar somecodemonkey avatar

Watchers

 avatar  avatar

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.