ecommerce 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +9 -0
  4. data/Gemfile.lock +96 -0
  5. data/README +256 -0
  6. data/Rakefile +7 -0
  7. data/app/controllers/application_controller.rb +6 -0
  8. data/app/controllers/cart_controller.rb +42 -0
  9. data/app/controllers/ecommerce_controller.rb +5 -0
  10. data/app/controllers/payment_notifications_controller.rb +80 -0
  11. data/app/controllers/photos_controller.rb +19 -0
  12. data/app/controllers/products_controller.rb +35 -0
  13. data/app/helpers/application_helper.rb +3 -0
  14. data/app/helpers/products_helper.rb +8 -0
  15. data/app/models/cart.rb +108 -0
  16. data/app/models/cart_item.rb +39 -0
  17. data/app/models/photo.rb +21 -0
  18. data/app/models/product.rb +29 -0
  19. data/app/views/cart/index.haml +80 -0
  20. data/app/views/layouts/application.html.erb +14 -0
  21. data/app/views/products/_form.html.haml +45 -0
  22. data/app/views/products/edit.html.haml +5 -0
  23. data/app/views/products/index.html.haml +17 -0
  24. data/app/views/products/new.html.haml +4 -0
  25. data/app/views/products/show.haml +28 -0
  26. data/app/views/products/show/_photos.haml +13 -0
  27. data/config.ru +4 -0
  28. data/config/application.rb +43 -0
  29. data/config/boot.rb +13 -0
  30. data/config/database.yml +22 -0
  31. data/config/ecommerce.yml +16 -0
  32. data/config/environment.rb +5 -0
  33. data/config/environments/development.rb +26 -0
  34. data/config/environments/production.rb +49 -0
  35. data/config/environments/test.rb +35 -0
  36. data/config/initializers/ecommerce-config.rb +7 -0
  37. data/config/initializers/mime_types.rb +6 -0
  38. data/config/locales/en.yml +5 -0
  39. data/config/routes.rb +23 -0
  40. data/db/seeds.rb +7 -0
  41. data/doc/README_FOR_APP +2 -0
  42. data/ecommerce-0.0.1.gem +0 -0
  43. data/ecommerce.gemspec +24 -0
  44. data/lib/ecommerce.rb +4 -0
  45. data/lib/ecommerce/ecommerce.rb +5 -0
  46. data/lib/ecommerce/engine.rb +25 -0
  47. data/lib/ecommerce/version.rb +3 -0
  48. data/lib/generators/ecommerce/USAGE +4 -0
  49. data/lib/generators/ecommerce/ecommerce_generator.rb +30 -0
  50. data/lib/generators/ecommerce/templates/migration.rb +59 -0
  51. data/lib/tasks/.gitkeep +0 -0
  52. data/models/payment_notification.rb +15 -0
  53. data/public/404.html +26 -0
  54. data/public/422.html +26 -0
  55. data/public/500.html +26 -0
  56. data/public/favicon.ico +0 -0
  57. data/public/javascripts/ecommerce.js +10 -0
  58. data/public/robots.txt +5 -0
  59. data/public/stylesheets/.gitkeep +0 -0
  60. data/script/rails +6 -0
  61. data/spec/spec_helper.rb +27 -0
  62. data/test/performance/browsing_test.rb +9 -0
  63. data/test/test_helper.rb +13 -0
  64. data/vendor/plugins/.gitkeep +0 -0
  65. metadata +160 -0
