Module: Shoppy::ProductsHelper
- Defined in:
- app/helpers/shoppy/products_helper.rb
Class Method Summary collapse
- .add_options_groups_to_product(product, options_groups) ⇒ Object
- .convert_params_groups_to_objects(params) ⇒ Object
- .createVariants_for_product(product, variants_names) ⇒ Object
- .remove_options_groups_from_product(product, options_groups) ⇒ Object
- .update_options_groups_for_product(product, options_groups) ⇒ Object
Class Method Details
.add_options_groups_to_product(product, options_groups) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/shoppy/products_helper.rb', line 3 def self.(product, ) product. += product.save vs = product.variants vs.each do |v| .each do |og| v.put_option(og.name, "") end v.save end return product end |
.convert_params_groups_to_objects(params) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/shoppy/products_helper.rb', line 55 def self.convert_params_groups_to_objects(params) = params = [] .each do |o_id| o = OptionsGroup.find_by(id: o_id.to_i) ( += [o]) if o end return end |
.createVariants_for_product(product, variants_names) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/shoppy/products_helper.rb', line 41 def self.createVariants_for_product(product, variants_names) variants_names.each do |vn| v = Variant.new v.name = vn v.product = product product..each do |h| v.put_option(h.name, "") end v.save end return product end |
.remove_options_groups_from_product(product, options_groups) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/shoppy/products_helper.rb', line 16 def self.(product, ) product. -= product.save vs = product.variants vs.each do |v| .each do |og| v.delete_option(og.name) end v.save end return product end |
.update_options_groups_for_product(product, options_groups) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/shoppy/products_helper.rb', line 29 def self.(product, ) Product.transaction do original_groups = product. new_groups = added_groups = new_groups - original_groups removed_groups = original_groups - new_groups puts (product, removed_groups) puts (product, added_groups) return true end end |