|
|
@@ -276,61 +276,65 @@ class Product < ActiveRecord::Base
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+ # rubocop:disable Metrics/BlockLength
|
|
|
def save_new_attributes(new_sizes, new_colors, new_styles)
|
|
|
- combinations = Array.new
|
|
|
- attributes = Array.new
|
|
|
+ Thread.new do
|
|
|
+ combinations = Array.new
|
|
|
+ attributes = Array.new
|
|
|
|
|
|
- unless new_sizes.nil?
|
|
|
- new_sizes.each do |s|
|
|
|
- size_list.add(s.to_s)
|
|
|
- save(validate: false)
|
|
|
+ unless new_sizes.nil?
|
|
|
+ new_sizes.each do |s|
|
|
|
+ size_list.add(s.to_s)
|
|
|
+ save(validate: false)
|
|
|
+ end
|
|
|
end
|
|
|
- end
|
|
|
- unless new_colors.nil?
|
|
|
- new_colors.each do |s|
|
|
|
- color_list.add(s.to_s)
|
|
|
- save(validate: false)
|
|
|
+ unless new_colors.nil?
|
|
|
+ new_colors.each do |s|
|
|
|
+ color_list.add(s.to_s)
|
|
|
+ save(validate: false)
|
|
|
+ end
|
|
|
end
|
|
|
- end
|
|
|
- unless new_styles.nil?
|
|
|
- new_styles.each do |s|
|
|
|
- style_list.add(s.to_s)
|
|
|
- save(validate: false)
|
|
|
+ unless new_styles.nil?
|
|
|
+ new_styles.each do |s|
|
|
|
+ style_list.add(s.to_s)
|
|
|
+ save(validate: false)
|
|
|
+ end
|
|
|
end
|
|
|
- end
|
|
|
|
|
|
- combinations = get_combinations(combinations, attributes)
|
|
|
- # self.save(:validate: false)
|
|
|
- combinations.each_with_index do |combination, index|
|
|
|
- attributes = {}
|
|
|
- if combination.is_a?(Array)
|
|
|
- combination.each do |c|
|
|
|
- attributes = assign_attributes_to_variant(c, id, attributes)
|
|
|
+ combinations = get_combinations(combinations, attributes)
|
|
|
+ # self.save(:validate: false)
|
|
|
+ combinations.each_with_index do |combination, index|
|
|
|
+ attributes = {}
|
|
|
+ if combination.is_a?(Array)
|
|
|
+ combination.each do |c|
|
|
|
+ attributes = assign_attributes_to_variant(c, id, attributes)
|
|
|
+ end
|
|
|
+ else
|
|
|
+ attributes = assign_attributes_to_variant(combination, id, attributes)
|
|
|
end
|
|
|
- else
|
|
|
- attributes = assign_attributes_to_variant(combination, id, attributes)
|
|
|
- end
|
|
|
|
|
|
- next unless children.where("attributes_json = ?", attributes.to_json).select(:id).first.nil?
|
|
|
- # if children.where("attributes_json = ?", attributes.to_json).select(:id).first.nil?
|
|
|
- @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
|
|
|
- attrs_json = {}
|
|
|
- if combination.is_a?(Array)
|
|
|
- combination.each do |attrib|
|
|
|
- attrs_json = @products_variant.assign_attributes_to_variant(attrib, id, attrs_json)
|
|
|
+ next unless children.where("attributes_json = ?", attributes.to_json).select(:id).first.nil?
|
|
|
+ # if children.where("attributes_json = ?", attributes.to_json).select(:id).first.nil?
|
|
|
+ @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
|
|
|
+ attrs_json = {}
|
|
|
+ if combination.is_a?(Array)
|
|
|
+ combination.each do |attrib|
|
|
|
+ attrs_json = @products_variant.assign_attributes_to_variant(attrib, id, attrs_json)
|
|
|
+ end
|
|
|
+ else
|
|
|
+ attrs_json = @products_variant.assign_attributes_to_variant(combination, id, attrs_json)
|
|
|
end
|
|
|
- else
|
|
|
- attrs_json = @products_variant.assign_attributes_to_variant(combination, id, attrs_json)
|
|
|
+ @products_variant.attributes_json = attributes.to_json
|
|
|
+ @products_variant.save(validate: false)
|
|
|
end
|
|
|
- @products_variant.attributes_json = attributes.to_json
|
|
|
- @products_variant.save(validate: false)
|
|
|
end
|
|
|
end
|
|
|
+ # rubocop:enable Metrics/BlockLength
|
|
|
|
|
|
def children
|
|
|
Product.where("parent_id = ? and status != 0 ", id)
|