app/workers/spree/import_product_worker.rb
def make_taxons(row_hash, mappers)
      taxons = []
      get_value(row_hash, mappers, 'Category').split('|').each do |taxon_group|
        if taxon_group.include?('->')
          parent, child = taxon_group.strip.split('->').map(&:strip)
          taxonomy = Spree::Taxonomy.find_or_create_by!(name: parent)
          taxon = Spree::Taxon.find_by(name: child)
          if taxon
            taxons << taxon
          else
            taxon = taxonomy.root.children.create!(name: child, taxonomy_id: taxonomy.id)
          end
          taxons << taxon
        else
          raise "Invalid category format."
        end
      end
      taxons
    end
# return taxons list which product belongs to
return taxons list which product belongs to
return taxons list which product belongs to
def make_taxons(row_hash, mappers)
      taxons = []
      get_value(row_hash, mappers, 'Category').split('|').each do |taxon_group|
        if taxon_group.include?('->')
          parent, child = taxon_group.strip.split('->').map(&:strip)
          taxonomy = Spree::Taxonomy.find_or_create_by!(name: parent)
          taxon = Spree::Taxon.find_by(name: child)
          if taxon
            taxons << taxon
          else
            taxon = taxonomy.root.children.create!(name: child, taxonomy_id: taxonomy.id)
          end
          taxons << taxon
        else
          raise "Invalid category format."
        end
      end
      taxons
    end
def make_taxons ( row_hash , mappers ) taxons = [ ] get_value ( row_hash , mappers , 'Category' ) . split ( '|' ) . each do | taxon_group | if taxon_group . include? ( '->' ) parent , child = taxon_group . strip . split ( '->' ) . map ( & :strip ) taxonomy = Spree :: Taxonomy . find_or_create_by! ( name : parent ) taxon = Spree :: Taxon . find_by ( name : child ) if taxon taxons << taxon else taxon = taxonomy . root . children . create! ( name : child , taxonomy_id : taxonomy . id ) end taxons << taxon else raise "Invalid category format." end end taxons end
return taxons list which product belongs to
return taxons list which product belongs to
row_hash
mappers