Sha256: c9fa4151c1b7a67dc5b2d9ab1b099679b5ce27912fe419f7a56f1e7e0f572e5d

Contents?: true

Size: 936 Bytes

Versions: 2

Compression:

Stored size: 936 Bytes

Contents

module Workarea
  decorate Storefront::ProductViewModel, with: :global_e do
    decorated do
      delegate :sell_min_fixed_prices, :sell_max_fixed_prices, :original_min_fixed_prices, :original_max_fixed_prices, to: :pricing
    end

    def current_product?
      options["controller"] == "workarea/storefront/products" &&
        options["action"] == "show" &&
        options["id"] == model.slug
    end

    # @return [::String, nil]
    #
    def country_exceptions_data
      return unless current_product?

      data = model.country_exceptions.map do |country_exception|
        [
          country_exception.country.alpha2,
          {
            restricted: country_exception.restricted.presence,
            vat: country_exception.vat_rate.presence
          }.compact
        ]
      end.to_h

      if model.global_e_forbidden?
        data["all"] = { "forbidden" => true }
      end

      data.to_json
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-global_e-1.3.0 app/view_models/workarea/storefront/product_view_model.decorator
workarea-global_e-1.2.1 app/view_models/workarea/storefront/product_view_model.decorator