@@ -0,0 +1,4 @@
1
+ %h1 New product
2
+
3
+ = render 'form'
4
+
@@ -0,0 +1,28 @@
1
+ :ruby
2
+ page_title('Our products are built to last while creating memories along the way.')
3
+
4
+ %div#productC.clearfix.container
5
+ %div.span-24
6
+ = render :partial => 'products/show/photos'
7
+ %div.span-22
8
+ %h2
9
+ = @product.name
10
+ = admin_area do
11
+ = link_to 'Edit', edit_product_path(@product.permalink)
12
+
13
+ - if @product.price?
14
+ %div.price= @product.pricef
15
+
16
+ = sanitize @product.descr, :tags => %w(br p a b ul li), :attributes => %w(href)
17
+
18
+ %div#atcC
19
+ - form_tag cart_path(), :method => :put do
20
+ = hidden_field_tag :product_id, @product.id
21
+
22
+ #atc_button.actions.clearfix
23
+ = submit_tag 'Add To Cart', :class => :button
24
+
25
+ .field#quantityC
26
+ %label{:for => :quantity, :class => :inline} Quantity:
27
+ = text_field_tag :quantity, 1, :size => 2
28
+
@@ -0,0 +1,13 @@
1
+ - if @product.photos?
2
+ = image_tag @product.photos.first.photo.url(:large), :id => 'hero_image'
3
+
4
+ - if @product.photos.size > 1
5
+ %p.thumbs
6
+ - @product.photos.each do |photo|
7
+ - img = image_tag photo.photo.url(:thumb), :alt => photo.alt
8
+ = link_to img, photo.photo.url(:large)
9
+
10
+ :javascript
11
+ $(document).ready(function() {
12
+ $(".thumbs a").simple_photo_swap('hero_image');
13
+ });
data/config.ru ADDED
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Ecommerce::Application
@@ -0,0 +1,43 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # If you have a Gemfile, require the gems listed there, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
8
+
9
+ module Ecommerce
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+
15
+ # Custom directories with classes and modules you want to be autoloadable.
16
+ # config.autoload_paths += %W(#{config.root}/extras)
17
+ config.autoload_paths += %W(#{config.root}/lib/ecommerce)
18
+
19
+ # Only load the plugins named here, in the order given (default is alphabetical).
20
+ # :all can be used as a placeholder for all plugins not explicitly named.
21
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
22
+
23
+ # Activate observers that should always be running.
24
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
25
+
26
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
27
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
28
+ # config.time_zone = 'Central Time (US & Canada)'
29
+
30
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
31
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
32
+ # config.i18n.default_locale = :de
33
+
34
+ # JavaScript files you want as :defaults (application.js is always included).
35
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
36
+
37
+ # Configure the default encoding used in templates for Ruby 1.9.
38
+ config.encoding = "utf-8"
39
+
40
+ # Configure sensitive parameters which will be filtered from the log file.
41
+ config.filter_parameters += [:password]
42
+ end
43
+ end
data/config/boot.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
5
+ begin
6
+ ENV['BUNDLE_GEMFILE'] = gemfile
7
+ require 'bundler'
8
+ Bundler.setup
9
+ rescue Bundler::GemNotFound => e
10
+ STDERR.puts e.message
11
+ STDERR.puts "Try running `bundle install`."
12
+ exit!
13
+ end if File.exist?(gemfile)
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000
@@ -0,0 +1,16 @@
1
+ development:
2
+ # Sandbox : paypal-sandbox@28dev.com / asdfasdf
3
+ # buyer : buyer_1301262667_per@28dev.com / 301262633
4
+ # seller : seller_1301259322_biz@28dev.com / 301259292
5
+ paypal:
6
+ email: seller_1301259322_biz@28dev.com
7
+ secret: foobar
8
+ cert_id: PCHTSCQZLRAPU
9
+ url: https://www.sandbox.paypal.com/cgi-bin/webscr
10
+
11
+ production:
12
+ paypal:
13
+ email: seller_1277185454_biz@28dev.com
14
+ secret: DVQQKEw5ZYWtpb
15
+ cert_id: SMHGQTJ3UGNJ6
16
+ url: https://www.sandbox.paypal.com/cgi-bin/webscr
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Ecommerce::Application.initialize!
@@ -0,0 +1,26 @@
1
+ Ecommerce::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
19
+
20
+ # Print deprecation notices to the Rails logger
21
+ config.active_support.deprecation = :log
22
+
23
+ # Only use best-standards-support built into browsers
24
+ config.action_dispatch.best_standards_support = :builtin
25
+ end
26
+
@@ -0,0 +1,49 @@
1
+ Ecommerce::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # Specifies the header that your server uses for sending files
13
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
+
15
+ # For nginx:
16
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
+
18
+ # If you have no front-end server that supports something like X-Sendfile,
19
+ # just comment this out and Rails will serve the files
20
+
21
+ # See everything in the log (default is :info)
22
+ # config.log_level = :debug
23
+
24
+ # Use a different logger for distributed setups
25
+ # config.logger = SyslogLogger.new
26
+
27
+ # Use a different cache store in production
28
+ # config.cache_store = :mem_cache_store
29
+
30
+ # Disable Rails's static asset server
31
+ # In production, Apache or nginx will already do this
32
+ config.serve_static_assets = false
33
+
34
+ # Enable serving of images, stylesheets, and javascripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+ # Disable delivery errors, bad email addresses will be ignored
38
+ # config.action_mailer.raise_delivery_errors = false
39
+
40
+ # Enable threaded mode
41
+ # config.threadsafe!
42
+
43
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
+ # the I18n.default_locale when a translation can not be found)
45
+ config.i18n.fallbacks = true
46
+
47
+ # Send deprecation notices to registered listeners
48
+ config.active_support.deprecation = :notify
49
+ end
@@ -0,0 +1,35 @@
1
+ Ecommerce::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ # Disable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ # Tell Action Mailer not to deliver emails to the real world.
24
+ # The :test delivery method accumulates sent emails in the
25
+ # ActionMailer::Base.deliveries array.
26
+ config.action_mailer.delivery_method = :test
27
+
28
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
29
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
30
+ # like if you have constraints or database-specific column types
31
+ # config.active_record.schema_format = :sql
32
+
33
+ # Print deprecation notices to the stderr
34
+ config.active_support.deprecation = :stderr
35
+ end
@@ -0,0 +1,7 @@
1
+ require 'yaml'
2
+ env = Rails.env.present? ? Rails.env.to_s : 'test'
3
+ ECO = YAML.load(File.read(File.expand_path('../../ecommerce.yml', __FILE__)))[env]
4
+
5
+ PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
6
+ APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
7
+ APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
@@ -0,0 +1,6 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
6
+ Mime::Type.register_alias "text/html", :yml
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
data/config/routes.rb ADDED
@@ -0,0 +1,23 @@
1
+ Rails.application.routes.draw do
2
+ match '/cart', :via => :get, :to => 'cart#index'
3
+ match '/cart', :via => :put, :to => 'cart#update'
4
+ match '/cart', :via => :delete, :to => 'cart#destroy'
5
+
6
+
7
+ # resources :cart, :except => [:update, :edit, :show, :create, :new] do
8
+ # collection do
9
+ # put :update
10
+ # end
11
+ # end
12
+
13
+ resources :payment_notifications
14
+ resources :order_confirmation
15
+
16
+ match '/products/search' => 'products#search'
17
+ resources :products do
18
+ resources :photos
19
+ end
20
+
21
+ match '/p/*path' => 'products#by_permalink'
22
+
23
+ end
data/db/seeds.rb ADDED
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
+ # Mayor.create(:name => 'Daley', :city => cities.first)
@@ -0,0 +1,2 @@
1
+ Use this README file to introduce your application and point to useful places in the API for learning more.
2
+ Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
Binary file
data/ecommerce.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ecommerce/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ecommerce"
7
+ s.version = Ecommerce::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jason Younker"]
10
+ s.email = ["jason@ynkr.org"]
11
+ s.homepage = ""
12
+ s.summary = %q{Very simple ecommerce framework}
13
+ s.description = %q{Very simple ecommerce framework including products table, cart (and cart items) and paypal checkout}
14
+
15
+ s.rubyforge_project = "ecommerce"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "rails"
23
+ s.add_development_dependency "rspec"
24
+ end
data/lib/ecommerce.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Ecommerce
2
+ require 'ecommerce/engine' if defined?(Rails)
3
+
4
+ end
@@ -0,0 +1,5 @@
1
+ module Ecommerce
2
+
3
+ require 'ecommerce/engine' if defined?(Rails)
4
+
5
+ end
@@ -0,0 +1,25 @@
1
+ # http://olympiad.posterous.com/how-to-building-a-rails-3-engine-and-set-up-t
2
+ # http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2---writing-an-engine/
3
+ # http://www.themodestrubyist.com/2010/03/16/rails-3-plugins---part-3---rake-tasks-generators-initializers-oh-my/
4
+ require "ecommerce"
5
+ require "rails"
6
+
7
+ module Ecommerce
8
+
9
+ class Engine < Rails::Engine
10
+
11
+ # How Do We Get JS To Load (for the client app)
12
+ # 1. We must make the ecommerce engine's public directory available to the client app
13
+ initializer "static assets" do |app|
14
+ app.middleware.use ::ActionDispatch::Static, "#{root}/public"
15
+ end
16
+
17
+ # 2. Now, add our js file to the client's default js files list. For more, see
18
+ # Rails Config Hooks: http://andre.arko.net/2010/10/15/extending-rails-3-with-railties/
19
+ config.before_initialize do
20
+ config.action_view.javascript_expansions[:defaults] += %w(ecommerce.js)
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ module Ecommerce
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,4 @@
1
+ Description:
2
+ rails g ecommerce
3
+
4
+ Create a migration which will create products, photos, carts, cart_items and (paypal) payment_notifications tables
@@ -0,0 +1,30 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module Ecommerce
5
+ module Generators
6
+ class SetupGenerator < Rails::Generators::Base
7
+ namespace "ecommerce"
8
+ include Rails::Generators::Migration
9
+
10
+ def create_migration_file
11
+ migration_template 'migration.rb', 'db/migrate/create_ecommerce_tables.rb'
12
+ end
13
+
14
+ # This class method must be defined in your generator in order to find things like our migration templates
15
+ def self.source_root
16
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
17
+ end
18
+
19
+ # Implement the required interface for Rails::Generators::Migration.
20
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
21
+ def self.next_migration_number(dirname)
22
+ if ActiveRecord::Base.timestamped_migrations
23
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
24
+ else
25
+ "%.3d" % (current_migration_number(dirname) + 1)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end