Sha256: a5b3ddbf7815f154154e0a9e09099a1216793bd8c7221f5c59743b3018e2e440

Contents?: true

Size: 945 Bytes

Versions: 5

Compression:

Stored size: 945 Bytes

Contents

module Workarea
  module MailChimp
    class Variant
      include ActionView::Helpers::AssetUrlHelper
      include Core::Engine.routes.url_helpers
      include Workarea::ApplicationHelper

      delegate :sku, to: :variant

      attr_reader :variant

      def initialize(variant)
        @variant = variant
      end

      # @return Hash
      def to_h
        {
          id: sku,
          title: variant.name,
          sku: sku,
          price: price.to_s,
          inventory_quantity: inventory_sku.available_to_sell,
          visibility: inventory_sku.displayable?.to_s
        }
      end

      private

      def inventory_sku
        @inventory_sku ||= Inventory::Sku.find(sku) rescue Inventory::Sku.new(id: sku)
      end

      def pricing_sku
        @pricing_sku ||= Pricing::Sku.find(sku) rescue Pricing::Sku.new(id: sku)
      end

      def price
        pricing_sku.sell_price.dollars.to_f
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
workarea-mail_chimp-3.1.0 app/services/workarea/mail_chimp/variant.rb
workarea-mail_chimp-3.0.5 app/services/workarea/mail_chimp/variant.rb
workarea-mail_chimp-3.0.4 app/services/workarea/mail_chimp/variant.rb
workarea-mail_chimp-3.0.3 app/services/workarea/mail_chimp/variant.rb
workarea-mail_chimp-3.0.2 app/services/workarea/mail_chimp/variant.rb