Coder Social home page Coder Social logo

ror-react-ecommerce's Introduction

README

Epsy, an Etsy clone, is a global online marketplace where people come togetehr to make, sell, buy and collect unique items.

Here is an image of the homepage:

Built with

Deployment

Hosted on Heroku

Getting started

Refer to the wiki for more details of this project!

Installation

Start installation
git clone https://github.com/chinweenie/Full-Stack-Project-Etsy.git
cd Full-Stack-Project-Etsy
bundle install
npm install
bundle exec rails s
npm run webpack

Technical details

The navbar shows different button when a user is logged in. The implementation of this involves a check on whether there is a session id.
const mapStateToProps = state => {
    let shopId;
    if (state.session.id){
        shopId = currentUserHasShop(state.session.id, state.entities.users)
    } else {
        shopId = false;
    };

    return {
        navbar: Boolean(state.session.id),
        shopId,
        users: selectAllUsers(state.entities.users),
    }
  
};

Also, if a user adds a product(which has already been added before) into the cart, the create action automatically update the quantity of the cart item instead of creating a new cart item with the same product id. The create and update action also checks if the cart item quantity is still within the maximum quantity allowed (based of the availability of the product).

def create
        if check_current_cart(product_id, quantity)
            @cart_item = CartItem.find_by(product_id: product_id, user_id: current_user.id)

            total = @cart_item.quantity + quantity.to_i
            maximum_quantity = Product.find_by(id: product_id).quantity 

            if total > maximum_quantity
                render json: ['Sorry, not enough stock!'], status: 422 
                return 
            else
                if @cart_item.update(quantity: total)
                    render :show
                else
                    render json: @cart_item.errors.full_messages, status: 422
                end
            end
        else
            @cart_item = CartItem.new(cart_item_params)
            @cart_item.user_id = current_user.id
            if @cart_item.save
                render :show
            else
                render json: @cart_item.errors.full_messages, status: 422
            end

        end
    end

    def update
        @cart_item = CartItem.where(user_id: current_user.id, id: params[:id]).first
        if params[:cart_item][:quantity] == '0'
            @cart_item.destroy 
        else

            maximum_quantity = Product.find_by(id: @cart_item.product_id).quantity  
            total = quantity + @cart_item.quantity 

            if quantity > maximum_quantity 
                @cart_item.quantity = maximum_quantity
                @cart_item.save!  
                render :show   

            else         
                if @cart_item.update(cart_item_params)
                    render :show
                else
                    render json: @cart_item.errors.full_messages
                end
            end
            
            
        end
        
    end

Author

Winnie Chin

Acknowledgments

Thank you Andy for providing me user feedbacks throughout the project development.

ror-react-ecommerce's People

Contributors

bluestars1233 avatar

Watchers

 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.