Sha256: 4dc0b914addee20e91a75b71a5d9d6993580aa181f0a608296cf12fd6fb10783

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

module Shopper
  module CheckoutPage
    class AddressStepPresenter < Rectify::Presenter
      def initialize(order, billing_form = nil, shipping_form = nil, use_billing = nil)
        @order = order
        @billing_form  = billing_form
        @shipping_form = shipping_form
        @use_billing   = use_billing || order.use_billing
        super()
      end

      attr_reader :use_billing

      def order_summary
        @order_summary ||= OrderSummary::OrderDecorator
                           .new(@order, deficit_method: :hide, position: :left)
      end

      def billing
        @billing = address(:billing)
      end

      def shipping
        @shipping = address(:shipping)
      end

      def selected_country_id(type)
        send(type).country_id || 1
      end

      def countries
        Country.order(:name).pluck(:name, :id)
      end

      def shipping_fields_style
        'display: none;' if use_billing
      end

      private

      def address(type)
        address = instance_variable_get("@#{type}_form") ||
                  current_order.send("#{type}_address")  ||
                  current_customer.send("#{type}_address")

        return address if address

        "Shopper::#{type.capitalize}Address".constantize.new(
          first_name: current_customer.first_name,
          last_name:  current_customer.last_name
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoppper-0.1.0 app/presenters/shopper/checkout_page/address_step_presenter.rb