Sha256: 499fc57f7befeca219afc402f4b9425da5aae01a4de07082ff37a5ffd2a3306f

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

module Workarea
  class Admin::VariantViewModel < ApplicationViewModel
    delegate :msrp, :on_sale, :on_sale?, :discountable,
      :discountable?, :tax_code, :sell_price, to: :pricing

    def pricing
      @pricing ||= Pricing::Sku.find_or_create_by(id: sku)
    end

    def inventory
      @inventory ||= Inventory::Sku.find_or_create_by(id: sku)
    end

    def available_inventory
      inventory.available_to_sell
    end

    def available_to_sell_inventory
      inventory.available_to_sell
    end

    def fulfillment
      @fulfillment ||= Fulfillment::Sku.find_or_create_by(id: sku)
    end

    def fulfillment_policy
      fulfillment.policy.titleize
    end

    def detail_1_name
      details_array.first.try(:first)
    end

    def detail_1_value
      details_array.first.try(:second)
    end

    def detail_2_name
      details_array.second.try(:first)
    end

    def detail_2_value
      details_array.second.try(:second)
    end

    def detail_3_name
      details_array.third.try(:first)
    end

    def detail_3_value
      details_array.third.try(:second)
    end

    private

    def details_array
      details.to_a
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/view_models/workarea/admin/variant_view_model.rb
workarea-admin-3.5.26 app/view_models/workarea/admin/variant_view_model.rb
workarea-admin-3.5.25 app/view_models/workarea/admin/variant_view_model.rb
workarea-admin-3.5.23 app/view_models/workarea/admin/variant_view_model.rb
workarea-admin-3.5.22 app/view_models/workarea/admin/variant_view_model.rb
workarea-admin-3.5.21 app/view_models/workarea/admin/variant_view_model.rb
workarea-admin-3.5.20 app/view_models/workarea/admin/variant_view_model.rb
workarea-admin-3.5.19 app/view_models/workarea/admin/variant_view_model.rb