Hot questions for Using Spree in ruby on rails 3
Using Spree and ransack, how is it possible to return the Spree::Variants included in Spree::Orders that have completed since a certain date? The ransack documentation gives a little advice about searching associations, but does not seem to go deep enough.
Spree::Order has_many :line_items Spree::LineItem belongs_to :line_item belongs_to :variant Spree::Variant has_many: line_items
Orders that have completed can be searched with:
But how to find the Spree::LineItems within these orders and return the Spree::Variants' SKUs within these orders is unclear.
I'm attempting to use ransack because this will be used in a Spree report.
You don't need to use ransack in this area at all. ActiveRecord will let you do what you need:
Spree::Order.complete.where( Spree::Order.arel_table[:completed_at].gteq( Date.new(2015, 10, 1) ) ).joins( line_items: :variant ).select(:sku).distinct.pluck(:sku)
If you must use ransack, you can get the ActiveRecord relation, using
.result and apply the joins and such.
Spree::Order.complete.ransack( completed_at_gt: '2015-05-01' ).result.joins( line_items: :variant ).select(:sku).distinct.pluck(:sku)
Since you don't have
.pluck, you're running a really old version of Spree that is pre-Rails 4. You can get the results by using:
Spree::Order.complete.ransack( completed_at_gt: '2015-05-01' ).result.joins( line_items: :variant ).select(:sku).map(&:sku).uniq
In short, is it possible to build an Amazon clone without substantial modification to Spree?
it is indeed possible. If you do, don't use spree as an engine, just use the whole sourcecode as itself. If you use it as an engine, you'll end up overriding so much features of spree that you will be lost totally! Also use and extend the tests that come with spree. You will however loose the ability to update spree, because you will have to change a lot of stuff in the core.
sorry if this questions are too simple. Just started to learn Ruby on Rails and Spree ecommerce.
Successfully installed the demo store according the the instructions here: https://github.com/spree/spree , however, I don't quite understand how the source codes at the Github are linked to the sources codes on the Ruby on Rails spree ecommerce store. The directories are pretty different from each other. For example, spree source codes have "/API", "/backend", "/core", etc... while the ruby on rails spree ecommerce store has "/app", "/bin", "/config", etc...
I know the ruby on rails auto generates some codes. But how the two correlated with each other? Say, some codes at Spree ecommerce are updated, what to do to update the Spree store?
thank you very much!
The Spree framework is a gem that works as an engine with each part(API, backend, frontend, core) separated in their own directories like a separated gem, just for better organization. Used to be all inside the Spree gem back in the day.
Your Rails app, the one with the 'app/', 'bin/' and 'config/' directories, is the true application, when you install/add Spree in your app it will be mounted alongside with your Rails app and will provide all the e-commerce platform.
In short when your add a gem into your Gemfile, the gem will be downloaded to your local system in the
bundle install part. Rails will load the files from the gems listed on your Gemfile and everything will be good and accessible, automagically for you.
To update the gem spree you would have to use the
bundle update spree command and the
bundler will take care of updating the files.
To customize your Spree code, you can start to learn how in their guide.