Class: CatalogPresenter

Inherits:
BasePresenter show all
Includes:
Presenters::StandardOperationsForRecord
Defined in:
app/presenters/catalog_presenter.rb

Constant Summary collapse

BASE_BADGE_CLASS =
'px-2 py-1'.freeze

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

#actions_drop_downObject



27
28
29
30
31
32
33
34
35
36
37
# File 'app/presenters/catalog_presenter.rb', line 27

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_stockObject



61
62
63
64
65
66
67
68
# File 'app/presenters/catalog_presenter.rb', line 61

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


169
170
171
172
173
174
175
# File 'app/presenters/catalog_presenter.rb', line 169

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-specific: items where reported product type differs from desired



114
115
116
117
118
119
120
121
122
123
# File 'app/presenters/catalog_presenter.rb', line 114

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_feedsObject



283
284
285
# File 'app/presenters/catalog_presenter.rb', line 283

def associated_feeds
  Feed.joins(:customer).where(Customer[:catalog_id].eq(catalog.id)).order(:name)
end


7
8
9
# File 'app/presenters/catalog_presenter.rb', line 7

def breadcrumb_all_catalogs
  h.(:li, h.link_to('Catalogs', h.catalogs_path), class: 'breadcrumb-item')
end


15
16
17
# File 'app/presenters/catalog_presenter.rb', line 15

def breadcrumb_current_catalog
  h.(:li, h.link_to(name, h.catalog_path(id)), class: 'breadcrumb-item') unless new_record?
end


11
12
13
# File 'app/presenters/catalog_presenter.rb', line 11

def breadcrumb_parent_catalog
  h.(:li, h.link_to(parent_catalog.name, h.catalog_path(parent_catalog)), class: 'breadcrumb-item') if parent_catalog
end


19
20
21
22
23
24
25
# File 'app/presenters/catalog_presenter.rb', line 19

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_fulfilledObject



95
96
97
98
99
100
101
102
# File 'app/presenters/catalog_presenter.rb', line 95

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


70
71
72
73
74
75
76
# File 'app/presenters/catalog_presenter.rb', line 70

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


78
79
80
81
82
83
84
# File 'app/presenters/catalog_presenter.rb', line 78

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


86
87
88
89
90
91
92
93
# File 'app/presenters/catalog_presenter.rb', line 86

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


104
105
106
107
108
109
110
111
# File 'app/presenters/catalog_presenter.rb', line 104

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

Gives you a link to the catalog items in this particular product line



160
161
162
163
164
165
166
167
# File 'app/presenters/catalog_presenter.rb', line 160

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


53
54
55
56
57
58
59
# File 'app/presenters/catalog_presenter.rb', line 53

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


125
126
127
128
129
130
131
# File 'app/presenters/catalog_presenter.rb', line 125

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_statesObject



49
50
51
# File 'app/presenters/catalog_presenter.rb', line 49

def catalog_items_states
  catalog.catalog_items.pluck(:state).uniq.sort
end

#css_class_for_product_line(product_line) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'app/presenters/catalog_presenter.rb', line 39

def css_class_for_product_line(product_line)
  return unless product_line_ids.include?(product_line.id)

  if product_lines_from_catalog_items.detect { |pl| pl.id == product_line.id }
    :success
  else
    :warning
  end
end


287
288
289
290
# File 'app/presenters/catalog_presenter.rb', line 287

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


211
212
213
# File 'app/presenters/catalog_presenter.rb', line 211

def delete_prices_link(options = {})
  destroy_record_link(catalog, options)
end


227
228
229
230
231
# File 'app/presenters/catalog_presenter.rb', line 227

def duplicate_catalog_link(options = {})
  return unless h.can?(:create, Catalog)

  h.link_to 'Duplicate Catalog', h.duplicate_catalog_path(id)
end


223
224
225
# File 'app/presenters/catalog_presenter.rb', line 223

def edit_catalog_link(options = {})
  edit_record_link(catalog, options)
end


177
178
179
180
181
182
183
# File 'app/presenters/catalog_presenter.rb', line 177

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


200
201
202
203
# File 'app/presenters/catalog_presenter.rb', line 200

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


189
190
191
192
193
194
195
196
197
198
# File 'app/presenters/catalog_presenter.rb', line 189

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


185
186
187
# File 'app/presenters/catalog_presenter.rb', line 185

def items_not_in_catalog_link_from_product_lines
  items_not_in_catalog_link(product_line_ids)
end

#map_percentage_displayObject



153
154
155
156
157
# File 'app/presenters/catalog_presenter.rb', line 153

def map_percentage_display
  return unless retailer_type_vendor?

  "#{(map_percentage * 100).round(0)}% of MSRP"
end

MAP violation link - only for vendor catalogs with active items below MAP



134
135
136
137
138
139
140
141
142
143
# File 'app/presenters/catalog_presenter.rb', line 134

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 })[0]
end


215
216
217
218
219
220
221
# File 'app/presenters/catalog_presenter.rb', line 215

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_friendlyObject



251
252
253
254
255
256
# File 'app/presenters/catalog_presenter.rb', line 251

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_friendlyObject



258
259
260
261
262
263
# File 'app/presenters/catalog_presenter.rb', line 258

def parent_catalog_discount_refurb_friendly
  return unless parent_catalog
  return 'Untracked' unless parent_catalog_discount_refurb

  "#{parent_catalog_discount_refurb * 100} % off"
end


265
266
267
# File 'app/presenters/catalog_presenter.rb', line 265

def parent_catalog_link
  h.link_to(parent_catalog.name, h.catalog_path(parent_catalog)) if parent_catalog
end

#price_sync_policy_humanObject



269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'app/presenters/catalog_presenter.rb', line 269

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


247
248
249
# File 'app/presenters/catalog_presenter.rb', line 247

def product_line_analysis_link
  h.link_to('Analyze Product Lines', h.product_line_analysis_catalog_path(catalog))
end

#product_lines_actual?Boolean

Returns:

  • (Boolean)


238
239
240
# File 'app/presenters/catalog_presenter.rb', line 238

def product_lines_actual?
  catalog.product_lines_from_catalog_items.present?
end


242
243
244
245
# File 'app/presenters/catalog_presenter.rb', line 242

def product_lines_actual_link
  h.link_to(h.(:span, catalog.product_lines_from_catalog_items.size, class: BASE_BADGE_CLASS),
            h.product_line_analysis_catalog_path(catalog))
end


233
234
235
236
# File 'app/presenters/catalog_presenter.rb', line 233

def product_lines_specified_link
  h.link_to(h.(:span, catalog.product_line_ids.size, class: BASE_BADGE_CLASS),
            h.product_line_analysis_catalog_path(catalog))
end

#retailer_type_badgeObject



145
146
147
148
149
150
151
# File 'app/presenters/catalog_presenter.rb', line 145

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


205
206
207
208
209
# File 'app/presenters/catalog_presenter.rb', line 205

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