Class: Search::ProductCatalogPresenter

Inherits:
BasePresenter
  • Object
show all
Includes:
Presenters::Timeable
Defined in:
app/presenters/search/product_catalog_presenter.rb

Overview

Row presenter for ProductCatalogSearch — renders the cells in the CRM
product catalog search/results table. Wraps a ViewProductCatalog projection
rather than a fully-loaded CatalogItem so the search grid stays light.

Direct Known Subclasses

ProductCatalogTextPresenter

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from BasePresenter

#can?, #capture, #concat, #content_tag, #fa_icon, #h, #initialize, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u

Constructor Details

This class inherits a constructor from BasePresenter

Instance Method Details

#catalogActiveSupport::SafeBuffer?

Linked catalog name → catalog show page.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


43
44
45
46
47
# File 'app/presenters/search/product_catalog_presenter.rb', line 43

def catalog
  return unless r.has_columns?(:catalog_name, :catalog_id)

  h.link_to(r.catalog_name, h.catalog_path(r.catalog_id))
end

Linked coupon code → coupon show page.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


25
26
27
28
29
# File 'app/presenters/search/product_catalog_presenter.rb', line 25

def coupon_link
  return unless r.has_columns?(:coupon_id, :coupon_code)

  h.link_to(r.coupon_code, h.coupon_path(r.coupon_id))
end

#effective_priceString?

Effective price formatted as currency.

Returns:

  • (String, nil)


164
165
166
167
168
# File 'app/presenters/search/product_catalog_presenter.rb', line 164

def effective_price
  return unless r.has_columns?(:effective_price, :currency_symbol)

  h.number_to_currency(r.effective_price, unit: r.currency_symbol)
end

#effective_price_with_vatString?

Effective price including VAT formatted as currency.

Returns:

  • (String, nil)


191
192
193
194
195
# File 'app/presenters/search/product_catalog_presenter.rb', line 191

def effective_price_with_vat
  return unless r.has_columns?(:effective_price_with_vat, :currency_symbol)

  h.number_to_currency(r.effective_price_with_vat, unit: r.currency_symbol)
end

#item_skuActiveSupport::SafeBuffer, String

Linked item SKU → catalog item show page when an ID is available.

Returns:

  • (ActiveSupport::SafeBuffer, String)


14
15
16
17
18
19
20
# File 'app/presenters/search/product_catalog_presenter.rb', line 14

def item_sku
  if r.respond_to?(:id)
    h.link_to(r.item_sku, h.catalog_item_path(r.id))
  else
    r.item_sku
  end
end

#map_priceString?

Minimum advertised price formatted as currency.

Returns:

  • (String, nil)


118
119
120
121
122
# File 'app/presenters/search/product_catalog_presenter.rb', line 118

def map_price
  return unless r.has_columns?(:map_price, :currency_symbol)

  h.number_to_currency(r.map_price, unit: r.currency_symbol)
end

#map_violationActiveSupport::SafeBuffer?

MAP violation indicator badge (Yes/No).

Returns:

  • (ActiveSupport::SafeBuffer, nil)


127
128
129
130
131
132
133
134
135
136
# File 'app/presenters/search/product_catalog_presenter.rb', line 127

def map_violation
  return unless r.has_columns?(:map_violation, :retail_price, :map_price, :currency_symbol)
  return if r.map_violation.nil?

  if r.map_violation
    h.tag.span('Yes', class: 'badge bg-danger', title: "Retail: #{h.number_to_currency(r.retail_price, unit: r.currency_symbol)} < MAP: #{h.number_to_currency(r.map_price, unit: r.currency_symbol)}")
  else
    h.tag.span('No', class: 'badge bg-success')
  end
end

#old_priceString?

Previous item price formatted as currency.

Returns:

  • (String, nil)


79
80
81
82
83
# File 'app/presenters/search/product_catalog_presenter.rb', line 79

def old_price
  return unless r.has_columns?(:old_price, :currency_symbol)

  h.number_to_currency(r.old_price, unit: r.currency_symbol)
end

#parent_catalog_itemActiveSupport::SafeBuffer?

Linked parent catalog item name → parent catalog item show page.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


52
53
54
55
56
# File 'app/presenters/search/product_catalog_presenter.rb', line 52

def parent_catalog_item
  return unless r.has_columns?(:parent_catalog_item_id, :parent_catalog_name)

  h.link_to(r.parent_catalog_name, h.catalog_item_path(r.parent_catalog_item_id))
end

#parent_catalog_priceString?

Parent catalog price formatted as currency.

Returns:

  • (String, nil)


