Class: CatalogPresenter
- Inherits:
-
BasePresenter
show all
- Includes:
- Presenters::StandardOperationsForRecord
- Defined in:
- app/presenters/catalog_presenter.rb
Overview
Presenter: catalog presenter.
Constant Summary
collapse
- BASE_BADGE_CLASS =
'px-2 py-1'
Instance Attribute Summary
#current_account, #options, #url_helper
Instance Method Summary
collapse
#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
#actions_drop_down ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/presenters/catalog_presenter.rb', line 31
def actions_drop_down
h.render_combo_drop_down [edit_catalog_link,
product_line_analysis_link,
duplicate_catalog_link,
sync_prices_link,
:separator,
delete_prices_link,
:separator,
*h.audit_links(catalog)],
dropdown_options: { right_menu: true }, main_link_class: 'btn-primary'
end
|
#active_catalog_items_out_of_stock ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'app/presenters/catalog_presenter.rb', line 65
def active_catalog_items_out_of_stock
query_params = {
catalog_id_in: [id],
catalog_item_state_in: ['active'],
store_item_qty_available_lteq: 0
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params })[0]
end
|
#active_coupons_catalog_link ⇒ Object
173
174
175
176
177
178
179
|
# File 'app/presenters/catalog_presenter.rb', line 173
def active_coupons_catalog_link
query_params = {
status_in: ['active'],
customer_filter_catalog_ids_overlap_array: [id]
}
h.query_template_link(CouponSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params })[0]
end
|
#amazon_product_type_divergent_link ⇒ Object
Amazon-specific: items where reported product type differs from desired
118
119
120
121
122
123
124
125
126
127
|
# File 'app/presenters/catalog_presenter.rb', line 118
def amazon_product_type_divergent_link
return unless is_amazon?
query_params = {
catalog_id_in: [id],
catalog_item_state_in: ['active'],
amazon_product_type_divergent_eq: true
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params, show_zero: true })[0]
end
|
#associated_feeds ⇒ Object
287
288
289
|
# File 'app/presenters/catalog_presenter.rb', line 287
def associated_feeds
Feed.joins(:customer).where(Customer[:catalog_id].eq(catalog.id)).order(:name)
end
|
#breadcrumb_all_catalogs ⇒ Object
11
12
13
|
# File 'app/presenters/catalog_presenter.rb', line 11
def breadcrumb_all_catalogs
h.content_tag(:li, h.link_to('Catalogs', h.catalogs_path), class: 'breadcrumb-item')
end
|
#breadcrumb_current_catalog ⇒ Object
19
20
21
|
# File 'app/presenters/catalog_presenter.rb', line 19
def breadcrumb_current_catalog
h.content_tag(:li, h.link_to(name, h.catalog_path(id)), class: 'breadcrumb-item') unless new_record?
end
|
#breadcrumb_parent_catalog ⇒ Object
15
16
17
|
# File 'app/presenters/catalog_presenter.rb', line 15
def breadcrumb_parent_catalog
h.content_tag(:li, h.link_to(parent_catalog.name, h.catalog_path(parent_catalog)), class: 'breadcrumb-item') if parent_catalog
end
|
#breadcrumbs ⇒ Object
23
24
25
26
27
28
29
|
# File 'app/presenters/catalog_presenter.rb', line 23
def breadcrumbs
h.capture do
h.concat breadcrumb_all_catalogs
h.concat breadcrumb_parent_catalog
h.concat breadcrumb_current_catalog
end
end
|
#catalog_items_amazon_fulfilled ⇒ Object
99
100
101
102
103
104
105
106
|
# File 'app/presenters/catalog_presenter.rb', line 99
def catalog_items_amazon_fulfilled
query_params = {
catalog_id_in: [id],
catalog_item_state_in: CatalogItem::EDI_FEED_STATUSES,
fulfillment_eq: CatalogItem.fulfillments[:amazon_fulfilled]
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params })[0]
end
|
#catalog_items_for_edi_feed_link ⇒ Object
74
75
76
77
78
79
80
|
# File 'app/presenters/catalog_presenter.rb', line 74
def catalog_items_for_edi_feed_link
query_params = {
catalog_id_in: [id],
catalog_item_state_in: CatalogItem::EDI_FEED_STATUSES
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params })[0]
end
|
#catalog_items_for_edi_feed_link_only_active ⇒ Object
82
83
84
85
86
87
88
|
# File 'app/presenters/catalog_presenter.rb', line 82
def catalog_items_for_edi_feed_link_only_active
query_params = {
catalog_id_in: [id],
catalog_item_state_in: ['active']
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params })[0]
end
|
90
91
92
93
94
95
96
97
|
# File 'app/presenters/catalog_presenter.rb', line 90
def catalog_items_for_edi_feed_link_only_active_promo
query_params = {
catalog_id_in: [id],
catalog_item_state_in: ['active'],
sale_price_in_effect_eq: true
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params, show_zero: true })[0]
end
|
#catalog_items_for_edi_with_diverging_prices_link ⇒ Object
108
109
110
111
112
113
114
115
|
# File 'app/presenters/catalog_presenter.rb', line 108
def catalog_items_for_edi_with_diverging_prices_link
query_params = {
catalog_id_in: [id],
catalog_item_state_in: CatalogItem::EDI_FEED_STATUSES,
price_diverging_eq: true
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params })[0]
end
|
#catalog_items_in_product_line_link(product_line_id) ⇒ Object
Gives you a link to the catalog items in this particular product line
164
165
166
167
168
169
170
171
|
# File 'app/presenters/catalog_presenter.rb', line 164
def catalog_items_in_product_line_link(product_line_id)
query_params = {
catalog_id_in: [id],
product_line_ids_contains_array: [product_line_id],
catalog_item_state_in: ['active']
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params })[0]
end
|
#catalog_items_link(state = 'active') ⇒ Object
57
58
59
60
61
62
63
|
# File 'app/presenters/catalog_presenter.rb', line 57
def catalog_items_link(state = 'active')
query_params = {
catalog_id_in: [id],
catalog_item_state_in: [state].presence
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params })[0]
end
|
#catalog_items_link_hidden_from_feed_link ⇒ Object
129
130
131
132
133
134
135
|
# File 'app/presenters/catalog_presenter.rb', line 129
def catalog_items_link_hidden_from_feed_link
query_params = {
catalog_id_in: [id],
catalog_item_state_in: CatalogItem::HIDDEN_STATES
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params })[0]
end
|
#catalog_items_states ⇒ Object
53
54
55
|
# File 'app/presenters/catalog_presenter.rb', line 53
def catalog_items_states
catalog.catalog_items.pluck(:state).uniq.sort
end
|
#css_class_for_product_line(product_line) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'app/presenters/catalog_presenter.rb', line 43
def css_class_for_product_line(product_line)
return unless product_line_ids.include?(product_line.id)
if product_lines_from_catalog_items.find { |pl| pl.id == product_line.id }
:success
else
:warning
end
end
|
#customers_with_this_catalog_link ⇒ Object
291
292
293
294
|
# File 'app/presenters/catalog_presenter.rb', line 291
def customers_with_this_catalog_link
query_params = { catalog_id_in: [catalog.id] }
h.query_template_link(CustomerSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params }).first
end
|
#delete_prices_link(options = {}) ⇒ Object
215
216
217
|
# File 'app/presenters/catalog_presenter.rb', line 215
def delete_prices_link(options = {})
destroy_record_link(catalog, options)
end
|
#duplicate_catalog_link(_options = {}) ⇒ Object
231
232
233
234
235
|
# File 'app/presenters/catalog_presenter.rb', line 231
def duplicate_catalog_link(_options = {})
return unless h.can?(:create, Catalog)
h.link_to 'Duplicate Catalog', h.duplicate_catalog_path(id)
end
|
#edit_catalog_link(options = {}) ⇒ Object
227
228
229
|
# File 'app/presenters/catalog_presenter.rb', line 227
def edit_catalog_link(options = {})
edit_record_link(catalog, options)
end
|
#future_coupons_catalog_link ⇒ Object
181
182
183
184
185
186
187
|
# File 'app/presenters/catalog_presenter.rb', line 181
def future_coupons_catalog_link
query_params = {
status_in: ['future'],
customer_filter_catalog_ids_overlap_array: [id]
}
h.query_template_link(CouponSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params })[0]
end
|
#items_in_catalog_link ⇒ Object
204
205
206
207
|
# File 'app/presenters/catalog_presenter.rb', line 204
def items_in_catalog_link
query_params = { in_catalog: [id] }
h.query_template_link(ItemSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params }).first
end
|
#items_not_in_catalog_link(filter_product_line_ids = nil) ⇒ Object
193
194
195
196
197
198
199
200
201
202
|
# File 'app/presenters/catalog_presenter.rb', line 193
def items_not_in_catalog_link(filter_product_line_ids = nil)
filter_product_line_ids = [filter_product_line_ids].flatten if filter_product_line_ids.present?
query_params = {}
query_params[:in_catalog_and_active] = parent_catalog_id if parent_catalog_id
query_params[:not_in_catalog] = id
query_params[:product_category_id_in] = ProductCategory.all_non_publication_goods_ids
query_params[:primary_product_line_id_in] = filter_product_line_ids if filter_product_line_ids.present?
query_params[:is_discontinued_eq] = 'false'
h.query_template_link(ItemSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params }).first
end
|
#items_not_in_catalog_link_from_product_lines ⇒ Object
189
190
191
|
# File 'app/presenters/catalog_presenter.rb', line 189
def items_not_in_catalog_link_from_product_lines
items_not_in_catalog_link(product_line_ids)
end
|
#map_percentage_display ⇒ Object
157
158
159
160
161
|
# File 'app/presenters/catalog_presenter.rb', line 157
def map_percentage_display
return unless retailer_type_vendor?
"#{(map_percentage * 100).round(0)}% of MSRP"
end
|
#map_violations_link ⇒ Object
MAP violation link - only for vendor catalogs with active items below MAP
138
139
140
141
142
143
144
145
146
147
|
# File 'app/presenters/catalog_presenter.rb', line 138
def map_violations_link
return unless retailer_type_vendor?
query_params = {
catalog_id_in: [id],
catalog_item_state_in: ['active'],
map_violation_eq: true
}
h.query_template_link(ProductCatalogSearch, nil, { counter_class: BASE_BADGE_CLASS, query_params: query_params, show_zero: true })[0]
end
|
#new_catalog_item_link(options = {}) ⇒ Object
219
220
221
222
223
224
225
|
# File 'app/presenters/catalog_presenter.rb', line 219
def new_catalog_item_link(options = {})
return unless h.can?(:create, Catalog)
options[:class] = 'btn btn-outline-primary btn-block'
h.link_to(h.fa_icon('plus-circle', text: 'New Catalog Item'), h.new_catalog_catalog_item_path(catalog), **options)
end
|
#parent_catalog_discount_friendly ⇒ Object
255
256
257
258
259
260
|
# File 'app/presenters/catalog_presenter.rb', line 255
def parent_catalog_discount_friendly
return unless parent_catalog
return 'Untracked' unless parent_catalog_discount
"#{parent_catalog_discount * 100} % off"
end
|
#parent_catalog_discount_refurb_friendly ⇒ Object
262
263
264
265
266
267
|
# File 'app/presenters/catalog_presenter.rb', line 262
def parent_catalog_discount_refurb_friendly
return unless parent_catalog
return 'Untracked' unless parent_catalog_discount_refurb
"#{parent_catalog_discount_refurb * 100} % off"
end
|
#parent_catalog_link ⇒ Object
269
270
271
|
# File 'app/presenters/catalog_presenter.rb', line 269
def parent_catalog_link
h.link_to(parent_catalog.name, h.catalog_path(parent_catalog)) if parent_catalog
end
|
#price_sync_policy_human ⇒ Object
273
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'app/presenters/catalog_presenter.rb', line 273
def price_sync_policy_human
if price_sync_timed?
if price_sync_delay == 0
'Immediate'
else
"Timed, #{h.pluralize(price_sync_delay, 'day')} delay"
end
elsif price_sync_manual?
'Manual'
else
'Unknown'
end
end
|
#product_line_analysis_link ⇒ Object
251
252
253
|
# File 'app/presenters/catalog_presenter.rb', line 251
def product_line_analysis_link
h.link_to('Analyze Product Lines', h.product_line_analysis_catalog_path(catalog))
end
|
#product_lines_actual? ⇒ Boolean
242
243
244
|
# File 'app/presenters/catalog_presenter.rb', line 242
def product_lines_actual?
catalog.product_lines_from_catalog_items.present?
end
|
#product_lines_actual_link ⇒ Object
246
247
248
249
|
# File 'app/presenters/catalog_presenter.rb', line 246
def product_lines_actual_link
h.link_to(h.content_tag(:span, catalog.product_lines_from_catalog_items.size, class: BASE_BADGE_CLASS),
h.product_line_analysis_catalog_path(catalog))
end
|
#product_lines_specified_link ⇒ Object
237
238
239
240
|
# File 'app/presenters/catalog_presenter.rb', line 237
def product_lines_specified_link
h.link_to(h.content_tag(:span, catalog.product_line_ids.size, class: BASE_BADGE_CLASS),
h.product_line_analysis_catalog_path(catalog))
end
|
#retailer_type_badge ⇒ Object
149
150
151
152
153
154
155
|
# File 'app/presenters/catalog_presenter.rb', line 149
def retailer_type_badge
if retailer_type_vendor?
h.tag.span('Vendor (1P)', class: 'badge bg-warning')
else
h.tag.span('Marketplace (3P)', class: 'badge bg-info')
end
end
|
#sync_prices_link ⇒ Object
209
210
211
212
213
|
# File 'app/presenters/catalog_presenter.rb', line 209
def sync_prices_link
return unless catalog_items.present? && parent_catalog && h.can?(:update, catalog)
h.link_to 'Force Price Sync', h.sync_prices_catalog_path(id)
end
|