Sha256: bce2b8aea5df4211aaa74c8927809fa97e72c9bb8dadb1bcbc652bb9e8cc1b0d

Contents?: true

Size: 999 Bytes

Versions: 3

Compression:

Stored size: 999 Bytes

Contents

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

      attr_reader :product

      def initialize(product)
        @product = product
      end

      # @return Hash
      def to_h
        {
          id: product.id.to_s,
          title: product.name,
          handle: product.slug,
          url:  product_url(id: product.to_param, host: Workarea.config.host),
          description: product.description.to_s,
          image_url: primary_image,
          variants: variants
        }
      end

      private

        def variants
          @variants ||= product.variants.map { |v| Variant.new(v).to_h }
        end

        def primary_image
          Workarea.config.host + ProductPrimaryImageUrl.new(product).path
        end

        def mounted_core
          self
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
workarea-mail_chimp-3.1.0 app/services/workarea/mail_chimp/product.rb
workarea-mail_chimp-3.0.5 app/services/workarea/mail_chimp/product.rb
workarea-mail_chimp-3.0.4 app/services/workarea/mail_chimp/product.rb