Created
September 9, 2011 17:44
-
-
Save adamcooper/1206846 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
ProductType.all.each do |product_type| | |
# Check if product type has banyan category group | |
product_type_group = product_type.category_group | |
# Create banyan category group for product type if not exist | |
if product_type_group.nil? | |
product_type_group = Banyan::CategoryGroup.new(:name => product_type.name + " Category Group") | |
product_type_group.group_categorizable = product_type | |
product_type_group.save! | |
end | |
# Assign categories | |
product_type.product_type_categories.each do |product_type_category| | |
# Find or create - two steps because 3.0.4 has some problems with find_or_create_by_name | |
category = Banyan::Category.find_by_name(product_type_category.name) | |
category ||= Banyan::Category.create(:name => product_type_category.name) | |
product_type_group.categories << category unless product_type_group.category_ids.include?(category.id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment