Class: Magento::Import::Category
- Inherits:
-
Object
- Object
- Magento::Import::Category
- Defined in:
- lib/magento/import/category.rb
Instance Method Summary collapse
- #associate ⇒ Object
-
#initialize(products) ⇒ Category
constructor
A new instance of Category.
Constructor Details
#initialize(products) ⇒ Category
Returns a new instance of Category.
4 5 6 7 8 |
# File 'lib/magento/import/category.rb', line 4 def initialize(products) @products = products @category_root = Magento::Category.all @cats = @category_root.children_data end |
Instance Method Details
#associate ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/magento/import/category.rb', line 10 def associate @products.each do |prod| cat1 = find_or_create(name: prod.cat1, parent: @category_root) if prod.cat1 cat2 = find_or_create(name: prod.cat2, parent: cat1) if prod.cat2 cat3 = find_or_create(name: prod.cat3, parent: cat2) if prod.cat3 prod.cat1, prod.cat2, prod.cat3 = cat1&.id, cat2&.id, cat3&.id @cats.push(*[cat1, cat2, cat3].compact) end end |