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,34 @@
|
|
1
|
+
module Shop
|
2
|
+
module Interface
|
3
|
+
module Variants
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.send :include, InstanceMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
attr_accessor :variants
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def load_default_shop_variants_regions
|
15
|
+
returning OpenStruct.new do |variants|
|
16
|
+
variants.edit = Radiant::AdminUI::RegionSet.new do |edit|
|
17
|
+
edit.main.concat %w{head form popups}
|
18
|
+
edit.form.concat %w{inputs meta parts foot}
|
19
|
+
edit.foot.concat %w{buttons timestamp}
|
20
|
+
end
|
21
|
+
variants.new = variants.edit
|
22
|
+
variants.index = Radiant::AdminUI::RegionSet.new do |index|
|
23
|
+
index.head.concat %w{buttons}
|
24
|
+
index.body.concat %w{name modify}
|
25
|
+
index.foot.concat %w{add}
|
26
|
+
end
|
27
|
+
variants.remove = variants.index
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Shop
|
2
|
+
module Models
|
3
|
+
module FormExtension
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
# Uses the page session data to find the current order
|
8
|
+
def find_current_order
|
9
|
+
@order = ShopOrder.find(@page.request.session[:shop_order])
|
10
|
+
@order.update_attribute(:customer_id, (current_customer.id rescue nil)) # either assign it to a user, or don't
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the current logged in ShopCustomer (if it exists)
|
14
|
+
def current_customer
|
15
|
+
return @shop_customer if @shop_customer.present?
|
16
|
+
return current_user if current_user.present?
|
17
|
+
@shop_customer = ShopCustomer.find(current_user.id)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/shop/models/page.rb
CHANGED
@@ -4,8 +4,9 @@ module Shop
|
|
4
4
|
|
5
5
|
def self.included(base)
|
6
6
|
base.class_eval do
|
7
|
-
|
8
|
-
|
7
|
+
has_one :shop_category, :dependent => :delete
|
8
|
+
has_one :shop_product, :dependent => :delete
|
9
|
+
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
data/lib/shop/tags/address.rb
CHANGED
@@ -6,7 +6,7 @@ module Shop
|
|
6
6
|
# Expand if the address has been assigned to the order
|
7
7
|
desc %{
|
8
8
|
Expand if an address has been assigned to the order
|
9
|
-
|
9
|
+
|
10
10
|
@type@ = (billing)|(shipping)
|
11
11
|
}
|
12
12
|
tag 'shop:cart:address' do |tag|
|
@@ -21,13 +21,13 @@ module Shop
|
|
21
21
|
# Expand if an address has been assigned to the order
|
22
22
|
desc %{ Expand if an address has been assigned to the order }
|
23
23
|
tag 'shop:cart:address:if_address' do |tag|
|
24
|
-
tag.expand if tag.locals.address.present?
|
24
|
+
tag.expand if tag.locals.address.name.present? rescue nil
|
25
25
|
end
|
26
26
|
|
27
27
|
# Expand if an address has not been assigned to the order
|
28
28
|
desc %{ Expand if an address has not been assigned to the order }
|
29
29
|
tag 'shop:cart:address:unless_address' do |tag|
|
30
|
-
tag.expand unless tag.locals.address.present?
|
30
|
+
tag.expand unless tag.locals.address.name.present? rescue nil
|
31
31
|
end
|
32
32
|
|
33
33
|
[:id, :name, :email, :unit, :street, :city, :state, :country, :postcode].each do |method|
|
data/lib/shop/tags/cart.rb
CHANGED
@@ -4,23 +4,23 @@ module Shop
|
|
4
4
|
include Radiant::Taggable
|
5
5
|
include ActionView::Helpers::NumberHelper
|
6
6
|
|
7
|
+
# Expand the shopping cart instance
|
8
|
+
# @param [Integer] id Id of the shopping cart (ShopOrder)
|
9
|
+
tag 'shop:cart' do |tag|
|
10
|
+
tag.locals.shop_order = Helpers.current_order(tag)
|
11
|
+
tag.expand
|
12
|
+
end
|
13
|
+
|
7
14
|
# Expand if a user has started a cart
|
8
15
|
desc %{ Expand if a user has started a cart }
|
9
|
-
tag 'shop:if_cart' do |tag|
|
10
|
-
tag.expand if
|
16
|
+
tag 'shop:cart:if_cart' do |tag|
|
17
|
+
tag.expand if tag.locals.shop_order.present?
|
11
18
|
end
|
12
19
|
|
13
20
|
# Expand unless a user has started a cart
|
14
21
|
desc %{ Expand unless a user has started a cart }
|
15
|
-
tag 'shop:unless_cart' do |tag|
|
16
|
-
tag.expand unless
|
17
|
-
end
|
18
|
-
|
19
|
-
# Expand the shopping cart instance
|
20
|
-
# @param [Integer] id Id of the shopping cart (ShopOrder)
|
21
|
-
tag 'shop:cart' do |tag|
|
22
|
-
tag.locals.shop_order = Helpers.current_order(tag)
|
23
|
-
tag.expand unless tag.locals.shop_order.nil?
|
22
|
+
tag 'shop:cart:unless_cart' do |tag|
|
23
|
+
tag.expand unless tag.locals.shop_order.present?
|
24
24
|
end
|
25
25
|
|
26
26
|
# Display the cart id / status
|
@@ -37,11 +37,7 @@ module Shop
|
|
37
37
|
attr = tag.attr.symbolize_keys
|
38
38
|
order = tag.locals.shop_order
|
39
39
|
|
40
|
-
|
41
|
-
:precision =>(attr[:precision] || Radiant::Config['shop.price_precision']).to_i,
|
42
|
-
:unit => attr[:unit] || Radiant::Config['shop.price_unit'],
|
43
|
-
:separator => attr[:separator] || Radiant::Config['shop.price_seperator'],
|
44
|
-
:delimiter => attr[:delimiter] || Radiant::Config['shop.price_delimiter'])
|
40
|
+
Helpers.currency(order.price,attr)
|
45
41
|
end
|
46
42
|
|
47
43
|
end
|
data/lib/shop/tags/category.rb
CHANGED
@@ -38,15 +38,13 @@ module Shop
|
|
38
38
|
|
39
39
|
tag 'shop:category:if_current' do |tag|
|
40
40
|
|
41
|
-
if tag.locals.shop_category
|
41
|
+
if tag.locals.page.shop_category == tag.locals.shop_category
|
42
42
|
# Looking at the shop_category generated page
|
43
43
|
tag.expand
|
44
|
-
|
45
|
-
|
46
|
-
tag.expand
|
47
|
-
elsif tag.locals.shop_product
|
44
|
+
|
45
|
+
elsif tag.locals.page.shop_product.present?
|
48
46
|
# A product page
|
49
|
-
if tag.locals.shop_product.category == tag.locals.shop_category
|
47
|
+
if tag.locals.page.shop_product.category == tag.locals.shop_category
|
50
48
|
# Where the products category is this category
|
51
49
|
tag.expand
|
52
50
|
end
|
data/lib/shop/tags/helpers.rb
CHANGED
@@ -2,20 +2,27 @@ module Shop
|
|
2
2
|
module Tags
|
3
3
|
class Helpers
|
4
4
|
class << self
|
5
|
+
include ActionView::Helpers::NumberHelper
|
5
6
|
|
6
7
|
def current_categories(tag)
|
7
8
|
result = []
|
8
9
|
|
10
|
+
# Returns the current categories if they exist
|
9
11
|
if tag.locals.shop_categories.present?
|
10
12
|
result = tag.locals.shop_categories
|
11
|
-
|
12
|
-
# Page params are protected, send is used to overcome this
|
13
|
-
elsif tag.locals.page.send(:params).has_key? 'query'
|
14
|
-
result = ShopCategory.search(tag.locals.page.send(:params)['query'])
|
15
|
-
|
16
|
-
elsif tag.attr['key'] and tag.attr['value']
|
17
|
-
result = ShopCategory.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
18
13
|
|
14
|
+
# Returns categories based on the slug of their categories parent page
|
15
|
+
elsif tag.attr['parent']
|
16
|
+
result = ShopCategory.all(
|
17
|
+
:joins => 'JOIN pages AS page ON page.id = shop_categories.page_id JOIN pages AS parent ON page.parent_id = parent.id',
|
18
|
+
:conditions => [ 'parent.slug = ?', tag.attr['parent'] ]
|
19
|
+
)
|
20
|
+
|
21
|
+
# Page params are protected, send is used to overcome this
|
22
|
+
# elsif tag.locals.page.send(:params).has_key? 'query'
|
23
|
+
# result = ShopCategory.search(tag.locals.page.send(:params)['query'])
|
24
|
+
|
25
|
+
# Returns all Categories
|
19
26
|
else
|
20
27
|
result = ShopCategory.all
|
21
28
|
|
@@ -27,24 +34,34 @@ module Shop
|
|
27
34
|
def current_category(tag)
|
28
35
|
result = nil
|
29
36
|
|
37
|
+
# Returns the current shop_category
|
30
38
|
if tag.locals.shop_category.present?
|
31
39
|
result = tag.locals.shop_category
|
40
|
+
|
41
|
+
# Returns a category based on its name (page title)
|
42
|
+
elsif tag.attr['name']
|
43
|
+
result = ShopCategory.first(
|
44
|
+
:joins => :page,
|
45
|
+
:conditions => [ "pages.title = ?", tag.attr['name'] ]
|
46
|
+
)
|
32
47
|
|
48
|
+
# Returns a category based on its handle (page slug)
|
49
|
+
elsif tag.attr['handle']
|
50
|
+
result = ShopCategory.first(
|
51
|
+
:joins => :page,
|
52
|
+
:conditions => [ "pages.slug = ?", tag.attr['handle'] ]
|
53
|
+
)
|
54
|
+
|
55
|
+
# Returns the category of the current shop_product
|
33
56
|
elsif tag.locals.shop_product.present?
|
34
|
-
|
35
|
-
|
36
|
-
elsif tag.attr['key'] and tag.attr['value']
|
37
|
-
result = ShopCategory.first(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
38
|
-
|
57
|
+
result = tag.locals.shop_product.category
|
58
|
+
|
39
59
|
elsif tag.locals.page.shop_category.present?
|
40
60
|
result = tag.locals.page.shop_category
|
41
61
|
|
42
62
|
elsif tag.locals.page.shop_product.present?
|
43
63
|
result = tag.locals.page.shop_product.category
|
44
64
|
|
45
|
-
else
|
46
|
-
result = ShopCategory.find_by_handle(tag.locals.page.slug)
|
47
|
-
|
48
65
|
end
|
49
66
|
|
50
67
|
result
|
@@ -52,19 +69,19 @@ module Shop
|
|
52
69
|
|
53
70
|
def current_products(tag)
|
54
71
|
result = nil
|
55
|
-
|
72
|
+
|
56
73
|
if tag.locals.shop_products.present?
|
57
74
|
result = tag.locals.shop_products
|
75
|
+
|
76
|
+
elsif tag.attr['category']
|
77
|
+
result = ShopCategory.first(
|
78
|
+
:joins => :page,
|
79
|
+
:conditions => [ 'page.slug = ?', tag.attr['category'] ]
|
80
|
+
).products
|
58
81
|
|
59
82
|
elsif tag.locals.shop_category.present?
|
60
83
|
result = tag.locals.shop_category.products
|
61
|
-
|
62
|
-
elsif tag.locals.page.send(:params).has_key? 'query'
|
63
|
-
result = ShopProduct.search(tag.locals.page.params['query'])
|
64
|
-
|
65
|
-
elsif tag.attr['key'] and tag.attr['value']
|
66
|
-
result = ShopProduct.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
67
|
-
|
84
|
+
|
68
85
|
elsif tag.locals.page.shop_category.present?
|
69
86
|
result = tag.locals.page.shop_category.products
|
70
87
|
|
@@ -81,16 +98,27 @@ module Shop
|
|
81
98
|
|
82
99
|
if tag.locals.shop_product.present?
|
83
100
|
result = tag.locals.shop_product
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
101
|
+
|
102
|
+
# Returns a product based on its name (page title)
|
103
|
+
elsif tag.attr['name']
|
104
|
+
result = ShopProduct.first(
|
105
|
+
:joins => :page,
|
106
|
+
:conditions => [ "pages.title = ?", tag.attr['name'] ]
|
107
|
+
)
|
108
|
+
|
109
|
+
# Returns a product based on its sku (page slug)
|
110
|
+
elsif tag.attr['sku']
|
111
|
+
result = ShopProduct.first(
|
112
|
+
:joins => :page,
|
113
|
+
:conditions => [ "pages.slug = ?", tag.attr['sku'] ]
|
114
|
+
)
|
115
|
+
|
116
|
+
elsif tag.locals.shop_line_item.present? and tag.locals.shop_line_item.item_type === 'ShopProduct'
|
117
|
+
result = tag.locals.shop_line_item.item
|
118
|
+
|
88
119
|
elsif tag.locals.page.shop_product.present?
|
89
120
|
result = tag.locals.page.shop_product
|
90
121
|
|
91
|
-
else
|
92
|
-
result = ShopProduct.find_by_sku(tag.locals.page.slug)
|
93
|
-
|
94
122
|
end
|
95
123
|
|
96
124
|
result
|
@@ -113,6 +141,20 @@ module Shop
|
|
113
141
|
|
114
142
|
result
|
115
143
|
end
|
144
|
+
|
145
|
+
def current_line_items(tag)
|
146
|
+
result = nil
|
147
|
+
|
148
|
+
if tag.locals.shop_line_items.present?
|
149
|
+
result = tag.locals.shop_line_items
|
150
|
+
elsif tag.attr['key'] and tag.attr['value']
|
151
|
+
result = tag.locals.shop_order.line_items.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
152
|
+
else
|
153
|
+
result = tag.locals.shop_order.line_items
|
154
|
+
end
|
155
|
+
|
156
|
+
result
|
157
|
+
end
|
116
158
|
|
117
159
|
def current_line_item(tag)
|
118
160
|
result = nil
|
@@ -151,6 +193,65 @@ module Shop
|
|
151
193
|
result
|
152
194
|
end
|
153
195
|
|
196
|
+
def current_packages(tag)
|
197
|
+
result = nil
|
198
|
+
|
199
|
+
if tag.locals.shop_product.present?
|
200
|
+
result = tag.locals.shop_product.packages
|
201
|
+
|
202
|
+
elsif tag.attr['key'] and tag.attr['value']
|
203
|
+
result = ShopPackage.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value']})
|
204
|
+
|
205
|
+
else
|
206
|
+
result = ShopPackage.all
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
result
|
211
|
+
end
|
212
|
+
|
213
|
+
def current_package(tag)
|
214
|
+
result = nil
|
215
|
+
|
216
|
+
if tag.locals.shop_package.present?
|
217
|
+
result = tag.locals.shop_package
|
218
|
+
|
219
|
+
elsif tag.attr['key'] and tag.attr['value']
|
220
|
+
result = ShopPackage.first(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value']})
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
result
|
225
|
+
end
|
226
|
+
|
227
|
+
def current_product_variants(tag)
|
228
|
+
result = nil
|
229
|
+
|
230
|
+
if tag.locals.shop_product.present?
|
231
|
+
result = tag.locals.shop_product.variants
|
232
|
+
end
|
233
|
+
|
234
|
+
result
|
235
|
+
end
|
236
|
+
|
237
|
+
def current_product_variant(tag)
|
238
|
+
result = nil
|
239
|
+
|
240
|
+
if tag.locals.shop_product_variant.present?
|
241
|
+
result = tag.locals.shop_product_variant
|
242
|
+
end
|
243
|
+
|
244
|
+
result
|
245
|
+
end
|
246
|
+
|
247
|
+
def currency(number,attr)
|
248
|
+
number_to_currency(number.to_f,
|
249
|
+
:precision =>(attr[:precision] || Radiant::Config['shop.price_precision']).to_i,
|
250
|
+
:unit => attr[:unit] || Radiant::Config['shop.price_unit'],
|
251
|
+
:separator => attr[:separator] || Radiant::Config['shop.price_separator'],
|
252
|
+
:delimiter => attr[:delimiter] || Radiant::Config['shop.price_delimiter'])
|
253
|
+
end
|
254
|
+
|
154
255
|
end
|
155
256
|
end
|
156
257
|
end
|
data/lib/shop/tags/item.rb
CHANGED
@@ -4,33 +4,34 @@ module Shop
|
|
4
4
|
include Radiant::Taggable
|
5
5
|
include ActionView::Helpers::NumberHelper
|
6
6
|
|
7
|
+
# Expand to line items
|
8
|
+
tag 'shop:cart:items' do |tag|
|
9
|
+
if tag.locals.shop_order.present?
|
10
|
+
tag.locals.shop_line_items = Helpers.current_line_items(tag)
|
11
|
+
tag.expand
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
7
15
|
# Expand if items are in cart
|
8
16
|
desc %{ Expand if the user has added items to their cart }
|
9
|
-
tag 'shop:cart:if_items' do |tag|
|
10
|
-
tag.expand unless tag.locals.
|
17
|
+
tag 'shop:cart:items:if_items' do |tag|
|
18
|
+
tag.expand unless tag.locals.shop_line_items.empty?
|
11
19
|
end
|
12
20
|
|
13
21
|
# Expand in no items are in cart
|
14
22
|
desc %{ Expand unless a user has added items to their cart }
|
15
|
-
tag 'shop:cart:unless_items' do |tag|
|
16
|
-
tag.expand if tag.locals.
|
17
|
-
end
|
18
|
-
|
19
|
-
# Expand to line items
|
20
|
-
tag 'shop:cart:items' do |tag|
|
21
|
-
tag.expand
|
23
|
+
tag 'shop:cart:items:unless_items' do |tag|
|
24
|
+
tag.expand if tag.locals.shop_line_items.empty?
|
22
25
|
end
|
23
26
|
|
24
27
|
# Iterate through each item in the cart
|
25
28
|
desc %{ Iterate through each item in the cart }
|
26
29
|
tag 'shop:cart:items:each' do |tag|
|
27
30
|
content = ''
|
28
|
-
items = tag.locals.
|
31
|
+
items = tag.locals.shop_line_items
|
29
32
|
|
30
33
|
items.each do |line_item|
|
31
34
|
tag.locals.shop_line_item = line_item
|
32
|
-
tag.locals.shop_product = line_item.item
|
33
|
-
|
34
35
|
content << tag.expand
|
35
36
|
end
|
36
37
|
|
@@ -42,9 +43,8 @@ module Shop
|
|
42
43
|
tag 'shop:cart:item' do |tag|
|
43
44
|
tag.locals.shop_line_item = Helpers.current_line_item(tag)
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
tag.locals.shop_product = line_item.item
|
46
|
+
if tag.locals.shop_line_item.present?
|
47
|
+
tag.locals.shop_product = tag.locals.shop_line_item.item
|
48
48
|
|
49
49
|
tag.expand
|
50
50
|
end
|
@@ -84,24 +84,7 @@ module Shop
|
|
84
84
|
attr = tag.attr.symbolize_keys
|
85
85
|
item = tag.locals.shop_line_item
|
86
86
|
|
87
|
-
|
88
|
-
:precision =>(attr[:precision] || Radiant::Config['shop.price_precision']).to_i,
|
89
|
-
:unit => attr[:unit] || Radiant::Config['shop.price_unit'],
|
90
|
-
:separator => attr[:separator] || Radiant::Config['shop.price_seperator'],
|
91
|
-
:delimiter => attr[:delimiter] || Radiant::Config['shop.price_delimiter'])
|
92
|
-
end
|
93
|
-
|
94
|
-
# Output a link to remove the item from the cart
|
95
|
-
desc %{ outputs a link to remove the item from the cart }
|
96
|
-
tag 'shop:cart:item:remove' do |tag|
|
97
|
-
item = tag.locals.shop_line_item
|
98
|
-
options = tag.attr.dup
|
99
|
-
attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip
|
100
|
-
attributes = " #{attributes}" unless attributes.empty?
|
101
|
-
|
102
|
-
text = tag.double? ? tag.expand : 'remove'
|
103
|
-
|
104
|
-
%{<a href="/#{Radiant::Config['shop.url_prefix']}/cart/items/#{item.id}/destroy"#{attributes}>#{text}</a>}
|
87
|
+
Helpers.currency(item.price,attr)
|
105
88
|
end
|
106
89
|
|
107
90
|
end
|