radiant-shop-extension 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -1
- data/VERSION +1 -1
- data/app/controllers/admin/shop/categories_controller.rb +32 -65
- data/app/controllers/admin/shop/customers_controller.rb +8 -7
- data/app/controllers/admin/shop/orders_controller.rb +37 -159
- data/app/controllers/admin/shop/packages/packings_controller.rb +90 -0
- data/app/controllers/admin/shop/packages_controller.rb +65 -0
- data/app/controllers/admin/shop/products/images_controller.rb +5 -8
- data/app/controllers/admin/shop/products/variant_templates_controller.rb +27 -0
- data/app/controllers/admin/shop/products/variants_controller.rb +60 -0
- data/app/controllers/admin/shop/products_controller.rb +67 -64
- data/app/controllers/admin/shop/variants_controller.rb +49 -0
- data/app/helpers/shop_helper.rb +5 -0
- data/app/models/form_address.rb +144 -0
- data/app/models/form_checkout.rb +200 -307
- data/app/models/form_line_item.rb +60 -0
- data/app/models/shop_address.rb +2 -2
- data/app/models/shop_category.rb +48 -51
- data/app/models/shop_customer.rb +25 -5
- data/app/models/shop_group.rb +15 -0
- data/app/models/shop_grouping.rb +6 -0
- data/app/models/shop_line_item.rb +7 -6
- data/app/models/shop_order.rb +44 -16
- data/app/models/shop_package.rb +74 -0
- data/app/models/shop_packing.rb +22 -0
- data/app/models/shop_page.rb +7 -0
- data/app/models/shop_payment.rb +5 -1
- data/app/models/shop_product.rb +86 -48
- data/app/models/shop_product_attachment.rb +5 -2
- data/app/models/shop_product_variant.rb +31 -0
- data/app/models/shop_variant.rb +25 -0
- data/app/views/admin/shop/categories/edit.html.haml +9 -10
- data/app/views/admin/shop/categories/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/categories/edit/_form.html.haml +14 -0
- data/app/views/admin/shop/categories/edit/_head.html.haml +4 -2
- data/app/views/admin/shop/categories/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/categories/edit/_meta.html.haml +8 -7
- data/app/views/admin/shop/categories/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/categories/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/categories/edit/inputs/_name.html.haml +4 -0
- data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +6 -5
- data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +6 -5
- data/app/views/admin/shop/categories/edit/meta/_page.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/parts/_description.html.haml +4 -1
- data/app/views/admin/shop/categories/index/_category.html.haml +11 -10
- data/app/views/admin/shop/categories/new.html.haml +10 -9
- data/app/views/admin/shop/customers/edit.html.haml +8 -10
- data/app/views/admin/shop/customers/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/customers/edit/_form.html.haml +13 -0
- data/app/views/admin/shop/customers/edit/_head.html.haml +4 -2
- data/app/views/admin/shop/customers/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/customers/edit/_parts.html.haml +9 -4
- data/app/views/admin/shop/customers/edit/inputs/_email.html.haml +3 -0
- data/app/views/admin/shop/customers/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/customers/edit/parts/_orders.html.haml +10 -6
- data/app/views/admin/shop/customers/index.html.haml +4 -1
- data/app/views/admin/shop/customers/index/_customer.html.haml +3 -3
- data/app/views/admin/shop/customers/index/_foot.html.haml +4 -0
- data/app/views/admin/shop/customers/index/_head.html.haml +4 -0
- data/app/views/admin/shop/customers/new.html.haml +9 -9
- data/app/views/admin/shop/orders/edit.html.haml +11 -0
- data/app/views/admin/shop/orders/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/orders/edit/_form.html.haml +13 -0
- data/app/views/admin/shop/orders/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/orders/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/orders/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/orders/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/orders/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/orders/edit/parts/_address.html.haml +7 -0
- data/app/views/admin/shop/orders/edit/parts/_addresses.html.haml +9 -0
- data/app/views/admin/shop/orders/edit/parts/_customer.html.haml +3 -0
- data/app/views/admin/shop/orders/edit/parts/_items.html.haml +8 -0
- data/app/views/admin/shop/orders/index.html.haml +10 -30
- data/app/views/admin/shop/orders/index/_foot.html.haml +3 -0
- data/app/views/admin/shop/orders/index/_head.html.haml +4 -0
- data/app/views/admin/shop/orders/index/_order.html.haml +13 -0
- data/app/views/admin/shop/orders/index/buttons/_all.html.haml +1 -0
- data/app/views/admin/shop/orders/index/buttons/_new.html.haml +1 -0
- data/app/views/admin/shop/orders/index/buttons/_paid.html.haml +1 -0
- data/app/views/admin/shop/orders/index/buttons/_shipped.html.haml +1 -0
- data/app/views/admin/shop/packages/edit.html.haml +11 -0
- data/app/views/admin/shop/packages/edit/_foot.html.haml +17 -0
- data/app/views/admin/shop/packages/edit/_form.html.haml +15 -0
- data/app/views/admin/shop/packages/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/packages/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/packages/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/packages/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/packages/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +1 -0
- data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +5 -0
- data/app/views/admin/shop/packages/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/packages/edit/parts/_products.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +7 -0
- data/app/views/admin/shop/packages/edit/shared/_product.html.haml +8 -0
- data/app/views/admin/shop/packages/index.html.haml +13 -0
- data/app/views/admin/shop/packages/index/_foot.html.haml +7 -0
- data/app/views/admin/shop/packages/index/_head.html.haml +4 -0
- data/app/views/admin/shop/packages/index/_package.html.haml +9 -0
- data/app/views/admin/shop/packages/new.html.haml +11 -0
- data/app/views/admin/shop/packages/remove.html.haml +12 -0
- data/app/views/admin/shop/products/edit.html.haml +9 -12
- data/app/views/admin/shop/products/edit/_foot.html.haml +19 -0
- data/app/views/admin/shop/products/edit/_form.html.haml +15 -0
- data/app/views/admin/shop/products/edit/_head.html.haml +4 -2
- data/app/views/admin/shop/products/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/products/edit/_meta.html.haml +8 -8
- data/app/views/admin/shop/products/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/products/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -1
- data/app/views/admin/shop/products/edit/buttons/_browse_templates.html.haml +1 -0
- data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -1
- data/app/views/admin/shop/products/edit/buttons/_new_variant.html.haml +1 -0
- data/app/views/admin/shop/products/edit/inputs/_name.html.haml +4 -0
- data/app/views/admin/shop/products/edit/inputs/_price.html.haml +3 -0
- data/app/views/admin/shop/products/edit/meta/_category.html.haml +6 -5
- data/app/views/admin/shop/products/edit/meta/_page.html.haml +2 -0
- data/app/views/admin/shop/products/edit/meta/_sku.html.haml +6 -5
- data/app/views/admin/shop/products/edit/parts/_customers.html.haml +5 -0
- data/app/views/admin/shop/products/edit/parts/_description.html.haml +4 -1
- data/app/views/admin/shop/products/edit/parts/_images.html.haml +1 -1
- data/app/views/admin/shop/products/edit/parts/_variants.html.haml +3 -0
- data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +1 -1
- data/app/views/admin/shop/products/edit/popups/_browse_templates.html.haml +6 -0
- data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +4 -4
- data/app/views/admin/shop/products/edit/popups/_new_variant.html.haml +16 -0
- data/app/views/admin/shop/products/edit/{_image.html.haml → shared/_image.html.haml} +0 -0
- data/app/views/admin/shop/products/edit/shared/_template.html.haml +6 -0
- data/app/views/admin/shop/products/edit/shared/_variant.html.haml +10 -0
- data/app/views/admin/shop/products/index.html.haml +6 -3
- data/app/views/admin/shop/products/index/_foot.html.haml +10 -0
- data/app/views/admin/shop/products/index/_head.html.haml +4 -0
- data/app/views/admin/shop/products/index/_product.html.haml +18 -10
- data/app/views/admin/shop/products/index/buttons/_discounts.html.haml +1 -0
- data/app/views/admin/shop/products/index/buttons/_packages.html.haml +1 -0
- data/app/views/admin/shop/products/index/buttons/_variants.html.haml +1 -0
- data/app/views/admin/shop/products/new.html.haml +10 -9
- data/app/views/admin/shop/variants/edit.html.haml +11 -0
- data/app/views/admin/shop/variants/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/variants/edit/_form.html.haml +13 -0
- data/app/views/admin/shop/variants/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/variants/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/variants/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/variants/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/variants/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/variants/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/variants/edit/inputs/_options.html.haml +3 -0
- data/app/views/admin/shop/variants/index.html.haml +13 -0
- data/app/views/admin/shop/variants/index/_foot.html.haml +4 -0
- data/app/views/admin/shop/variants/index/_head.html.haml +4 -0
- data/app/views/admin/shop/variants/index/_variant.html.haml +9 -0
- data/app/views/admin/shop/variants/new.html.haml +11 -0
- data/app/views/admin/shop/variants/remove.html.haml +12 -0
- data/config/locales/en.yml +8 -1
- data/config/routes.rb +11 -22
- data/db/migrate/20100929011106_fix_relationship_foreign_keys.rb +101 -0
- data/db/migrate/20100929011607_drop_shop_addressables.rb +25 -0
- data/db/migrate/20100929030510_create_shop_groups.rb +19 -0
- data/db/migrate/20100929080301_shop_groups_change_add_description.rb +11 -0
- data/db/migrate/20100929081200_create_variants.rb +20 -0
- data/db/migrate/20100929143531_change_variants_add_updated_by.rb +25 -0
- data/db/migrate/20100929145641_change_created_by_to_id.rb +75 -0
- data/db/migrate/20100929235221_change_category_add_variant_id.rb +9 -0
- data/db/migrate/20100930235221_create_packages.rb +31 -0
- data/db/migrate/20101005231713_create_page_ids.rb +11 -0
- data/db/migrate/20101006051214_create_pages_for_products_and_categories.rb +73 -0
- data/db/migrate/20101007111845_add_default_position_to_attachment.rb +9 -0
- data/lib/shop/controllers/application_controller.rb +1 -1
- data/lib/shop/interface/categories.rb +29 -0
- data/lib/shop/interface/customers.rb +15 -15
- data/lib/shop/interface/orders.rb +34 -0
- data/lib/shop/interface/packages.rb +34 -0
- data/lib/shop/interface/products.rb +18 -31
- data/lib/shop/interface/variants.rb +34 -0
- data/lib/shop/models/form_extension.rb +23 -0
- data/lib/shop/models/page.rb +3 -2
- data/lib/shop/tags/address.rb +3 -3
- data/lib/shop/tags/cart.rb +12 -16
- data/lib/shop/tags/category.rb +4 -6
- data/lib/shop/tags/helpers.rb +131 -30
- data/lib/shop/tags/item.rb +16 -33
- data/lib/shop/tags/package.rb +95 -0
- data/lib/shop/tags/product.rb +11 -16
- data/lib/shop/tags/product_variant.rb +52 -0
- data/mockups/discounts/new-edit.bmml +492 -0
- data/public/javascripts/admin/extensions/shop/edit.js +20 -0
- data/public/javascripts/admin/extensions/shop/packages/edit.js +109 -0
- data/public/javascripts/admin/extensions/shop/products/edit.js +64 -65
- data/public/javascripts/admin/extensions/shop/products/index.js +31 -36
- data/public/stylesheets/sass/admin/extensions/shop/edit.sass +58 -11
- data/public/stylesheets/sass/admin/extensions/shop/index.sass +104 -53
- data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +162 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +115 -36
- data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +12 -20
- data/radiant-shop-extension.gemspec +182 -38
- data/shop_extension.rb +29 -25
- data/spec/controllers/admin/shop/categories_controller_spec.rb +76 -191
- data/spec/controllers/admin/shop/customers_controller_spec.rb +67 -0
- data/spec/controllers/admin/shop/orders_controller_spec.rb +85 -0
- data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +188 -0
- data/spec/controllers/admin/shop/packages_controller_spec.rb +32 -0
- data/spec/controllers/admin/shop/products/images_controller_spec.rb +10 -15
- data/spec/controllers/admin/shop/products/variant_templates_controller_spec.rb +53 -0
- data/spec/controllers/admin/shop/products/variants_controller_spec.rb +116 -0
- data/spec/controllers/admin/shop/products_controller_spec.rb +80 -148
- data/spec/controllers/admin/shop/variants_controller_spec.rb +67 -0
- data/spec/datasets/forms.rb +23 -8
- data/spec/datasets/shop_addresses.rb +1 -4
- data/spec/datasets/shop_categories.rb +25 -4
- data/spec/datasets/shop_groups.rb +15 -0
- data/spec/datasets/shop_line_items.rb +4 -3
- data/spec/datasets/shop_orders.rb +6 -15
- data/spec/datasets/shop_packages.rb +25 -0
- data/spec/datasets/shop_payments.rb +12 -0
- data/spec/datasets/{images.rb → shop_product_attachments.rb} +9 -1
- data/spec/datasets/shop_product_variants.rb +22 -0
- data/spec/datasets/shop_products.rb +28 -18
- data/spec/datasets/shop_variants.rb +17 -0
- data/spec/lib/shop/models/image_spec.rb +4 -4
- data/spec/lib/shop/tags/address_spec.rb +3 -3
- data/spec/lib/shop/tags/cart_spec.rb +32 -43
- data/spec/lib/shop/tags/category_spec.rb +58 -93
- data/spec/lib/shop/tags/helpers_spec.rb +162 -69
- data/spec/lib/shop/tags/item_spec.rb +116 -158
- data/spec/lib/shop/tags/package_spec.rb +342 -0
- data/spec/lib/shop/tags/product_spec.rb +29 -26
- data/spec/lib/shop/tags/product_variant_spec.rb +175 -0
- data/spec/models/form_address_spec.rb +166 -0
- data/spec/models/form_checkout_spec.rb +27 -157
- data/spec/models/shop_address_spec.rb +81 -0
- data/spec/models/shop_category_spec.rb +114 -31
- data/spec/models/shop_customer_spec.rb +105 -0
- data/spec/models/shop_group_spec.rb +38 -0
- data/spec/models/shop_line_item_spec.rb +5 -5
- data/spec/models/shop_order_spec.rb +89 -83
- data/spec/models/shop_package_spec.rb +117 -0
- data/spec/models/shop_packing_spec.rb +67 -0
- data/spec/models/shop_payment_spec.rb +19 -0
- data/spec/models/shop_product_attachment_spec.rb +4 -3
- data/spec/models/shop_product_spec.rb +171 -92
- data/spec/models/shop_product_variant_spec.rb +92 -0
- data/spec/models/shop_variant_spec.rb +47 -0
- metadata +183 -39
- data/app/controllers/shop/categories_controller.rb +0 -45
- data/app/controllers/shop/line_items_controller.rb +0 -165
- data/app/controllers/shop/orders_controller.rb +0 -16
- data/app/controllers/shop/products_controller.rb +0 -48
- data/app/models/shop_addressable.rb +0 -11
- data/app/views/admin/shop/categories/edit/_fields.html.haml +0 -28
- data/app/views/admin/shop/categories/edit/_part.html.haml +0 -3
- data/app/views/admin/shop/categories/edit/_popup.html.haml +0 -3
- data/app/views/admin/shop/customers/edit/_fields.html.haml +0 -33
- data/app/views/admin/shop/customers/index/_bottom.html.haml +0 -4
- data/app/views/admin/shop/products/edit/_fields.html.haml +0 -38
- data/app/views/admin/shop/products/edit/_part.html.haml +0 -3
- data/app/views/admin/shop/products/edit/_popup.html.haml +0 -3
- data/app/views/admin/shop/products/index/_bottom.html.haml +0 -5
- data/spec/controllers/shop/categories_controller_spec.rb +0 -42
- data/spec/controllers/shop/line_items_controller_spec.rb +0 -256
- data/spec/controllers/shop/orders_controller_specs.rb +0 -37
- data/spec/controllers/shop/products_controller_spec.rb +0 -51
- data/vendor/plugins/json_fields/.gitignore +0 -3
- data/vendor/plugins/json_fields/MIT-LICENSE +0 -20
- data/vendor/plugins/json_fields/README.rdoc +0 -65
- data/vendor/plugins/json_fields/Rakefile +0 -55
- data/vendor/plugins/json_fields/init.rb +0 -2
- data/vendor/plugins/json_fields/lib/json_fields.rb +0 -99
- data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +0 -124
- data/vendor/plugins/json_fields/spec/spec.opts +0 -6
- data/vendor/plugins/json_fields/spec/spec_helper.rb +0 -29
- data/vendor/plugins/json_fields/spec/test_models.rb +0 -12
@@ -0,0 +1,60 @@
|
|
1
|
+
class FormLineItem
|
2
|
+
include Forms::Models::Extension
|
3
|
+
|
4
|
+
# line_item:
|
5
|
+
# process: add|update|remove
|
6
|
+
|
7
|
+
def create
|
8
|
+
@result ||= {}
|
9
|
+
find_or_create_current_order
|
10
|
+
|
11
|
+
case process
|
12
|
+
when 'add'
|
13
|
+
@result[:add] = @order.add(line_item_item_id,line_item_quantity,line_item_item_type)
|
14
|
+
when 'modify'
|
15
|
+
@result[:modify] = @order.modify(line_item_id,line_item_quantity)
|
16
|
+
when 'remove'
|
17
|
+
@result[:remove] = @order.remove(line_item_id,line_item_quantity)
|
18
|
+
end
|
19
|
+
|
20
|
+
@result
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
# Uses the page session data to find the current order
|
26
|
+
def find_or_create_current_order
|
27
|
+
begin
|
28
|
+
@order = ShopOrder.find(@page.request.session[:shop_order])
|
29
|
+
rescue
|
30
|
+
@order = ShopOrder.create
|
31
|
+
@result[:session] = { :shop_order => @order.id }
|
32
|
+
end
|
33
|
+
@order.update_attribute(:customer_id, (current_customer.id rescue nil)) # either assign it to a user, or don't
|
34
|
+
end
|
35
|
+
|
36
|
+
def process
|
37
|
+
@config[:process]
|
38
|
+
end
|
39
|
+
|
40
|
+
def line_item
|
41
|
+
@data[:line_item]
|
42
|
+
end
|
43
|
+
|
44
|
+
def line_item_id
|
45
|
+
line_item[:id]
|
46
|
+
end
|
47
|
+
|
48
|
+
def line_item_item_id
|
49
|
+
line_item[:item_id]
|
50
|
+
end
|
51
|
+
|
52
|
+
def line_item_item_type
|
53
|
+
line_item[:item_type]
|
54
|
+
end
|
55
|
+
|
56
|
+
def line_item_quantity
|
57
|
+
line_item[:quantity]
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/app/models/shop_address.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class ShopAddress < ActiveRecord::Base
|
2
2
|
|
3
|
-
has_many :
|
4
|
-
has_many :
|
3
|
+
has_many :billings, :class_name => 'ShopOrder', :foreign_key => :billing_id
|
4
|
+
has_many :shippings, :class_name => 'ShopOrder', :foreign_key => :shipping_id
|
5
5
|
|
6
6
|
validates_presence_of :name
|
7
7
|
validates_presence_of :street
|
data/app/models/shop_category.rb
CHANGED
@@ -1,85 +1,82 @@
|
|
1
1
|
class ShopCategory < ActiveRecord::Base
|
2
2
|
|
3
|
-
default_scope :
|
3
|
+
default_scope :joins => 'JOIN pages AS page ON page.id = shop_categories.page_id JOIN pages AS parent ON page.parent_id = parent.id',
|
4
|
+
:order => 'parent.position, page.position ASC'
|
4
5
|
|
6
|
+
belongs_to :page, :dependent => :destroy
|
5
7
|
belongs_to :created_by, :class_name => 'User'
|
6
8
|
belongs_to :updated_by, :class_name => 'User'
|
7
|
-
belongs_to :layout
|
8
9
|
belongs_to :product_layout, :class_name => 'Layout'
|
9
10
|
|
10
|
-
|
11
|
+
before_validation :assign_slug, :assign_breadcrumb
|
11
12
|
|
12
|
-
|
13
|
+
accepts_nested_attributes_for :page
|
13
14
|
|
14
|
-
validates_presence_of
|
15
|
+
validates_presence_of :page
|
15
16
|
|
16
|
-
|
17
|
+
# Returns the title of the product's page
|
18
|
+
def name; page.title; end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
def custom=(values)
|
21
|
-
values.each do |key, value|
|
22
|
-
self.json_field_set(key, value)
|
23
|
-
end
|
24
|
-
end
|
20
|
+
# Returns the url of the page formatted as an sku
|
21
|
+
def handle; ShopProduct.to_sku(page.url); end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
23
|
+
# Returns the content of the product's page's description part
|
24
|
+
def description; page.parts.find_by_name('description').content end
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
end
|
26
|
+
# Returns products through the pages children
|
27
|
+
def products; page.children.map(&:shop_product); end
|
33
28
|
|
34
|
-
|
29
|
+
# Returns the url of the page
|
30
|
+
def url; page.url; end
|
31
|
+
|
32
|
+
# Returns the page slug
|
33
|
+
def slug; page.slug; end
|
34
|
+
|
35
|
+
# Overloads the base to_json to return what we want
|
36
|
+
def to_json(*attrs); super self.class.params; end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
conditions = [sql, {:term => "%#{search.downcase}%" }]
|
45
|
-
else
|
46
|
-
conditions = []
|
38
|
+
class << self
|
39
|
+
|
40
|
+
# Sorts a group of categories based on their ID and position in an array
|
41
|
+
def sort(*category_ids)
|
42
|
+
category_ids.each_with_index do |id, index|
|
43
|
+
ShopCategory.find(id).page.update_attributes!(
|
44
|
+
:position => index+1
|
45
|
+
)
|
47
46
|
end
|
48
|
-
|
49
|
-
all({ :conditions => conditions })
|
50
47
|
end
|
51
48
|
|
49
|
+
# Returns attributes attached to the category
|
52
50
|
def attrs
|
53
|
-
[ :id, :
|
51
|
+
[ :id, :product_layout_id, :page_id, :created_at, :updated_at ]
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns methods with usefuly information
|
55
|
+
def methds
|
56
|
+
[ :name, :description, :handle, :url, :created_at, :updated_at ]
|
54
57
|
end
|
55
58
|
|
59
|
+
# Returns a custom hash of attributes on the category
|
56
60
|
def params
|
57
|
-
{
|
58
|
-
:include => { :products => { :only => ShopProduct.attrs } },
|
59
|
-
:only => ShopCategory.attrs
|
60
|
-
}
|
61
|
+
{ :only => self.attrs, :methods => self.methds }
|
61
62
|
end
|
62
63
|
|
63
64
|
end
|
64
65
|
|
65
|
-
|
66
|
+
protected
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
# Assigns a slug to a page if its not set
|
69
|
+
def assign_slug
|
70
|
+
if page.present?
|
71
|
+
self.page.slug = ShopProduct.to_sku(page.slug.present? ? page.slug : page.title)
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
# Assigns a breadcrumb to the page if its not set
|
76
|
+
def assign_breadcrumb
|
77
|
+
if page.present?
|
78
|
+
self.page.breadcrumb = ShopProduct.to_sku(page.breadcrumb.present? ? page.breadcrumb : page.slug)
|
76
79
|
end
|
77
|
-
self.handle.downcase
|
78
|
-
end
|
79
|
-
|
80
|
-
def set_layouts
|
81
|
-
self.layout = Layout.find_by_name(Radiant::Config['shop.category_layout']) if self.layout.nil?
|
82
|
-
self.product_layout = Layout.find_by_name(Radiant::Config['shop.product_layout']) if self.product_layout.nil?
|
83
80
|
end
|
84
81
|
|
85
82
|
end
|
data/app/models/shop_customer.rb
CHANGED
@@ -1,18 +1,38 @@
|
|
1
1
|
class ShopCustomer < User
|
2
|
+
|
2
3
|
include Scoped::Models::User::Scoped
|
3
4
|
|
4
|
-
has_many :orders,
|
5
|
-
has_many :billings,
|
6
|
-
has_many :shippings,
|
5
|
+
has_many :orders, :class_name => 'ShopOrder', :foreign_key => :customer_id
|
6
|
+
has_many :billings, :through => :orders
|
7
|
+
has_many :shippings, :through => :orders
|
8
|
+
|
9
|
+
belongs_to :created_by, :class_name => 'User'
|
10
|
+
belongs_to :updated_by, :class_name => 'User'
|
7
11
|
|
8
12
|
accepts_nested_attributes_for :orders, :allow_destroy => true
|
9
13
|
|
10
14
|
def first_name
|
11
|
-
|
15
|
+
name = ''
|
16
|
+
|
17
|
+
names = self.name.split(' ')
|
18
|
+
if names.length > 1
|
19
|
+
name = names[0, names.length-1].join(' ')
|
20
|
+
else
|
21
|
+
name = names.join(' ')
|
22
|
+
end
|
23
|
+
|
24
|
+
name
|
12
25
|
end
|
13
26
|
|
14
27
|
def last_name
|
15
|
-
|
28
|
+
name = ''
|
29
|
+
|
30
|
+
names = self.name.split(' ')
|
31
|
+
if names.length > 1
|
32
|
+
name = names[-1]
|
33
|
+
end
|
34
|
+
|
35
|
+
name
|
16
36
|
end
|
17
37
|
|
18
38
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ShopGroup < ActiveRecord::Base
|
2
|
+
|
3
|
+
belongs_to :created_by, :class_name => 'User'
|
4
|
+
belongs_to :updated_by, :class_name => 'User'
|
5
|
+
|
6
|
+
has_many :groupings, :class_name => 'ShopGrouping', :foreign_key => :group_id
|
7
|
+
has_many :products, :class_name => 'ShopProduct', :through => :groupings
|
8
|
+
|
9
|
+
validates_presence_of :name
|
10
|
+
|
11
|
+
def available_products
|
12
|
+
ShopProduct.all - self.products
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -1,18 +1,19 @@
|
|
1
1
|
class ShopLineItem < ActiveRecord::Base
|
2
2
|
|
3
|
-
belongs_to
|
4
|
-
|
5
|
-
|
6
|
-
validates_uniqueness_of :item_id, :scope => [ :shop_order_id, :item_type ]
|
3
|
+
belongs_to :order, :class_name => 'ShopOrder'
|
4
|
+
has_one :customer, :class_name => 'ShopCustomer', :through => :order, :source => :customer
|
5
|
+
belongs_to :item, :polymorphic => true
|
7
6
|
|
8
7
|
before_validation :adjust_quantity
|
8
|
+
validates_uniqueness_of :item_id, :scope => [ :order_id, :item_type ]
|
9
|
+
validates_presence_of :item
|
9
10
|
|
10
11
|
def price
|
11
|
-
item.price.to_f * self.quantity.to_f
|
12
|
+
(item.price.to_f * self.quantity.to_f).to_f
|
12
13
|
end
|
13
14
|
|
14
15
|
def weight
|
15
|
-
item.weight.to_f * self.quantity.to_f
|
16
|
+
(item.weight.to_f * self.quantity.to_f).to_f
|
16
17
|
end
|
17
18
|
|
18
19
|
class << self
|
data/app/models/shop_order.rb
CHANGED
@@ -1,46 +1,67 @@
|
|
1
1
|
class ShopOrder < ActiveRecord::Base
|
2
2
|
|
3
|
-
default_scope :order => 'shop_orders.updated_at
|
3
|
+
default_scope :order => 'shop_orders.updated_at DESC'
|
4
4
|
|
5
|
-
has_one :payment, :class_name => 'ShopPayment', :dependent => :destroy
|
6
|
-
has_many :line_items, :class_name => 'ShopLineItem', :dependent => :destroy
|
5
|
+
has_one :payment, :class_name => 'ShopPayment', :foreign_key => :order_id, :dependent => :destroy
|
6
|
+
has_many :line_items, :class_name => 'ShopLineItem', :foreign_key => :order_id, :dependent => :destroy
|
7
7
|
|
8
8
|
belongs_to :billing, :class_name => 'ShopAddress'
|
9
9
|
belongs_to :shipping, :class_name => 'ShopAddress'
|
10
10
|
belongs_to :created_by, :class_name => 'User'
|
11
11
|
belongs_to :updated_by, :class_name => 'User'
|
12
|
-
belongs_to :customer, :class_name => 'ShopCustomer'
|
12
|
+
belongs_to :customer, :class_name => 'ShopCustomer'
|
13
13
|
|
14
14
|
accepts_nested_attributes_for :line_items, :reject_if => :all_blank
|
15
15
|
accepts_nested_attributes_for :billing, :reject_if => :all_blank
|
16
16
|
accepts_nested_attributes_for :shipping, :reject_if => :all_blank
|
17
17
|
|
18
18
|
def add!(id, quantity = nil, type = nil)
|
19
|
-
|
20
|
-
type ||= 'ShopProduct'
|
19
|
+
result = true
|
21
20
|
|
22
|
-
|
23
|
-
line_item =
|
24
|
-
quantity
|
21
|
+
begin
|
22
|
+
line_item = line_items.find(id)
|
23
|
+
quantity = line_item.quantity + quantity.to_i
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
modify!(id,quantity)
|
26
|
+
rescue
|
27
|
+
quantity ||= 1
|
28
|
+
type ||= 'ShopProduct'
|
29
|
+
|
30
|
+
if line_items.exists?({:item_id => id, :item_type => type})
|
31
|
+
line_item = line_items.first(:conditions => {:item_id => id, :item_type => type})
|
32
|
+
quantity = line_item.quantity + quantity.to_i
|
33
|
+
|
34
|
+
modify!(line_item.id, quantity)
|
35
|
+
else
|
36
|
+
line_items.create!({:item_id => id, :item_type => type, :quantity => quantity})
|
37
|
+
end
|
29
38
|
end
|
30
39
|
|
40
|
+
result
|
41
|
+
end
|
42
|
+
|
43
|
+
def add(*attrs)
|
44
|
+
add!(*attrs)
|
31
45
|
true
|
46
|
+
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
47
|
+
false
|
32
48
|
end
|
33
49
|
|
34
|
-
def
|
50
|
+
def modify!(id, quantity = 1)
|
35
51
|
quantity = quantity.to_i
|
36
52
|
if quantity <= 0
|
37
53
|
remove!(id)
|
38
54
|
else
|
39
|
-
line_item =
|
40
|
-
line_item.
|
55
|
+
line_item = line_items.find(id)
|
56
|
+
line_item.update_attributes! :quantity => quantity
|
41
57
|
end
|
42
|
-
|
58
|
+
end
|
59
|
+
|
60
|
+
def modify(*attrs)
|
61
|
+
modify!(*attrs)
|
43
62
|
true
|
63
|
+
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
|
64
|
+
false
|
44
65
|
end
|
45
66
|
|
46
67
|
def remove!(id)
|
@@ -50,6 +71,13 @@ class ShopOrder < ActiveRecord::Base
|
|
50
71
|
true
|
51
72
|
end
|
52
73
|
|
74
|
+
def remove(*attrs)
|
75
|
+
remove!(*attrs)
|
76
|
+
true
|
77
|
+
rescue ActiveRecord::RecordNotFound
|
78
|
+
false
|
79
|
+
end
|
80
|
+
|
53
81
|
def clear!
|
54
82
|
line_items.destroy_all
|
55
83
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class ShopPackage < ActiveRecord::Base
|
2
|
+
|
3
|
+
belongs_to :created_by, :class_name => 'User'
|
4
|
+
belongs_to :updated_by, :class_name => 'User'
|
5
|
+
|
6
|
+
has_many :packings, :class_name => 'ShopPacking', :foreign_key => :package_id, :dependent => :destroy
|
7
|
+
has_many :products, :class_name => 'ShopProduct', :foreign_key => :product_id, :through => :packings
|
8
|
+
|
9
|
+
has_many :line_items, :class_name => 'ShopLineItem', :as => :item
|
10
|
+
has_many :orders, :class_name => 'ShopOrder', :through => :line_items
|
11
|
+
|
12
|
+
before_validation :assign_sku
|
13
|
+
|
14
|
+
validates_presence_of :name, :sku
|
15
|
+
|
16
|
+
validates_uniqueness_of :name, :sku
|
17
|
+
|
18
|
+
validates_numericality_of :price, :greater_than => 0.00, :allow_nil => true, :precisions => 2
|
19
|
+
|
20
|
+
# Returns the products not attached to the category
|
21
|
+
def available_products; ShopProduct.all - self.products; end
|
22
|
+
|
23
|
+
# Returns the slug of the first product
|
24
|
+
def slug; products.first.slug; end
|
25
|
+
|
26
|
+
# Overloads the base to_json to return what we want
|
27
|
+
def to_json(*attrs); super self.class.params; end
|
28
|
+
|
29
|
+
# Returns the aggregate value of the products in the package
|
30
|
+
def value
|
31
|
+
value = 0
|
32
|
+
self.packings.map { |pkg| value += (pkg.product.price.to_f * pkg.quantity) }
|
33
|
+
value
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the aggregate weight of the products in the package
|
37
|
+
def weight
|
38
|
+
weight = 0
|
39
|
+
self.packings.map { |pkg| weight += (pkg.product.weight.to_f * pkg.quantity) }
|
40
|
+
weight
|
41
|
+
end
|
42
|
+
|
43
|
+
class << self
|
44
|
+
|
45
|
+
# Returns attributes attached to the product
|
46
|
+
def attrs
|
47
|
+
[ :id, :name, :price, :sku, :description, :created_at, :updated_at ]
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns methods with usefuly information
|
51
|
+
def methds
|
52
|
+
[]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the objects to include
|
56
|
+
def inclde
|
57
|
+
[ :category, :products ]
|
58
|
+
end
|
59
|
+
|
60
|
+
# Returns a custom hash of attributes on the product
|
61
|
+
def params
|
62
|
+
{ :only => self.attrs, :methods => self.methds, :include => self.inclde }
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
# Assigns an sku based off the name
|
70
|
+
def assign_sku
|
71
|
+
self.sku = ShopProduct.to_sku(sku.present? ? sku : name)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|