Sha256: 724963016e7898bdddb667a81e890374b1dea3039bf89d28cbaa7d77466c93d0

Contents?: true

Size: 1.14 KB

Versions: 3

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
    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

3 entries across 3 versions & 1 rubygems

Version Path
workarea-admin-3.5.18 app/view_models/workarea/admin/variant_view_model.rb
workarea-admin-3.5.17 app/view_models/workarea/admin/variant_view_model.rb
workarea-admin-3.5.16 app/view_models/workarea/admin/variant_view_model.rb