Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcooper/1206846 to your computer and use it in GitHub Desktop.
Save adamcooper/1206846 to your computer and use it in GitHub Desktop.
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