Giter Club home page Giter Club logo

piggybak_variants's Introduction

Piggybak Gem (Engine)

Modular / mountable ecommerce gem. Features:

  • Configurable tax methods, shipping methods, payment methods

  • One page checkout, with AJAX for shipping and tax calculations

  • Order processing completed in transaction, minimizing orphan data created

  • Fully defined backend RailsAdmin interface for adding orders on the backend

  • Piggybak 0.7.1 is compatible with Rails 4.1, 0.7.0 is compatible with Rails 4, and earlier version compatible with Rails 3.

Announcements

  • Variants were recently changed to sellables, to provide the opportunity for advanced variant support via an extension.

  • Significant recent rearchitecture has been applied to the order line items. Stay tuned for the documentation.

  • Review the new installation process below.

Installation

  • First create a new rails project: rails new webstore

  • Config your database.yml and create the databases

  • Add to Gemfile:

      gem "piggybak"
    
  • Next, run bundle install:

      bundle install
    
  • Next, run the piggybak install command:

      bundle exec piggybak install
    
  • Add piggybak/piggybak-application to your main application.js:

     //= require piggybak/piggybak-application
    

See the raw documentation to read more about the integration points and product configuration in Piggybak.

TODO

  • Ensure that changes in nested addresses are recorded on order notes.

Copyright

Copyright (c) 2014 End Point & Steph Skardal. See LICENSE for further details.

piggybak_variants's People

Contributors

killinit avatar marcamillion avatar timcase avatar timmyc avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

piggybak_variants's Issues

RA warnings on variants

[RailsAdmin] Please add 'attr_accessible :option_value_ids' in your 'PiggybakVariants::Variant' model definition if you want to make it editable.
You can also explicitely mark this field as read-only: 

config.model PiggybakVariants::Variant do
  field :option_values do
    read_only true
  end
end

Add 'config.yell_for_non_accessible_fields = false' in your 'rails_admin.rb' initializer if you do not want to see these warnings




[RailsAdmin] Please add 'attr_accessible :piggybak_sellable_attributes' in your 'PiggybakVariants::Variant' model definition if you want to make it editable.
You can also explicitely mark this field as read-only: 

config.model PiggybakVariants::Variant do
  field :piggybak_sellable do
    read_only true
  end
end

Add 'config.yell_for_non_accessible_fields = false' in your 'rails_admin.rb' initializer if you do not want to see these warnings


Variant export ID field incorrect

The fifth field, titled 'Id [Piggybak sellable]', seems to contain the id of the variant, not the sellable upon which it is based.

N+1 Query Problem - Eager Loading Optimization

I am using the Bullet Gem - http://github.com/flyerhzm/bullet - to look for inefficient queries in my app.

It gave me this result, related to piggybak_variants:

user: marcamillion
localhost:3000/products/36
N+1 Query detected
  PiggybakVariants::Variant => [:piggybak_sellable]
  Add to your finder: :include => [:piggybak_sellable]
N+1 Query method call stack
  N+1 Query method call stack
  /myapp/app/views/piggybak_variants/cart/_form.html.erb:5:in `_app_views_piggybak_variants_cart__form_html_erb___516701594289197123_70186523336120'
  /myapp/app/views/products/show.html.erb:49:in `_app_views_products_show_html_erb___1025568626930858953_70186508468620'
  /myapp/app/controllers/products_controller.rb:33:in `show'
user: marcamillion
localhost:3000/products/36
N+1 Query detected
  PiggybakVariants::OptionConfiguration => [:option]
  Add to your finder: :include => [:option]
N+1 Query method call stack
  N+1 Query method call stack
  /myapp/app/views/piggybak_variants/cart/_form.html.erb:9:in `_app_views_piggybak_variants_cart__form_html_erb___516701594289197123_70186523336120'
  /myapp/app/views/products/show.html.erb:49:in `_app_views_products_show_html_erb___1025568626930858953_70186508468620'
  /myapp/app/controllers/products_controller.rb:33:in `show'

I tried tracking it down, but I can't find the appropriate controller for this particular call.

All you have to do is add an .includes(:piggybak_sellables) or .includes(:sellables) (whichever is appropriate) to the right controller call that loads all the variants.

The same would apply to the options, except it would simply be .includes(:options).

Edit 1

For what it's worth, this is what my piggybak_variants/cart/_form.html.erb looks like:

<% if object.reflections.keys.include?(:variants) -%>
    <%= javascript_include_tag "piggybak_variants/piggybak_variants" %>

    <script type="text/javascript">
        var variant_map = <%= raw variant_map(object) %>;
    </script>

    <div class="variant_options">
        <% options_for_klass(object.class).each do |option| -%>
        <div class="option" id="option_<%= option.id %>">
        <h4><%= option.name %></h4>
        <%= select_tag option.name, options_for_select(option.option_values.map{ |o| [o.name, o.id, { name: "option_#{option.name}-#{o.id}"}] }), include_blank: true %>
        <br />
        </div>
        <% end -%>
        <span class="all_selected">You must select a choice from each option.</span>
        <span class="unavailable">This combination is not available.</span>
        <%= form_tag piggybak.cart_add_url do -%>
        <input type="hidden" id="sellable_id" name="sellable_id" />
        <!-- <div id="variant_price">Price: <span></span></div> -->
        <label for="quantity">Quantity</label>
        <%= text_field_tag :quantity, 1 %>
        <%= submit_tag "Add to Cart", :id => "submit" %>
        <% end -%>
    </div>
<% end -%>

Line 5 is raw variant_map(object) line and line 9 is the options_for_klass(object.class).each do.... line.

Hope that helps!

Bug in RailsAdmin when creating variants if class is multiple words (camel case)

In app/views/rails_admin/main/_option_values.html.haml both the hidden field and checkbox tag ids are generated by converting object class to a downcase string, which only works if the class name is one word. It needs to be converted to the underscored class name if there are multiple words. For example ImagePrint becomes imageprint and it should be image_print. I was able to resolve it in my project by adding a to_underscore method to String and changing downcase to to_underscore.

Rails 4 upgrade

Hello,

I'm forking this project and piggybak and trying to make them rails 4 ready. I updated all dependencies, but have gotten stuck on one issue.
I am receiving the error when I submit an entry:

undefined method `valid?' for #<ActiveRecord::Associations::CollectionProxy []>

Which seems to correspond to this part of the code:
https://github.com/piggybak/piggybak_variants/blob/master/lib/associated_bubbling_validator.rb#L6

And I found this on the rails 4 upgrade section of the rails website:
http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#active-model

Any insight you could provide on how to fix that would be great.

Massive market with fixed variant is not optimal

Gem is not optimal when user want fixed variants.
For exemple for prints (like piggybak demo) options and options values like:

  • Size (S, M, L)
  • Frame (Black or white)
    => 6 possibilities for options (this number could be very important if we have 3 options and more)

Given I have 1000 photographs to sold on my marketplace with same variants :

  • piggybak_variants_variants table will have 1000 entries
  • piggybak_variants_option_values_variants will have 1000 * 6 = 6000 entries
  • piggybak_sellables will have 1000 lines

Plus, it's not very user friendly for admin. Admin must create a 'variant' and a 'sellable' for each photograph. He will create variants with same options values for very photographs, 6 times... 6000 times!

Should I fork the project because it's the heart of piggybak_variants that should be change :

  • sellable belongs_to an item and belongs_to an option_variant
  • variants has_many options_values and has_many sellables
  • add to sellable variant_id as foreign key

It's less modular but more effective for the case I describe

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.