|
|
@@ -164,31 +164,33 @@ class Product < ActiveRecord::Base
|
|
|
end
|
|
|
|
|
|
def save_variants
|
|
|
- combinations = Array.new
|
|
|
- attributes = Array.new
|
|
|
- combinations = get_combinations(combinations, attributes)
|
|
|
-
|
|
|
- ##--- recorrer combinaciones para crear las variantes de productos
|
|
|
- unless combinations.nil?
|
|
|
- combinations.each_with_index do |combination, index|
|
|
|
- @products_variant = Product.new
|
|
|
- @products_variant = dup
|
|
|
- @products_variant.parent_id = id
|
|
|
- @products_variant.is_parent = false
|
|
|
- @products_variant.sku = sku + (index + 1).to_s + "A"
|
|
|
- @products_variant.category_ids = category_ids
|
|
|
- attributes_json = {}
|
|
|
-
|
|
|
- if combination.is_a?(Array)
|
|
|
- combination.each do |attrib|
|
|
|
- attributes_json = @products_variant.assign_attributes_to_variant(attrib, id, attributes_json)
|
|
|
+ Thread.new do
|
|
|
+ combinations = Array.new
|
|
|
+ attributes = Array.new
|
|
|
+ combinations = get_combinations(combinations, attributes)
|
|
|
+
|
|
|
+ ##--- recorrer combinaciones para crear las variantes de productos
|
|
|
+ unless combinations.nil?
|
|
|
+ combinations.each_with_index do |combination, index|
|
|
|
+ @products_variant = Product.new
|
|
|
+ @products_variant = dup
|
|
|
+ @products_variant.parent_id = id
|
|
|
+ @products_variant.is_parent = false
|
|
|
+ @products_variant.sku = sku + (index + 1).to_s + "A"
|
|
|
+ @products_variant.category_ids = category_ids
|
|
|
+ attributes_json = {}
|
|
|
+
|
|
|
+ if combination.is_a?(Array)
|
|
|
+ combination.each do |attrib|
|
|
|
+ attributes_json = @products_variant.assign_attributes_to_variant(attrib, id, attributes_json)
|
|
|
+ end
|
|
|
+ else
|
|
|
+ attributes_json = @products_variant.assign_attributes_to_variant(combination, id, attributes_json)
|
|
|
end
|
|
|
- else
|
|
|
- attributes_json = @products_variant.assign_attributes_to_variant(combination, id, attributes_json)
|
|
|
- end
|
|
|
|
|
|
- @products_variant.attributes_json = attributes_json.to_json
|
|
|
- @products_variant.save
|
|
|
+ @products_variant.attributes_json = attributes_json.to_json
|
|
|
+ @products_variant.save
|
|
|
+ end
|
|
|
end
|
|
|
end
|
|
|
end
|