61
62
63
64
65
# File 'app/presenters/search/product_catalog_presenter.rb', line 61

def parent_catalog_price
  return unless r.has_columns?(:parent_catalog_price, :currency_symbol)

  h.number_to_currency(r.parent_catalog_price, unit: r.currency_symbol)
end

#parent_price_updated_atString

Date the parent catalog price was last updated.

Returns:

  • (String)


95
96
97
# File 'app/presenters/search/product_catalog_presenter.rb', line 95

def parent_price_updated_at
  h.render_date(r.parent_price_updated_at)
end

#priceString?

Item price formatted as currency.

Returns:

  • (String, nil)


70
71
72
73
74
# File 'app/presenters/search/product_catalog_presenter.rb', line 70

def price
  return unless r.has_columns?(:price, :currency_symbol)

  h.number_to_currency(r.price, unit: r.currency_symbol)
end

#price_differenceString

Difference between item and parent catalog prices formatted as currency.

Returns:

  • (String)


141
142
143
# File 'app/presenters/search/product_catalog_presenter.rb', line 141

def price_difference
  h.number_to_currency(r.price_difference, unit: r.currency_symbol)
end

#price_difference_factorActiveSupport::SafeBuffer, ...

Percentage factor of the price divergence from the parent catalog.

Returns:

  • (ActiveSupport::SafeBuffer, BigDecimal, nil)


200
201
202
203
204
205
206
207
208
209
210
211
# File 'app/presenters/search/product_catalog_presenter.rb', line 200

def price_difference_factor
  return unless r.has_columns?(:price_diverging, :price_difference_factor)

  if r.price_diverging
    h.(:p,
         (r.price_difference_factor * 100).round(2),
         style: 'color: red;font-weight:bolder',
         title: "The parent catalog discount differs from the discount in this item. Parent catalog discount is #{(r.parent_catalog_discount * 100).round(2)} %")
  else
    (r.price_difference_factor * 100).round(2)
  end
end

#price_updated_atString

Date the item price was last updated.

Returns:

  • (String)


88
89
90
# File 'app/presenters/search/product_catalog_presenter.rb', line 88

def price_updated_at
  h.render_date(r.price_updated_at)
end

#price_updated_parent_differential_in_daysString

Difference in days between item and parent catalog price updates.

Returns:

  • (String)


102
103
104
# File 'app/presenters/search/product_catalog_presenter.rb', line 102

def price_updated_parent_differential_in_days
  h.pluralize(r.price_updated_parent_differential_in_days.to_i, 'day')
end

#price_with_vatString?

Price including VAT formatted as currency.

Returns:

  • (String, nil)


173
174
175
176
177
# File 'app/presenters/search/product_catalog_presenter.rb', line 173

def price_with_vat
  return unless r.has_columns?(:price_with_vat, :currency_symbol)

  h.number_to_currency(r.price_with_vat, unit: r.currency_symbol)
end

#retail_priceString?

Retail price formatted as currency.

Returns:

  • (String, nil)


109
110
111
112
113
# File 'app/presenters/search/product_catalog_presenter.rb', line 109

def retail_price
  return unless r.has_columns?(:retail_price, :currency_symbol)

  h.number_to_currency(r.retail_price, unit: r.currency_symbol)
end

#sale_priceString?

Sale price formatted as currency.

Returns:

  • (String, nil)


155
156
157
158
159
# File 'app/presenters/search/product_catalog_presenter.rb', line 155

def sale_price
  return unless r.has_columns?(:sale_price, :currency_symbol)

  h.number_to_currency(r.sale_price, unit: r.currency_symbol)
end

#sale_price_with_vatString?

Sale price including VAT formatted as currency.

Returns:

  • (String, nil)


182
183
184
185
186
# File 'app/presenters/search/product_catalog_presenter.rb', line 182

def sale_price_with_vat
  return unless r.has_columns?(:sale_price_with_vat, :currency_symbol)

  h.number_to_currency(r.sale_price_with_vat, unit: r.currency_symbol)
end

#stateString?

Catalog item state as a string.

Returns:

  • (String, nil)


34
35
36
37
38
# File 'app/presenters/search/product_catalog_presenter.rb', line 34

def state
  return unless r.has_columns?(:catalog_item_state)

  r.catalog_item_state.to_s
end

#store_item_unit_cogsString

Store item unit cost of goods sold formatted as currency.

Returns:

  • (String)


148
149
150
# File 'app/presenters/search/product_catalog_presenter.rb', line 148

def store_item_unit_cogs
  h.number_to_currency(r.store_item_unit_cogs)
end