Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment