Module: CatalogsHelper

Defined in:
app/helpers/catalogs_helper.rb

Overview

View helper: catalogs.

Instance Method Summary collapse

Instance Method Details

#catalog_image_profile_marketplace(catalog) ⇒ Symbol

Determines which image profile marketplace to use for a catalog.
Amazon catalogs use AMZ profiles, Walmart catalogs use WAL profiles, others use WYS (website)

Parameters:

  • catalog (Catalog)

    the catalog to determine the marketplace for

Returns:

  • (Symbol)

    one of +:AMZ+, +:WAL+, or +:WYS+



49
50
51
52
53
54
55
56
57
# File 'app/helpers/catalogs_helper.rb', line 49

def catalog_image_profile_marketplace(catalog)
  if catalog.is_amazon?
    :AMZ
  elsif catalog.orchestrator_key&.start_with?('walmart')
    :WAL
  else
    :WYS
  end
end

#catalog_image_profile_scope(catalog) ⇒ Symbol

Returns the image profile scope method name for a catalog.

Parameters:

  • catalog (Catalog)

    the catalog to determine the image profile scope for

Returns:

  • (Symbol)

    one of +:amazon_image_profiles+, +:walmart_image_profiles+,
    or +:website_image_profiles+

See Also:



65
66
67
68
69
70
71
# File 'app/helpers/catalogs_helper.rb', line 65

def catalog_image_profile_scope(catalog)
  case catalog_image_profile_marketplace(catalog)
  when :AMZ then :amazon_image_profiles
  when :WAL then :walmart_image_profiles
  else :website_image_profiles
  end
end

#catalog_marketplace_name(catalog) ⇒ String

Returns human-readable name for the marketplace.

Parameters:

  • catalog (Catalog)

    the catalog to name the marketplace for

Returns:

  • (String)

    one of +'Amazon'+, +'Walmart'+, or +'Website'+

See Also:



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

def catalog_marketplace_name(catalog)
  case catalog_image_profile_marketplace(catalog)
  when :AMZ then 'Amazon'
  when :WAL then 'Walmart'
  else 'Website'
  end
end

#catalog_tab_options(catalog = @catalog) ⇒ Hash{Symbol => Hash}

Builds the tab navigation options for a catalog detail page.

Parameters:

  • catalog (Catalog) (defaults to: @catalog)

    the catalog to build tab links for
    (defaults to the +@catalog+ instance variable)

Returns:

  • (Hash{Symbol => Hash})

    tab options keyed by tab name, each with
    +:remote_href+ and +:title+ entries



34
35
36
37
38
39
40
41
42
# File 'app/helpers/catalogs_helper.rb', line 34

def catalog_tab_options(catalog = @catalog)
  {
    overview: { remote_href: tab_overview_catalog_path(catalog), title: 'Overview' },
    items: { remote_href: tab_items_catalog_path(catalog), title: 'Items' },
    settings: { remote_href: tab_settings_catalog_path(catalog), title: 'Settings' },
    relationships: { remote_href: tab_relationships_catalog_path(catalog), title: 'Relationships' },
    images: { remote_href: tab_images_catalog_path(catalog), title: 'Images' }
  }
end

#catalogs_with_us_ca_prioritized(catalogs) ⇒ Array<Catalog>

Sorts catalogs by name with the main US and Canada catalogs moved to the front.

Logic Details

The Canada catalog is promoted first, then the US catalog, so the final
order is: US, Canada, then the remaining catalogs alphabetically by name.

Parameters:

  • catalogs (Enumerable<Catalog>)

    the catalogs to sort and prioritize

Returns:

  • (Array<Catalog>)

    catalogs sorted by name with US and Canada first

See Also:



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/catalogs_helper.rb', line 14

def catalogs_with_us_ca_prioritized(catalogs)
  catalogs_sorted = catalogs.to_a.sort_by(&:name)
  # Extract US and Canada main catalogs and move them to the front
  if (wy_ca = catalogs_sorted.find { |c| c.id == CatalogConstants::CA_CATALOG_ID })
    catalogs_sorted.delete(wy_ca)
    catalogs_sorted.insert(0, wy_ca)
  end
  if (wy_us = catalogs_sorted.find { |c| c.id == CatalogConstants::US_CATALOG_ID })
    catalogs_sorted.delete(wy_us)
    catalogs_sorted.insert(0, wy_us)
  end
  catalogs_sorted
end