<commit_before>module SpreeImporter
  module Importers
    class Variant
      include SpreeImporter::Importers::Base

      attr_accessor :batch_id

      row_based

      import_attributes :sku
      unique_keys :sku

      target ::Spree::Variant

      def import(headers, csv)
        return unless field headers, "master-sku"
        
        each_instance headers, csv do |instance, row|
          if instance.new_record?
            product          = master_variant(headers, row).product
            instance.product = product
            instance.option_types.each do |type|
              if f = val(headers, row, type.name)
                ov = type.option_values.select{|v| v.name == Field.new(f).key }.first
              
                # there's issue where where ov doesnt exist 
                instance.option_values << ov if ov
              end
            end
          end

          instance.batch_id = batch_id

          instance.save! # create stock item
          stock_headers(headers, row) do |location, value|
            if value.nil?
              instance.destroy
            else
              stock_item = location.stock_items.where(variant_id: instance.id).first
              stock_item.update_column :count_on_hand, value
            end
          end
        end
      end

      def master_variant(headers, row)
        target.find_by_sku val(headers, row, "master-sku")
      end<commit_msg>missed that last one<commit_after>module SpreeImporter
  module Importers
    class Variant
      include SpreeImporter::Importers::Base

      attr_accessor :batch_id

      row_based

      import_attributes :sku
      unique_keys :sku

      target ::Spree::Variant

      def import(headers, csv)
        return unless field headers, "master-sku"
        
        each_instance headers, csv do |instance, row|
          if instance.new_record?
            product          = master_variant(headers, row).product
            instance.product = product
            instance.option_types.each do |type|
              if f = val(headers, row, type.name)
                ov = type.option_values.select{|v| v.name == Field.new(f).key }.first
              
                # there's issue where where ov doesnt exist 
                instance.option_values << ov if ov
              end
            end
          end

          instance.batch_id = batch_id

          instance.save! # create stock item
          stock_headers(headers, row) do |location, value|
            if value.nil?
              instance.destroy
            else
              stock_item = location.stock_items.where(variant_id: instance.id).first
              stock_item.update_column :count_on_hand, value
            end
          end
        end
      end

      def master_variant(headers, row)
        target.find_by_sku val(headers, row, :master_sku)
      end
{'fraction_non_alphanumeric': 0.06894150417827298, 'fraction_numerical': 0.0, 'mean_word_length': 1.6825396825396826, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1773638', 'n_tokens_mistral': 781, 'n_tokens_neox': 746, 'n_words': 198}