Module: HasTrolleyControllerHelpersOverrides::UrlFor

Defined in:
lib/kete_gets_trollied/has_trolley_controller_helpers_overrides.rb

Instance Method Summary collapse

Instance Method Details

#url_for_order(options = { }) ⇒ Object

expects order either as instance variables or in options



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kete_gets_trollied/has_trolley_controller_helpers_overrides.rb', line 36

def url_for_order(options = { })
  trolley = options.delete(:trolley) || @trolley
  trolley = @order.trolley if @order

  order = options.delete(:order) || @order || trolley.selected_order
  
  options[:id] = order
  options[:controller] = 'orders'
  options[:action] = 'show'
  options[:urlified_name] = Basket.site_basket.urlified_name

  url_for options
end

#url_for_trolley(options = { }) ⇒ Object

expects user in options or @user or trolley being set unless @purchasable_item is present WARNING: in the case of @purchasable_item this method name breaks the principle of least surprise maybe alter trollied gem in future to come right



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kete_gets_trollied/has_trolley_controller_helpers_overrides.rb', line 14

def url_for_trolley(options = { })
  return url_for_dc_identifier(@purchasable_item) if @purchasable_item && params[:action] == 'create'

  user = options.delete(:user)
  trolley = options[:trolley] || @trolley || user.trolley

  if trolley.blank?
    user = @user
  else
    user = trolley.user
  end

  options[:user_id] = user.id
  options[:controller] = 'trolleys'
  options[:action] = 'show'
  options[:urlified_name] = Basket.site_basket.urlified_name

  url = url_for(options) # .split(".%23%")[0]
end