Giter Club home page Giter Club logo

ex_cart's Introduction

ExCart

E-commerce cart for elixir

Coverage Status CircleCI Version GitHub GitHub last commit (branch)

Installation

- clone the repo
- cd ex_cart
- mix deps.get

Run on iex

iex -S mix

Use to store values

ex_cart = ExCart.Cart.new
ex_cart = ExCart.Cart.add_item(ex_cart, %ExCart.Item{ec_sku: "SU04", ec_qty: 10, ec_price: 3})
adj = ExCart.Adjustment.new("shipping","Shipping",
  fn(x) ->
  sb = ExCart.Cart.subtotal(x)
    case sb do
      sb when sb > 25 -> 0
      _-> 10
    end
end)
ex_cart = ExCart.Cart.add_adjustment(ex_cart,adj)
ExCart.Cart.total(ex_cart)

Use as server (manage multiple cart processes and their states).

{:ok, pid1} = ExCart.Server.start_link
ExCart.Server.add_item(pid1, %ExCart.Item{ec_sku: "SU01", ec_qty: 10, ec_price: 3})
{:ok, pid2} = ExCart.Server.start_link
ExCart.Server.add_item(pid2, %ExCart.Item{ec_sku: "SU02", ec_qty: 5, ec_price: 3})
adj = ExCart.Adjustment.new("shipping","Shipping",
    fn(x) ->
        sb = ExCart.Cart.subtotal(x)
            case sb do
                sb when sb > 25 -> 0
                _-> 10
            end
    end)
ExCart.Server.add_adjustment(pid1,adj)
ExCart.Server.add_adjustment(pid2,adj)
ExCart.Server.total(pid1)
ExCart.Server.total(pid2)

How to use the registry to manage multiple ExCartServers

{:ok, session } = ExCart.Session.start_link
cart_one = ExCart.Session.server_process("cart one")
ExCart.Server.add_item(cart_one, %ExCart.Item{ec_sku: "SU01", ec_price: 10})
ExCart.Server.add_item(cart_one, %ExCart.Item{ec_sku: "SU02", ec_price: 15})
ExCart.Server.subtotal(cart_one)

cart_two = ExCart.Session.server_process("cart two")
ExCart.Server.add_item(cart_two, %ExCart.Item{ec_sku: "SU01", ec_price: 2})
ExCart.Server.add_item(cart_two, %ExCart.Item{ec_sku: "SU03", ec_price: 1})
ExCart.Server.subtotal(cart_two)

How to use the Dynamic Supervised ExCartServers

{:ok, pid } = ExCart.Cart.Supervisor.start_cart()
ExCart.Server.state(pid)

How to use the supervisor as starting point.

ExCart.Supervisor.start_link
cart_one = ExCart.Session.server_process("cart one")
ExCart.Server.add_item(cart_one, %ExCart.Item{ec_sku: "SU01", ec_price: 10})
ExCart.Server.add_item(cart_one, %ExCart.Item{ec_sku: "SU02", ec_price: 15})
ExCart.Server.subtotal(cart_one)

To use with Phoenix:

  • Add as dependency

  • To see how it works, start the application on iex

    $ iex -S mix phoenix.server

    #And then start the observer.

    iex(n)>:observer.start

    #And you will see the ex_cart application aside of your app.

Settings (config.exs)

  • config :ex_cart, max_items: 1000

License

Copyright 2022 Jason Clark Copyright 2018 Ruben Amortegui

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

ex_cart's People

Contributors

ramortegui avatar mithereal 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.