Sha256: 624a66e8bfd505e8c8a376b1d5fa6b50cb9d474c5c24d0201582cf7028df18e8

Contents?: true

Size: 1.46 KB

Versions: 28

Compression:

Stored size: 1.46 KB

Contents

module Workarea
  module Admin
    class FulfillmentViewModel < ApplicationViewModel
      def order
        options[:order] || OrderViewModel.wrap(Order.find(model.id))
      end

      def packages
        @packages ||= model.packages.map do |package|
          PackageViewModel.new(package, order: order)
        end
      end

      def pending_items
        @pending_items ||= model.pending_items.map do |fulfillment_item|
          next unless order_item = order
            .items
            .detect { |i| i.id.to_s == fulfillment_item.order_item_id }

          FulfillmentItemViewModel.new(
            order_item,
            quantity: fulfillment_item.quantity_pending
          )
        end.compact
      end

      def cancellations
        @cancellations ||= model.canceled_items.map do |fulfillment_item|
          next unless order_item = order
            .items
            .detect { |i| i.id.to_s == fulfillment_item.order_item_id }

          FulfillmentItemViewModel.new(
            order_item,
            quantity: fulfillment_item.quantity_canceled
          )
        end.compact
      end

      def skus
        @skus ||= FulfillmentSkusViewModel.wrap(
          Fulfillment::Sku.in(id: order.items.map(&:sku).uniq).to_a,
          options
        )
      end

      def tokens
        @tokens ||= FulfillmentTokenViewModel.wrap(
          Fulfillment::Token.by_order(order.id).to_a,
          options.merge(order: order)
        )
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-admin-3.5.6 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.5 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.4 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.3 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.2 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.1 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.0 app/view_models/workarea/admin/fulfillment_view_model.rb
workarea-admin-3.5.0.beta.1 app/view_models/workarea/admin/fulfillment_view_model.rb