shoppy 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +34 -0
- data/app/.DS_Store +0 -0
- data/app/api/apihelpers/api_auth.rb +50 -0
- data/app/api/base.rb +7 -0
- data/app/api/v1/auth.rb +57 -0
- data/app/api/v1/test.rb +15 -0
- data/app/api/v1/users.rb +50 -0
- data/app/api/v1/v1_api.rb +15 -0
- data/app/api/vo/user_vo.rb +7 -0
- data/app/assets/fonts/.DS_Store +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.svg +229 -0
- data/app/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/images/.DS_Store +0 -0
- data/app/assets/images/Sorting icons.psd +0 -0
- data/app/assets/images/back_disabled.png +0 -0
- data/app/assets/images/back_enabled.png +0 -0
- data/app/assets/images/back_enabled_hover.png +0 -0
- data/app/assets/images/favicon.ico +0 -0
- data/app/assets/images/forward_disabled.png +0 -0
- data/app/assets/images/forward_enabled.png +0 -0
- data/app/assets/images/forward_enabled_hover.png +0 -0
- data/app/assets/images/shoppy.svg +34 -0
- data/app/assets/images/sort_asc.png +0 -0
- data/app/assets/images/sort_asc_disabled.png +0 -0
- data/app/assets/images/sort_both.png +0 -0
- data/app/assets/images/sort_desc.png +0 -0
- data/app/assets/images/sort_desc_disabled.png +0 -0
- data/app/assets/images/spritemap.png +0 -0
- data/app/assets/images/spritemap@2x.png +0 -0
- data/app/assets/javascripts/.DS_Store +0 -0
- data/app/assets/javascripts/bootstrap.js +2114 -0
- data/app/assets/javascripts/bootstrap.min.js +6 -0
- data/app/assets/javascripts/jasny-bootstrap.min.js +6 -0
- data/app/assets/javascripts/jquery.dataTables.min.js +155 -0
- data/app/assets/javascripts/main.js +29 -0
- data/app/assets/javascripts/shoppy.js +31 -0
- data/app/assets/stylesheets/.DS_Store +0 -0
- data/app/assets/stylesheets/bootstrap.css +6203 -0
- data/app/assets/stylesheets/jasny-bootstrap.css +621 -0
- data/app/assets/stylesheets/jquery.dataTables.min.css +1 -0
- data/app/assets/stylesheets/jquery.dataTables_themeroller.css +330 -0
- data/app/assets/stylesheets/shoppy.css +23 -0
- data/app/assets/stylesheets/style.sass +79 -0
- data/app/controllers/.DS_Store +0 -0
- data/app/controllers/shoppy/accounts_controller.rb +102 -0
- data/app/controllers/shoppy/application_controller.rb +23 -0
- data/app/controllers/shoppy/brands_controller.rb +60 -0
- data/app/controllers/shoppy/cart_controller.rb +46 -0
- data/app/controllers/shoppy/categories_controller.rb +72 -0
- data/app/controllers/shoppy/concerns/.keep +0 -0
- data/app/controllers/shoppy/customer_addresses_controller.rb +90 -0
- data/app/controllers/shoppy/home_controller.rb +9 -0
- data/app/controllers/shoppy/inventories_controller.rb +62 -0
- data/app/controllers/shoppy/locations_controller.rb +80 -0
- data/app/controllers/shoppy/logs_controller.rb +9 -0
- data/app/controllers/shoppy/manufacturers_controller.rb +77 -0
- data/app/controllers/shoppy/options_controller.rb +63 -0
- data/app/controllers/shoppy/orders_controller.rb +130 -0
- data/app/controllers/shoppy/products_controller.rb +98 -0
- data/app/controllers/shoppy/reviews_controller.rb +70 -0
- data/app/controllers/shoppy/sessions_controller.rb +5 -0
- data/app/controllers/shoppy/settings_controller.rb +26 -0
- data/app/controllers/shoppy/shipments_controller.rb +125 -0
- data/app/controllers/shoppy/variants_controller.rb +104 -0
- data/app/helpers/shoppy/accounts_helper.rb +5 -0
- data/app/helpers/shoppy/application_helper.rb +19 -0
- data/app/helpers/shoppy/brands_helper.rb +4 -0
- data/app/helpers/shoppy/cart_helper.rb +66 -0
- data/app/helpers/shoppy/categories_helper.rb +4 -0
- data/app/helpers/shoppy/customer_addresses_helper.rb +4 -0
- data/app/helpers/shoppy/home_helper.rb +5 -0
- data/app/helpers/shoppy/inventories_helper.rb +53 -0
- data/app/helpers/shoppy/locations_helper.rb +4 -0
- data/app/helpers/shoppy/logs_helper.rb +4 -0
- data/app/helpers/shoppy/manufacturers_helper.rb +4 -0
- data/app/helpers/shoppy/options_helper.rb +43 -0
- data/app/helpers/shoppy/orders_helper.rb +61 -0
- data/app/helpers/shoppy/products_helper.rb +65 -0
- data/app/helpers/shoppy/reviews_helper.rb +4 -0
- data/app/helpers/shoppy/settings_helper.rb +5 -0
- data/app/helpers/shoppy/shipments_helper.rb +43 -0
- data/app/helpers/shoppy/variants_helper.rb +4 -0
- data/app/models/shoppy/.DS_Store +0 -0
- data/app/models/shoppy/admin.rb +5 -0
- data/app/models/shoppy/brand.rb +23 -0
- data/app/models/shoppy/cart_item.rb +13 -0
- data/app/models/shoppy/category.rb +50 -0
- data/app/models/shoppy/concerns/.DS_Store +0 -0
- data/app/models/shoppy/concerns/models/api_token_authenticatable.rb +36 -0
- data/app/models/shoppy/concerns/models/hashable.rb +60 -0
- data/app/models/shoppy/concerns/models/optionable.rb +60 -0
- data/app/models/shoppy/concerns/models/promotional.rb +36 -0
- data/app/models/shoppy/concerns/models/taggable.rb +44 -0
- data/app/models/shoppy/customer.rb +10 -0
- data/app/models/shoppy/customer_address.rb +44 -0
- data/app/models/shoppy/inventory.rb +18 -0
- data/app/models/shoppy/log.rb +8 -0
- data/app/models/shoppy/manufacturer.rb +35 -0
- data/app/models/shoppy/options_group.rb +57 -0
- data/app/models/shoppy/options_item.rb +18 -0
- data/app/models/shoppy/order.rb +15 -0
- data/app/models/shoppy/order_line.rb +16 -0
- data/app/models/shoppy/payment_method.rb +19 -0
- data/app/models/shoppy/product.rb +43 -0
- data/app/models/shoppy/review.rb +12 -0
- data/app/models/shoppy/setting.rb +11 -0
- data/app/models/shoppy/shipment.rb +11 -0
- data/app/models/shoppy/stock_location.rb +47 -0
- data/app/models/shoppy/user.rb +37 -0
- data/app/models/shoppy/variant.rb +48 -0
- data/app/views/.DS_Store +0 -0
- data/app/views/accounts/admins.html.erb +104 -0
- data/app/views/accounts/customers.html.erb +106 -0
- data/app/views/accounts/show.html.erb +50 -0
- data/app/views/brands/index.html.erb +85 -0
- data/app/views/brands/show.html.erb +31 -0
- data/app/views/cart/index.html.erb +52 -0
- data/app/views/categories/index.html.erb +84 -0
- data/app/views/categories/show.html.erb +29 -0
- data/app/views/customer_addresses/index.html.erb +112 -0
- data/app/views/customer_addresses/show.html.erb +50 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +29 -0
- data/app/views/devise/registrations/new.html.erb +23 -0
- data/app/views/devise/sessions/new.html.erb +33 -0
- data/app/views/devise/shared/_links.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/app/views/home/index.html.erb +4 -0
- data/app/views/inventories/.DS_Store +0 -0
- data/app/views/inventories/index.html.erb +119 -0
- data/app/views/layouts/.DS_Store +0 -0
- data/app/views/layouts/shoppy.html.erb +27 -0
- data/app/views/locations/index.html.erb +120 -0
- data/app/views/locations/show.html.erb +58 -0
- data/app/views/logs/index.html.erb +49 -0
- data/app/views/manufacturers/index.html.erb +119 -0
- data/app/views/manufacturers/show.html.erb +62 -0
- data/app/views/options/index.html.erb +90 -0
- data/app/views/options/show.html.erb +32 -0
- data/app/views/orders/index.html.erb +174 -0
- data/app/views/orders/show.html.erb +74 -0
- data/app/views/products/index.html.erb +102 -0
- data/app/views/products/show.html.erb +112 -0
- data/app/views/reviews/index.html.erb +58 -0
- data/app/views/reviews/show.html.erb +46 -0
- data/app/views/settings/show.html.erb +50 -0
- data/app/views/shared/_custom_file_input.html.erb +12 -0
- data/app/views/shared/_flashes.html.erb +21 -0
- data/app/views/shared/_navigation.html.erb +66 -0
- data/app/views/shipments/index.html.erb +97 -0
- data/app/views/shipments/show.html.erb +84 -0
- data/app/views/variants/index.html.erb +119 -0
- data/app/views/variants/show.html.erb +114 -0
- data/bin/shoppy +183 -0
- data/config/routes.rb +124 -0
- data/db/.DS_Store +0 -0
- data/db/migrate/001__setup_hstore.rb +9 -0
- data/db/migrate/002__create_logs.rb +11 -0
- data/db/migrate/003__devise_create_users.rb +49 -0
- data/db/migrate/004__add_personal_info_to_user.rb +8 -0
- data/db/migrate/005__create_user_addresses.rb +16 -0
- data/db/migrate/006__create_categories.rb +11 -0
- data/db/migrate/007__create_brands.rb +10 -0
- data/db/migrate/008__create_manufacturers.rb +19 -0
- data/db/migrate/009__create_options_groups.rb +10 -0
- data/db/migrate/010__create_options_items.rb +10 -0
- data/db/migrate/011__create_products.rb +14 -0
- data/db/migrate/012__create_product_options_joint_table.rb +9 -0
- data/db/migrate/013__create_stock_locations.rb +18 -0
- data/db/migrate/014__create_variants.rb +12 -0
- data/db/migrate/015__add_promotional_to_variant.rb +8 -0
- data/db/migrate/016__create_inventories.rb +12 -0
- data/db/migrate/017__create_payment_methods.rb +9 -0
- data/db/migrate/018__create_cart_items.rb +12 -0
- data/db/migrate/019__create_orders.rb +11 -0
- data/db/migrate/020__create_order_lines.rb +14 -0
- data/db/migrate/021__add_type_to_user.rb +5 -0
- data/db/migrate/022__rename_user_address_to_customer_address.rb +5 -0
- data/db/migrate/023__create_shipments.rb +12 -0
- data/db/migrate/024__add_shipment_id_to_order_line.rb +5 -0
- data/db/migrate/025__change_user_gender_to_not_nullable.rb +5 -0
- data/db/migrate/026__add_category_id_to_product.rb +5 -0
- data/db/migrate/027__add_attachment_brand_image_to_brands.rb +11 -0
- data/db/migrate/028__add_delivery_date_to_shipment.rb +5 -0
- data/db/migrate/029__add_customer_info_to_order.rb +13 -0
- data/db/migrate/030__add_status_to_order.rb +5 -0
- data/db/migrate/031__add_default_address_to_user.rb +5 -0
- data/db/migrate/032__add_options_to_variant.rb +5 -0
- data/db/migrate/033__add_display_to_options_groups.rb +5 -0
- data/db/migrate/034__add_points_to_variant.rb +5 -0
- data/db/migrate/035__add_points_to_user.rb +5 -0
- data/db/migrate/036__define_ids.rb +25 -0
- data/db/migrate/037__create_seed_users.rb +13 -0
- data/db/migrate/038__add_name_to_customer_address.rb +5 -0
- data/db/migrate/039__create_reviews.rb +14 -0
- data/db/migrate/040__alter_table_customer_address.rb +5 -0
- data/db/migrate/041__create_settings.rb +23 -0
- data/lib/.DS_Store +0 -0
- data/lib/shoppy.rb +13 -0
- data/lib/shoppy/client.rb +53 -0
- data/lib/shoppy/engine.rb +4 -0
- data/lib/shoppy/version.rb +3 -0
- data/lib/tasks/shoppy_tasks.rake +4 -0
- data/lib/template/.gitignore +20 -0
- data/lib/template/Gemfile +46 -0
- data/lib/template/Gemfile.lock +218 -0
- data/lib/template/Rakefile +6 -0
- data/lib/template/app/assets/images/.keep +0 -0
- data/lib/template/app/assets/javascripts/application.js +13 -0
- data/lib/template/app/assets/stylesheets/application.css +15 -0
- data/lib/template/app/controllers/accounts_controller.rb +3 -0
- data/lib/template/app/controllers/application_controller.rb +3 -0
- data/lib/template/app/controllers/brands_controller.rb +3 -0
- data/lib/template/app/controllers/cart_controller.rb +3 -0
- data/lib/template/app/controllers/categories_controller.rb +3 -0
- data/lib/template/app/controllers/concerns/.keep +0 -0
- data/lib/template/app/controllers/customer_addresses_controller.rb +3 -0
- data/lib/template/app/controllers/home_controller.rb +3 -0
- data/lib/template/app/controllers/inventories_controller.rb +3 -0
- data/lib/template/app/controllers/locations_controller.rb +3 -0
- data/lib/template/app/controllers/logs_controller.rb +3 -0
- data/lib/template/app/controllers/manufacturers_controller.rb +3 -0
- data/lib/template/app/controllers/options_controller.rb +3 -0
- data/lib/template/app/controllers/orders_controller.rb +3 -0
- data/lib/template/app/controllers/products_controller.rb +3 -0
- data/lib/template/app/controllers/reviews_controller.rb +3 -0
- data/lib/template/app/controllers/sessions_controller.rb +3 -0
- data/lib/template/app/controllers/settings_controller.rb +3 -0
- data/lib/template/app/controllers/shipments_controller.rb +3 -0
- data/lib/template/app/controllers/variants_controller.rb +3 -0
- data/lib/template/app/helpers/.keep +0 -0
- data/lib/template/app/helpers/orders_helper.rb +4 -0
- data/lib/template/app/mailers/.keep +0 -0
- data/lib/template/app/models/.keep +0 -0
- data/lib/template/app/models/account.rb +4 -0
- data/lib/template/app/models/admin.rb +4 -0
- data/lib/template/app/models/brand.rb +3 -0
- data/lib/template/app/models/cart_item.rb +3 -0
- data/lib/template/app/models/category.rb +3 -0
- data/lib/template/app/models/concerns/.keep +0 -0
- data/lib/template/app/models/concerns/hashable.rb +4 -0
- data/lib/template/app/models/customer.rb +4 -0
- data/lib/template/app/models/customer_address.rb +3 -0
- data/lib/template/app/models/inventory.rb +3 -0
- data/lib/template/app/models/log.rb +3 -0
- data/lib/template/app/models/manufacturer.rb +3 -0
- data/lib/template/app/models/option_item.rb +3 -0
- data/lib/template/app/models/options_group.rb +3 -0
- data/lib/template/app/models/order.rb +3 -0
- data/lib/template/app/models/order_line.rb +3 -0
- data/lib/template/app/models/payment_method.rb +3 -0
- data/lib/template/app/models/product.rb +3 -0
- data/lib/template/app/models/review.rb +3 -0
- data/lib/template/app/models/setting.rb +3 -0
- data/lib/template/app/models/shipment.rb +3 -0
- data/lib/template/app/models/stock_location.rb +3 -0
- data/lib/template/app/models/variant.rb +3 -0
- data/lib/template/app/views/layouts/.keep +0 -0
- data/lib/template/bin/bundle +3 -0
- data/lib/template/bin/rails +8 -0
- data/lib/template/bin/rake +8 -0
- data/lib/template/bin/spring +18 -0
- data/lib/template/config.ru +4 -0
- data/lib/template/config/application.rb +23 -0
- data/lib/template/config/boot.rb +4 -0
- data/lib/template/config/database.yml +86 -0
- data/lib/template/config/environment.rb +5 -0
- data/lib/template/config/environments/development.rb +37 -0
- data/lib/template/config/environments/production.rb +78 -0
- data/lib/template/config/environments/test.rb +39 -0
- data/lib/template/config/initializers/assets.rb +8 -0
- data/lib/template/config/initializers/backtrace_silencers.rb +7 -0
- data/lib/template/config/initializers/cookies_serializer.rb +3 -0
- data/lib/template/config/initializers/devise.rb +256 -0
- data/lib/template/config/initializers/filter_parameter_logging.rb +4 -0
- data/lib/template/config/initializers/inflections.rb +16 -0
- data/lib/template/config/initializers/mime_types.rb +4 -0
- data/lib/template/config/initializers/session_store.rb +3 -0
- data/lib/template/config/initializers/wrap_parameters.rb +14 -0
- data/lib/template/config/locales/devise.en.yml +59 -0
- data/lib/template/config/locales/en.yml +23 -0
- data/lib/template/config/routes.rb +3 -0
- data/lib/template/config/secrets.yml +22 -0
- data/lib/template/db/migrate/.keep +0 -0
- data/lib/template/db/seeds.rb +7 -0
- data/lib/template/lib/assets/.keep +0 -0
- data/lib/template/lib/tasks/.keep +0 -0
- data/lib/template/log/.keep +0 -0
- data/lib/template/public/404.html +67 -0
- data/lib/template/public/422.html +67 -0
- data/lib/template/public/500.html +66 -0
- data/lib/template/public/favicon.ico +0 -0
- data/lib/template/public/robots.txt +5 -0
- data/lib/template/test/controllers/.keep +0 -0
- data/lib/template/test/fixtures/.keep +0 -0
- data/lib/template/test/helpers/.keep +0 -0
- data/lib/template/test/integration/.keep +0 -0
- data/lib/template/test/mailers/.keep +0 -0
- data/lib/template/test/models/.keep +0 -0
- data/lib/template/test/test_helper.rb +10 -0
- data/lib/template/vendor/assets/javascripts/.keep +0 -0
- data/lib/template/vendor/assets/stylesheets/.keep +0 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/shoppy/Users/alybadawy/exp/shoppy/lib/template/Gemfile.lock +217 -0
- data/test/shoppy/Users/alybadawy/exp/shoppy/lib/template/README.rdoc +28 -0
- data/test/shoppy/Users/alybadawy/exp/shoppy/lib/template/config.ru +4 -0
- data/test/shoppy_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +495 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
module Shoppy
|
2
|
+
module OptionsHelper
|
3
|
+
def self.create_options_group(group_name, display, options_names)
|
4
|
+
items = options_names.split(',')
|
5
|
+
OptionsGroup.transaction do
|
6
|
+
g = OptionsGroup.new
|
7
|
+
g.name = group_name.downcase.titleize
|
8
|
+
g.display = display
|
9
|
+
g.save
|
10
|
+
items.each do |i|
|
11
|
+
OptionsItem.create(name: i.to_s, options_group_id: g.id)
|
12
|
+
end
|
13
|
+
return g
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.items_to_string(options_group)
|
18
|
+
ois = ""
|
19
|
+
options_group.options_items.order("name ASC").each do |oi|
|
20
|
+
ois += oi.name + ","
|
21
|
+
end
|
22
|
+
return ois[0..ois.length-2]
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def self.update_options_items(options_group)
|
27
|
+
o = options_group.optionsItems.split(',')
|
28
|
+
n = options_group.items_string.split(',')
|
29
|
+
o.each do |oi|
|
30
|
+
if n.include?(oi) == false
|
31
|
+
to_remove = OptionsItem.find_by(name: oi, options_group_id: options_group.id)
|
32
|
+
to_remove.destroy if to_remove
|
33
|
+
end
|
34
|
+
end
|
35
|
+
n.each do |ni|
|
36
|
+
if o.include?(ni) == false
|
37
|
+
OptionsItem.create(name: ni, options_group_id: options_group.id)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
return true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Shoppy
|
2
|
+
module OrdersHelper
|
3
|
+
|
4
|
+
def self.calculate_points(order)
|
5
|
+
Customer.transaction do
|
6
|
+
c = order.customer
|
7
|
+
ois = order.order_lines
|
8
|
+
ois.each do |ol|
|
9
|
+
c.points += (ol.variant.points * ol.quantity)
|
10
|
+
end
|
11
|
+
c.save
|
12
|
+
return true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.new_order(customer, order_lines_hash, customer_address)
|
17
|
+
OrderLine.transaction do
|
18
|
+
order = Order.new
|
19
|
+
order.customer = customer
|
20
|
+
order.customer_name = customer.name
|
21
|
+
order.customer_email = customer.email
|
22
|
+
order.customer_phone = customer.phone
|
23
|
+
order.customer_add_line1 = customer_address.add_line1
|
24
|
+
order.customer_add_line2 = customer_address.add_line2
|
25
|
+
order.customer_city = customer_address.city
|
26
|
+
order.customer_state = customer_address.state
|
27
|
+
order.customer_country = customer_address.country
|
28
|
+
order.customer_zip = customer_address.zip
|
29
|
+
order.save
|
30
|
+
order_total_price = 0.0
|
31
|
+
ols = []
|
32
|
+
order_lines_hash.each do |variant_id, quantity|
|
33
|
+
v = Variant.find_by(id: variant_id)
|
34
|
+
if v && quantity > 0
|
35
|
+
ol = OrderLine.new
|
36
|
+
ol.order = order
|
37
|
+
ol.variant = Variant.find(variant_id.to_i)
|
38
|
+
ol.quantity = quantity.to_i
|
39
|
+
ol.price_per_one = ol.variant.price
|
40
|
+
line_totalprice = ol.quantity * ol.price_per_one
|
41
|
+
order_total_price += line_totalprice
|
42
|
+
ols += [ol]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
order.total_price = order_total_price
|
46
|
+
order.date = Date.today
|
47
|
+
order.order_lines = ols
|
48
|
+
if ols.count > 0 && order.save
|
49
|
+
OrdersHelper::calculate_points(order)
|
50
|
+
return order
|
51
|
+
else
|
52
|
+
return nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Shoppy
|
2
|
+
module ProductsHelper
|
3
|
+
def self.add_options_groups_to_product(product, options_groups)
|
4
|
+
product.options_groups += options_groups
|
5
|
+
product.save
|
6
|
+
vs = product.variants
|
7
|
+
vs.each do |v|
|
8
|
+
options_groups.each do |og|
|
9
|
+
v.put_option(og.name, "")
|
10
|
+
end
|
11
|
+
v.save
|
12
|
+
end
|
13
|
+
return product
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.remove_options_groups_from_product(product, options_groups)
|
17
|
+
product.options_groups -= options_groups
|
18
|
+
product.save
|
19
|
+
vs = product.variants
|
20
|
+
vs.each do |v|
|
21
|
+
options_groups.each do |og|
|
22
|
+
v.delete_option(og.name)
|
23
|
+
end
|
24
|
+
v.save
|
25
|
+
end
|
26
|
+
return product
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.update_options_groups_for_product(product, options_groups)
|
30
|
+
Product.transaction do
|
31
|
+
original_groups = product.options_groups
|
32
|
+
new_groups = options_groups
|
33
|
+
added_groups = new_groups - original_groups
|
34
|
+
removed_groups = original_groups - new_groups
|
35
|
+
puts remove_options_groups_from_product(product, removed_groups)
|
36
|
+
puts add_options_groups_to_product(product, added_groups)
|
37
|
+
return true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.createVariants_for_product(product, variants_names)
|
42
|
+
variants_names.each do |vn|
|
43
|
+
v = Variant.new
|
44
|
+
v.name = vn
|
45
|
+
v.product = product
|
46
|
+
product.options_groups.each do |h|
|
47
|
+
v.put_option(h.name, "")
|
48
|
+
end
|
49
|
+
v.save
|
50
|
+
end
|
51
|
+
return product
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def self.convert_params_groups_to_objects(params)
|
56
|
+
options_ids = params
|
57
|
+
options = []
|
58
|
+
options_ids.each do |o_id|
|
59
|
+
o = OptionsGroup.find_by(id: o_id.to_i)
|
60
|
+
(options += [o]) if o
|
61
|
+
end
|
62
|
+
return options
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Shoppy
|
2
|
+
module ShipmentsHelper
|
3
|
+
def self.prepare_shipment(order, order_lines, stock_location, customer_address)
|
4
|
+
if(order.customer_address == customer_address.customer) && ((order_lines - order.orderlines).empty?)
|
5
|
+
Shipment.transaction do
|
6
|
+
s = Shipment.new
|
7
|
+
s.order = order
|
8
|
+
s.stock_location = stock_location
|
9
|
+
s.order_lines = order_lines
|
10
|
+
order_lines.each do |ol|
|
11
|
+
InventoriesHelper::deduct_variant_from_stuck_location(ol.variant, ol.quantity, stock_location)
|
12
|
+
end
|
13
|
+
s.name = customer_address.customer.name
|
14
|
+
s.phone = customer_address.customer.phone
|
15
|
+
s.add_line1 = customer_address.add_line1
|
16
|
+
s.add_line2 = customer_address.add_line2
|
17
|
+
s.city = customer_address.city
|
18
|
+
s.state = customer_address.state
|
19
|
+
s.country = customer_address.country
|
20
|
+
s.zip = customer_address.zip
|
21
|
+
return s.save
|
22
|
+
end
|
23
|
+
else
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.ship_shipment(shipment, tracking_number)
|
29
|
+
s = shipment
|
30
|
+
s.tracking_number = tracking_number
|
31
|
+
s.shipment_date = Date.today
|
32
|
+
s.status = "Shipped"
|
33
|
+
return s.save
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.mark_shipment_delivered(shipment)
|
37
|
+
s = shipment
|
38
|
+
s.status = "Delivered"
|
39
|
+
s.delivery_date = Date.today
|
40
|
+
return s.save
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Shoppy
|
2
|
+
class Brand < ActiveRecord::Base
|
3
|
+
## Relationships
|
4
|
+
has_many :products, dependent: :nullify
|
5
|
+
|
6
|
+
has_attached_file :brand_image,
|
7
|
+
:path => ":rails_root/public/uploads/brands/:id_:style_:filename",
|
8
|
+
:url => "/uploads/brands/:id_:style_:filename",
|
9
|
+
:default_url => "/system/no_brand.png"
|
10
|
+
|
11
|
+
## Validators
|
12
|
+
validates_attachment :brand_image,
|
13
|
+
presence: true,
|
14
|
+
content_type: { content_type: /\Aimage\/.*\Z/ },
|
15
|
+
size: { less_than: 1.megabyte }
|
16
|
+
|
17
|
+
validates :name, presence: true
|
18
|
+
validates :name, length: { in: 2..100, too_short: "must have at least %{count} letters", too_long: "must have at most %{count} letters" }
|
19
|
+
validates :name, uniqueness: true
|
20
|
+
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Shoppy
|
2
|
+
class CartItem < ActiveRecord::Base
|
3
|
+
## Relationships
|
4
|
+
belongs_to :customer
|
5
|
+
belongs_to :variant
|
6
|
+
|
7
|
+
## Validators
|
8
|
+
validates :quantity, presence: true
|
9
|
+
validates :quantity, :numericality => { :greater_than_or_equal_to => 0 }
|
10
|
+
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Shoppy
|
2
|
+
class Category < ActiveRecord::Base
|
3
|
+
## Relationships
|
4
|
+
belongs_to :parent_category, class_name: "Category"
|
5
|
+
has_many :child_categories, class_name: "Category", foreign_key: "parent_category_id", dependent: :nullify
|
6
|
+
has_many :products, dependent: :nullify
|
7
|
+
|
8
|
+
## Filters
|
9
|
+
before_save :caps
|
10
|
+
|
11
|
+
## Validators
|
12
|
+
validates :name, presence: true
|
13
|
+
validates :name, length: { in: 2..100, too_short: "must have at least %{count} letters", too_long: "must have at most %{count} letters" }
|
14
|
+
validates :name, uniqueness: true
|
15
|
+
validate :parent_is_not_same_category
|
16
|
+
|
17
|
+
|
18
|
+
def breadcrumb
|
19
|
+
bc = [self.id]
|
20
|
+
fbc = "Root -> "
|
21
|
+
c = self
|
22
|
+
while c.parent_category
|
23
|
+
bc.append(c.parent_category.id)
|
24
|
+
c = c.parent_category
|
25
|
+
end
|
26
|
+
bc.reverse.each do |c|
|
27
|
+
fbc += (Category.find(c).name + " -> ")
|
28
|
+
end
|
29
|
+
fbc[0..(fbc.length - 5)]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.all_sorted
|
33
|
+
self.all.sort_by {|c| c.breadcrumb }
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
private
|
40
|
+
def parent_is_not_same_category
|
41
|
+
if (self.parent_category_id != nil) && (self.parent_category_id == self.id)
|
42
|
+
errors.add(:parent_category, "is same as selected category.")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
def caps
|
46
|
+
self.name = self.name.downcase.titleize
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
Binary file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Shoppy::Concerns::Models::ApiTokenAuthenticatable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
# For every model that you want to make ApiTokenAuthenticatable,
|
5
|
+
# Add the following attributes to the model:
|
6
|
+
# string :api_token, null: false, default: ""
|
7
|
+
# datetime :api_token_expires_at
|
8
|
+
# boolean :api_token_active, null: false, default: false
|
9
|
+
|
10
|
+
|
11
|
+
def api_token_expired?
|
12
|
+
DateTime.now >= self.api_token_expires_at
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid_api_token?
|
16
|
+
self.api_token_active && !self.api_token_expired?
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def generate_api_token
|
21
|
+
begin
|
22
|
+
self.api_token = SecureRandom.hex
|
23
|
+
end while self.class.exists?(api_token: api_token)
|
24
|
+
self.api_token_expires_at = DateTime.now + 1.day
|
25
|
+
self.api_token_active = true
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def invalidate_api_token
|
30
|
+
self.api_token = ""
|
31
|
+
self.api_token_expires_at = Time.now
|
32
|
+
self.api_token_active = false
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Shoppy::Concerns::Models::Hashable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
## For each model that you need to make 'Hashable', make sure
|
5
|
+
## You have an attribute called 'hash_data' for that model.
|
6
|
+
## Also, make sure to give that attribute a default value in
|
7
|
+
## the database that is equal to an empty hash, or '{}'
|
8
|
+
##
|
9
|
+
## In simple format, add this field to your migration file:
|
10
|
+
## # Hashable
|
11
|
+
## t.hstore :hash_data, null: false, default: {}
|
12
|
+
|
13
|
+
|
14
|
+
# This method will add a key value paid to the model
|
15
|
+
# or update the value of the key, if the key is found
|
16
|
+
# for a given instance of the model
|
17
|
+
def put_hash(key, value)
|
18
|
+
if self.hash_data[key] == nil
|
19
|
+
self.hash_data.merge!({key => value}) unless key == ""
|
20
|
+
self.hash_data_will_change! unless key == ""
|
21
|
+
self
|
22
|
+
else
|
23
|
+
self.hash_data[key] = value unless key == ""
|
24
|
+
self.hash_data_will_change! unless key == ""
|
25
|
+
self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# This mothos will delete the key/value pair for the
|
30
|
+
# give instance, if the key is founf. if not, the command
|
31
|
+
# will be ignored.
|
32
|
+
def delete_hash(key)
|
33
|
+
self.hash_data.delete(key)
|
34
|
+
self.hash_data_will_change!
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def empty_hash
|
39
|
+
self.hash_data = {}
|
40
|
+
self.hash_data_will_change!
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
## These are shared mothods, a.k.a class methods
|
46
|
+
module ClassMethods
|
47
|
+
# Query all model instances that have a given key,
|
48
|
+
# regardless of the valiue for that key.
|
49
|
+
def by_hash_key(key)
|
50
|
+
self.where("hash_data ? :key", key: key)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Query all model instance sthat have a given
|
54
|
+
# key/value pair.
|
55
|
+
def by_hash_key_value(key, value)
|
56
|
+
kv = key + "=>" + value
|
57
|
+
self.where("hash_data @> :kv", kv: kv)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Shoppy::Concerns::Models::Optionable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
## For each model that you need to make 'Optionable', make sure
|
5
|
+
## You have an attribute called 'options' for that model.
|
6
|
+
## Also, make sure to give that attribute a default value in
|
7
|
+
## the database that is equal to an empty option, or '{}'
|
8
|
+
##
|
9
|
+
## In simple format, add this field to your migration file:
|
10
|
+
## # Optionable
|
11
|
+
## t.hstore :options, null: false, default: {}
|
12
|
+
|
13
|
+
|
14
|
+
# This method will add a key value paid to the model
|
15
|
+
# or update the value of the key, if the key is found
|
16
|
+
# for a given instance of the model
|
17
|
+
def put_option(key, value)
|
18
|
+
if self.options[key] == nil
|
19
|
+
self.options.merge!({key => value}) unless key == ""
|
20
|
+
self.options_will_change! unless key == ""
|
21
|
+
self
|
22
|
+
else
|
23
|
+
self.options[key] = value unless key == ""
|
24
|
+
self.options_will_change! unless key == ""
|
25
|
+
self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# This mothos will delete the key/value pair for the
|
30
|
+
# give instance, if the key is founf. if not, the command
|
31
|
+
# will be ignored.
|
32
|
+
def delete_option(key)
|
33
|
+
self.options.delete(key)
|
34
|
+
self.options_will_change!
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def empty_option
|
39
|
+
self.options = {}
|
40
|
+
self.options_will_change!
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
## These are shared mothods, a.k.a class methods
|
46
|
+
module ClassMethods
|
47
|
+
# Query all model instances that have a given key,
|
48
|
+
# regardless of the valiue for that key.
|
49
|
+
def by_option_key(key)
|
50
|
+
self.where("options ? :key", key: key)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Query all model instance sthat have a given
|
54
|
+
# key/value pair.
|
55
|
+
def by_option_key_value(key, value)
|
56
|
+
kv = key + "=>" + value
|
57
|
+
self.where("options @> :kv", kv: kv)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|