Guest User

Untitled

a guest
Jan 22nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. ProductType.all.each do |product_type|
  2. # Check if product type has banyan category group
  3. product_type_group = product_type.category_group
  4.  
  5. # Create banyan category group for product type if not exist
  6. if product_type_group.nil?
  7. product_type_group = Banyan::CategoryGroup.new(:name => product_type.name + " Category Group")
  8. product_type_group.group_categorizable = product_type
  9. product_type_group.save!
  10. end
  11.  
  12. # Assign categories
  13. product_type.product_type_categories.each do |product_type_category|
  14. # Find or create - two steps because 3.0.4 has some problems with find_or_create_by_name
  15. category = Banyan::Category.find_by_name(product_type_category.name)
  16. category ||= Banyan::Category.create(:name => product_type_category.name)
  17.  
  18. product_type_group.categories << category unless product_type_group.category_ids.include?(category.id)
  19. end
  20. end
Add Comment
Please, Sign In to add comment