Sha256: d872bfe72dba206b95521f7032c37fb244cd57dfeea3e3b8fe3971ce65937a5e

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

module Workarea
  module Storefront
    module Checkout
      module GiftOptionsViewModel
        extend ActiveSupport::Concern

        included do
          delegate :gift_message, to: :shipping, allow_nil: true
        end

        def gift_message?
          gift_message.present?
        end

        # Whether to show gift wrapping as an option in checkout.
        # Based on whether the Catalog has any configured gift wrap.
        #
        # @return [Boolean]
        #
        def offer_gift_wrapping?
          gift_wraps.any?
        end

        # An array of gift wrapping options from the Catalog.
        # First element is the name, second is the id.
        # Used in the gift wrap select on the shipping step.
        #
        # @return [Array<Array>]
        #
        def gift_wrapping_options
          @gift_wrapping_options ||=
            [['None', nil]] + gift_wraps.map do |gift_wrap|
              [gift_wrap.name, gift_wrap.id.to_s]
            end
        end

        private

        def gift_wraps
          @gift_wraps ||= Catalog::GiftWrap.all.to_a
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-gift_wrapping-1.3.0 app/view_models/workarea/storefront/checkout/gift_options_view_model.rb
workarea-gift_wrapping-1.2.1 app/view_models/workarea/storefront/checkout/gift_options_view_model.rb