Module: MyQuotesHelper

Defined in:
app/helpers/my_quotes_helper.rb

Overview

View helper: my quotes.

Instance Method Summary collapse

Instance Method Details

#display_discounted_shipping_price(quote) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/my_quotes_helper.rb', line 67

def display_discounted_shipping_price(quote)
  shipping_cost = quote.line_items.shipping_only.to_a.sum(&:price_total)
  discounted_shipping_cost = quote.discounted_shipping_total
  currency_symbol = begin
    quote.currency_symbol
  rescue StandardError
    Money::Currency.new('USD').symbol
  end

  if shipping_cost == discounted_shipping_cost
    number_to_currency(shipping_cost, unit: currency_symbol)
  elsif discounted_shipping_cost.zero?
    tag.del(number_to_currency(shipping_cost, unit: currency_symbol), class: 'text-body-secondary small me-1') +
      tag.span('FREE', class: 'text-success fw-bold')
  else
    tag.del(number_to_currency(shipping_cost, unit: currency_symbol), class: 'text-body-secondary small me-1') +
      tag.span(number_to_currency(discounted_shipping_cost, unit: currency_symbol), class: 'text-danger fw-bold')
  end
end

#quote_primary_cta(quote) ⇒ Hash?

Primary purchase call-to-action for the customer-facing /ql/ quote,
computed once so the hero button (top), the in-page Purchase banner
(bottom), and the sidebar all render the SAME action (label + url +
data). Returns nil when there's no buy CTA — quote cancelled, already
converted to an active order, or not yet convertible — in which case
callers fall back to a "contact your rep" message.

Reads the controller-set @context_user (guest or signed-in party) and
@can_manage_cart (signed-in owner/contact) ivars — the same ones the
/ql/ partials use. Memoized per request.

Parameters:

Returns:

  • (Hash, nil)

    keys: :kind, :label, :url, :data



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/my_quotes_helper.rb', line 26

def quote_primary_cta(quote)
  return @quote_primary_cta if defined?(@quote_primary_cta)

  @quote_primary_cta =
    if quote.cancelled? || quote.placed_order.present? || !quote.can_convert?
      nil
    else
      cart           = @context_user&.cart
      cart_for_quote = cart && cart.quote_id == quote.id && cart.line_items.non_shipping.present?
      needs_shipping = quote.shipping_address.nil? || quote.deliveries.empty?

      if cart_for_quote
        { kind: :continue, label: 'Continue checkout', url: checkout_my_cart_path,
          data: { controller: 'ui-blocker' },
          hint: "You'll review the order on the next step before any charge." }
      elsif needs_shipping && @can_manage_cart
        { kind: :add_to_cart, label: 'Add to cart', url: add_to_cart_my_quote_path(quote),
          data: { turbo_frame: '_top', controller: 'ui-blocker' },
          hint: "You'll add a delivery address and review the order before any charge." }
      elsif needs_shipping
        { kind: :sign_in, label: 'Sign in to purchase', url: (quote),
          data: { turbo_frame: '_top' },
          hint: 'Sign in to your WarmlyYours account to add a delivery address and check out.' }
      else
        { kind: :buy_now, label: 'Buy now', url: buy_now_my_quote_path(quote),
          data: { turbo_frame: '_top', controller: 'ui-blocker' },
          hint: "You'll review the order on the next step before any charge." }
      end
    end
end

#quote_revision_history(quote) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/helpers/my_quotes_helper.rb', line 4

def quote_revision_history(quote)
  html = +''
  if quote.parent
    html << (:li, link_to("Quote # #{quote.parent.reference_number}", (quote.parent)))
    html << quote_revision_history(quote.parent)
  end
  raw(html)
end

#quote_sign_in_url(quote) ⇒ String

Devise sign-in URL that returns the visitor to this quote afterward — the
/ql/ short link when reached anonymously, else the my-account path.

Parameters:

Returns:

  • (String)


62
63
64
65
# File 'app/helpers/my_quotes_helper.rb', line 62

def (quote)
  return_path = params[:token].present? ? short_quote_lookup_path(token: params[:token]) : (quote.id)
  (devise_return_path: return_path)
end