Module: VariantGroupsHelper

Defined in:
app/helpers/variant_groups_helper.rb

Overview

View helpers for VariantGroup pages, notably the per-marketplace Amazon
parent-listing operations (absorbed from Crm::AmazonVariationsHelper).

An Amazon row belongs to exactly one Amazon marketplace, so every listing
action targets that marketplace's single Seller Central catalog.

Constant Summary collapse

CATALOG_STATE_BADGE_CLASSES =

Bootstrap badge classes per catalog_items.state (fallback: bg-info for
the onboarding/review states).

{
  'active' => 'bg-success',
  'active_hidden' => 'bg-warning text-dark',
  'discontinued' => 'bg-secondary'
}.freeze

Instance Method Summary collapse

Instance Method Details

#catalog_item_public_url(catalog_item) ⇒ String?

The public product page behind an ACTIVE listing: the retailer URL when
mirrored (catalog_items.url), our own www page for core catalog rows
(site map), else the Wayfair/Amazon URL derived from the listing ids.

Parameters:

Returns:

  • (String, nil)


42
43
44
45
46
47
48
49
# File 'app/helpers/variant_groups_helper.rb', line 42

def catalog_item_public_url(catalog_item)
  return unless catalog_item.state == 'active'

  catalog_item.url.presence ||
    catalog_item.site_maps.first&.url ||
    catalog_item.wayfair_product_url ||
    catalog_item.amazon_product_url
end

#catalog_item_state_badge(catalog_item) ⇒ ActiveSupport::SafeBuffer

State badge for one members-table catalog cell, linking to the catalog
item; a muted dash when the member has no row in that catalog. Active
listings additionally get an external-link icon to the public product
page (retailer page, or our www page for the core catalogs).

Parameters:

Returns:

  • (ActiveSupport::SafeBuffer)


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/variant_groups_helper.rb', line 23

def catalog_item_state_badge(catalog_item)
  return tag.span('', class: 'text-body-secondary') unless catalog_item

  css = CATALOG_STATE_BADGE_CLASSES.fetch(catalog_item.state, 'bg-info text-dark')
  badge = link_to(catalog_item.state.humanize, catalog_item_path(catalog_item),
                  class: "badge #{css}", data: { turbo_frame: '_top' })
  public_url = catalog_item_public_url(catalog_item)
  return badge unless public_url

  safe_join([badge,
             link_to(fa_icon('arrow-up-right-from-square', class: 'fa-xs'), public_url,
                     target: '_blank', rel: 'noopener noreferrer', title: 'Open public page')], ' ')
end

#governing_group_banner(channel_label, group) ⇒ ActiveSupport::SafeBuffer

"«Catalog» is governed by the … «group»" info banner shown on channel
panels when a different group (an override or the default) owns the
catalog's grouping.

Parameters:

  • channel_label (String)

    e.g. 'Wayfair-US'

  • group (VariantGroup)

    the governing group

Returns:

  • (ActiveSupport::SafeBuffer)


57
58
59
60
61
62
63
64
# File 'app/helpers/variant_groups_helper.rb', line 57

def governing_group_banner(channel_label, group)
  descriptor = group.override? ? "#{group.catalog.name} override" : 'default group'
  tag.div(class: 'alert alert-info mb-2') do
    safe_join(["#{channel_label} is governed by the ",
               link_to("#{descriptor} #{group.name}", variant_group_path(group), data: { turbo_frame: '_top' }),
               '.'])
  end
end

#variant_group_amazon_actions(variant_group) ⇒ Object



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

def variant_group_amazon_actions(variant_group)
  links = []
  return links unless can?(:manage, variant_group)

  links << link_to('Clone Listing', clone_variant_group_path(variant_group), data: { turbo_method: :post, turbo_confirm: 'Clone this listing?' })
  if (catalog = variant_group.listing_catalog)
    # The ProductCatalogSearch view aliases catalog_items.variant_group_id as
    # amazon_variation_id, so the legacy ransack key keeps working.
    links << link_to("Search AMZ #{variant_group.amazon_marketplace.iso_code} Catalog Items",
      new_search_path(type: 'ProductCatalogSearch', query_params: {
        catalog_id_in: [catalog.id],
        catalog_item_state_in: %w[active],
        amazon_variation_id_eq: variant_group.id
      }),
      target: '_blank', rel: 'noopener noreferrer')
  end
  links
end


100
101
102
103
104
105
106
# File 'app/helpers/variant_groups_helper.rb', line 100

def variant_group_amazon_delete_links(variant_group)
  variant_group_listing_action_links(variant_group) do |catalog, mkt|
    link_to("Delete #{mkt.iso_code} Listing",
      send_delete_listing_data_variant_group_path(variant_group, catalog_id: catalog.id),
      data: { turbo_method: :post, turbo_confirm: "Delete listing from #{mkt.name}?" })
  end
end


85
86
87
88
89
90
# File 'app/helpers/variant_groups_helper.rb', line 85

def variant_group_amazon_pull_links(variant_group)
  variant_group_listing_action_links(variant_group) do |catalog, mkt|
    link_to("Pull #{mkt.iso_code} Listing Info",
      pull_listing_data_variant_group_path(variant_group, catalog_id: catalog.id))
  end
end


92
93
94
95
96
97
98
# File 'app/helpers/variant_groups_helper.rb', line 92

def variant_group_amazon_push_links(variant_group)
  variant_group_listing_action_links(variant_group) do |catalog, mkt|
    link_to("Send #{mkt.iso_code} Listing Data",
      send_listing_data_variant_group_path(variant_group, catalog_id: catalog.id),
      data: { turbo_method: :post, turbo_confirm: "Send listing to #{mkt.name}?" })
  end
end