Sha256: aeb23fea912c6aca21efb55238500ed31e99eee8a30e9f891b041f7787ae8f7d

Contents?: true

Size: 1.09 KB

Versions: 18

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module FlowcommerceSpree
  module Webhooks
    class LocalItemUpserted
      attr_accessor :errors
      alias full_messages errors

      def self.process(data, opts = {})
        new(data, opts).process
      end

      def initialize(data, opts = {})
        @data = data
        @opts = opts
        @errors = []
      end

      def process
        errors << { message: 'Local item param missing' } && (return self) unless (local_item = @data['local_item'])

        errors << { message: 'SKU param missing' } && (return self) unless (flow_sku = local_item.dig('item', 'number'))

        if (variant = Spree::Variant.find_by(sku: flow_sku))
          variant.add_flow_io_experience_data(
            local_item.dig('experience', 'key'),
            'prices' => [local_item.dig('pricing', 'price')], 'status' => local_item['status']
          )

          variant.update_column(:meta, variant.meta.to_json)
          return variant
        else
          errors << { message: "Variant with sku [#{flow_sku}] not found!" }
        end

        self
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
flowcommerce_spree-0.0.22 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.21 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.20 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.19 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.18 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.17 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.16 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.15 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.14 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.13 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.12 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.11 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.10 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.9 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.8 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.7 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.6 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
flowcommerce_spree-0.0.5 app/services/flowcommerce_spree/webhooks/local_item_upserted.rb