Created
February 22, 2013 17:35
-
-
Save kalupa/5015184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update_cousin_variants_by_variant_value(variant_value) | |
first_sibling_value = variant_value.category.variant_values.first | |
existing_variants_with_this_value = self.variants.includes(:variant_values).where('variant_value_id = ?', first_sibling_value.id) | |
new_variants = [] | |
existing_variants_with_this_value.each do |variant| | |
new_variant = product.variant.create(price: self.price) | |
variant.variant_values.each do |old_variant_value| | |
if old_variant_value.variant_category != variant_value.variant_category | |
new_variant.variant_values << old_variant_value | |
else | |
new_variant.variant_values << variant_value | |
end | |
end | |
new_variants << new_variant | |
end | |
new_variants | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment