Class: Catalog

Inherits:
ApplicationRecord show all
Includes:
CatalogConstants, Models::Auditable, Models::Lineage, OrderQuery
Defined in:
app/models/catalog.rb

Overview

== Schema Information

Table name: catalogs
Database name: primary

id :integer not null, primary key
alternate_warehouse_stock_fraction :integer default(25), not null
bom_enabled :boolean default(FALSE), not null
country_iso3 :string(3) not null
currency :string(255)
currency_symbol :string(255)
default_catalog_item_state :string(30)
external_price_check_enabled :boolean default(FALSE), not null
for_admin :boolean default(FALSE), not null
is_active_third_party_sku_filter :boolean default(FALSE), not null
is_discontinued :boolean default(FALSE), not null
locales :string default([]), not null, is an Array
map_percentage :decimal(5, 4) default(0.8), not null
name :string(255)
orchestrator_key :string
parent_catalog_discount :decimal(5, 4)
parent_catalog_discount_refurb :decimal(5, 4) default(0.0)
price_sync_delay :integer
price_sync_policy :integer default("price_sync_manual"), not null
public_name :string
require_upc :boolean default(FALSE), not null
retailer_part_number_label :string
retailer_type :integer default("marketplace"), not null
shipping_preferences :jsonb
third_party_name_en_required :boolean default(FALSE), not null
third_party_name_fr_required :boolean default(FALSE), not null
third_party_part_number_required :boolean default(FALSE), not null
third_party_sku_filter_regex :string
third_party_sku_required :boolean default(FALSE), not null
url_template :string
vendor_code :string
website :string
created_at :datetime
updated_at :datetime
amazon_marketplace_id :integer
company_id :integer
parent_catalog_id :integer
sales_manager_employee_record_id :integer
store_id :integer

Indexes

catalogs_company_id_idx (company_id)
catalogs_parent_catalog_id_idx (parent_catalog_id)
catalogs_sales_manager_employee_record_id_idx (sales_manager_employee_record_id)
index_catalogs_on_alternate_warehouse_stock_fraction (alternate_warehouse_stock_fraction)
index_catalogs_on_amazon_marketplace_id (amazon_marketplace_id)
index_catalogs_on_bom_enabled (bom_enabled)
index_catalogs_on_name (name)
index_catalogs_on_store_id (store_id)

Foreign Keys

catalogs_company_id_fkey (company_id => companies.id)
catalogs_sales_manager_employee_record_id_fk (sales_manager_employee_record_id => employee_records.id)
catalogs_store_id_fkey (store_id => stores.id)
fk_rails_... (amazon_marketplace_id => amazon_marketplaces.id)
fk_rails_... (country_iso3 => countries.iso3)
fk_rails_... (parent_catalog_id => catalogs.id)

Defined Under Namespace

Classes: AmazonBuyBoxRecoveryService, AmazonImageBackfillService, AmazonPriceLoweringService, AmazonPriceRaisingService, AmazonPricingAutomationService, AssignCatalogItem, AssignCatalogToCustomer, CatalogCloner, CreateCatalogItem, PullAmazonCatalogSuppressionData, PullAmazonCatalogsListingsData, PushCatalogItemPrice, SynchronizeCatalogPrices, UpdateCatalog, UpdateCatalogItem, ValidateCatalogItems

Constant Summary collapse

EXCLUDABLE_DIRECT_CARRIERS =

Convenience: all carrier exclusion options for select dropdowns

%w[SpeedeeDelivery USPS UPS FedEx Canadapost Purolator Canpar RlCarriers Freightquote].freeze
EXCLUDABLE_MARKETPLACE_CARRIERS =
%w[USPS FEDEX UPS SPEEDEE ONTRAC LASERSHIP DHL AMAZON_SHIPPING].freeze

Constants included from CatalogConstants

CatalogConstants::ALL_MAIN_CATALOG_IDS, CatalogConstants::AMAZON_CATALOG_IDS, CatalogConstants::AMAZON_CA_CATALOG_IDS, CatalogConstants::AMAZON_EU_CATALOG_IDS, CatalogConstants::AMAZON_NA_SELLER_IDS, CatalogConstants::AMAZON_SC_BE_CATALOG_ID, CatalogConstants::AMAZON_SC_CATALOG_IDS, CatalogConstants::AMAZON_SC_CA_CATALOG_ID, CatalogConstants::AMAZON_SC_DE_CATALOG_ID, CatalogConstants::AMAZON_SC_ES_CATALOG_ID, CatalogConstants::AMAZON_SC_FR_CATALOG_ID, CatalogConstants::AMAZON_SC_IT_CATALOG_ID, CatalogConstants::AMAZON_SC_NL_CATALOG_ID, CatalogConstants::AMAZON_SC_PL_CATALOG_ID, CatalogConstants::AMAZON_SC_SE_CATALOG_ID, CatalogConstants::AMAZON_SC_UK_CATALOG_ID, CatalogConstants::AMAZON_SC_US_CATALOG_ID, CatalogConstants::AMAZON_SELLER_IDS, CatalogConstants::AMAZON_US_CATALOG_IDS, CatalogConstants::AMAZON_VC_CATALOG_IDS, CatalogConstants::AMAZON_VC_CA_CATALOG_ID, CatalogConstants::AMAZON_VC_CA_CATALOG_IDS, CatalogConstants::AMAZON_VC_DIRECT_FULFILLMENT_CATALOG_IDS, CatalogConstants::AMAZON_VC_US_CATALOG_IDS, CatalogConstants::AMAZON_VC_US_WASN4_CATALOG_ID, CatalogConstants::AMAZON_VC_US_WAX7V_CATALOG_ID, CatalogConstants::AMAZON_VC_WAT0F_CA_CATALOG_ID, CatalogConstants::AMAZON_VC_WAT4D_CA_CATALOG_ID, CatalogConstants::AMAZON_VENDOR_CODE_TO_CATALOG_ID, CatalogConstants::BESTBUY_CANADA, CatalogConstants::BUILD_COM, CatalogConstants::CANADIAN_TIRE, CatalogConstants::CA_CATALOG_ID, CatalogConstants::COSTCO_CANADA, CatalogConstants::COSTCO_CATALOGS, CatalogConstants::COSTCO_USA, CatalogConstants::EU_CATALOG_ID, CatalogConstants::HOME_DEPOT_CANADA, CatalogConstants::HOME_DEPOT_CATALOGS, CatalogConstants::HOME_DEPOT_USA, CatalogConstants::HOUZZ, CatalogConstants::LOCALE_TO_CATALOG, CatalogConstants::LOWES_CANADA, CatalogConstants::LOWES_USA, CatalogConstants::MARKETPLACE_CATALOGS, CatalogConstants::PRICE_CHECK_ENABLED_CATALOGS, CatalogConstants::RONA_CANADA, CatalogConstants::US_CATALOG_ID, CatalogConstants::VENDOR_CATALOGS, CatalogConstants::WALMART_CATALOGS, CatalogConstants::WALMART_SELLER_CANADA, CatalogConstants::WALMART_SELLER_USA, CatalogConstants::WAYFAIR_CANADA, CatalogConstants::WAYFAIR_CATALOGS, CatalogConstants::WAYFAIR_GERMANY, CatalogConstants::WAYFAIR_USA

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has and belongs to many collapse

Has many collapse

Delegated Instance Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CatalogConstants

amazon_catalog?, amazon_seller_catalog?, costco_catalog?, home_depot_catalog?, marketplace_catalog?, price_check_enabled?, vendor_catalog?, walmart_catalog?, wayfair_catalog?

Methods included from Models::Lineage

#ancestors, #ancestors_ids, #children_and_roots, #descendants, #descendants_ids, #ensure_non_recursive_lineage, #family_members, #generate_full_name, #generate_full_name_array, #lineage, #lineage_array, #lineage_simple, #root, #root_id, #self_ancestors_and_descendants, #self_ancestors_and_descendants_ids, #self_and_ancestors, #self_and_ancestors_ids, #self_and_children, #self_and_descendants, #self_and_descendants_ids, #self_and_siblings, #self_and_siblings_ids, #siblings, #siblings_ids

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#company_idObject (readonly)



91
# File 'app/models/catalog.rb', line 91

validates :name, :currency, :currency_symbol, :store_id, :company_id, presence: true

#currencyObject (readonly)



91
# File 'app/models/catalog.rb', line 91

validates :name, :currency, :currency_symbol, :store_id, :company_id, presence: true

#currency_symbolObject (readonly)



91
# File 'app/models/catalog.rb', line 91

validates :name, :currency, :currency_symbol, :store_id, :company_id, presence: true

#default_catalog_item_stateObject (readonly)



93
# File 'app/models/catalog.rb', line 93

validates :default_catalog_item_state, presence: true

#explode_product_linesObject

Returns the value of attribute explode_product_lines.



147
148
149
# File 'app/models/catalog.rb', line 147

def explode_product_lines
  @explode_product_lines
end

#nameObject (readonly)



91
# File 'app/models/catalog.rb', line 91

validates :name, :currency, :currency_symbol, :store_id, :company_id, presence: true

#parent_catalog_idObject (readonly)



94
# File 'app/models/catalog.rb', line 94

validates :parent_catalog_id, presence: { if: :price_sync_timed?, message: 'When price sync timed is set, a parent catalog is required' }

#price_sync_delayObject (readonly)



92
# File 'app/models/catalog.rb', line 92

validates :price_sync_delay, presence: { if: :price_sync_timed? }

#price_sync_policyObject (readonly)



95
96
# File 'app/models/catalog.rb', line 95

validates :price_sync_policy, inclusion: { in: %w[price_sync_timed], message: 'must be timed if a price sync delay is specified',
if: :price_sync_delay }

#store_idObject (readonly)



91
# File 'app/models/catalog.rb', line 91

validates :name, :currency, :currency_symbol, :store_id, :company_id, presence: true

Class Method Details

.activeActiveRecord::Relation<Catalog>

A relation of Catalogs that are active. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



109
# File 'app/models/catalog.rb', line 109

scope :active, -> { where(is_discontinued: false) }

.amazon_sellersActiveRecord::Relation<Catalog>

A relation of Catalogs that are amazon sellers. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



117
# File 'app/models/catalog.rb', line 117

scope :amazon_sellers, -> { where(id: AMAZON_SELLER_IDS) }

.amazonsActiveRecord::Relation<Catalog>

A relation of Catalogs that are amazons. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



116
# File 'app/models/catalog.rb', line 116

scope :amazons, -> { where(id: AMAZON_CATALOG_IDS) }

.bom_enabledActiveRecord::Relation<Catalog>

A relation of Catalogs that are bom enabled. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



111
# File 'app/models/catalog.rb', line 111

scope :bom_enabled, -> { where(bom_enabled: true) }

.ca_catalogObject



164
165
166
# File 'app/models/catalog.rb', line 164

def self.ca_catalog
  Catalog.find(CA_CATALOG_ID).freeze
end

.catalog_for_party(party) ⇒ Object



186
187
188
# File 'app/models/catalog.rb', line 186

def self.catalog_for_party(party)
  party&.catalog || Catalog.locale_to_catalog(I18n.locale)
end

.catalog_id_to_locale(catalog_id) ⇒ Object



182
183
184
# File 'app/models/catalog.rb', line 182

def self.catalog_id_to_locale(catalog_id)
  { US_CATALOG_ID => 'en-US', CA_CATALOG_ID => 'en-CA' }[catalog_id] || 'en-US'
end

.default_for_country(country_iso3_or_iso2) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
# File 'app/models/catalog.rb', line 200

def self.default_for_country(country_iso3_or_iso2)
  # TODO: I18n: Add other countries here or store catalog in country table
  case country_iso3_or_iso2&.upcase
  when 'CA', 'CAN'
    Catalog.ca_catalog
  when *Country::EU_COUNTRIES_ISO
    Catalog.eu_catalog
  else
    Catalog.us_catalog
  end
end

.eu_catalogObject



168
169
170
# File 'app/models/catalog.rb', line 168

def self.eu_catalog
  Catalog.find(EU_CATALOG_ID).freeze
end

.for_amazon_seller_marketplace_identifier(marketplace_identifier) ⇒ Object



226
227
228
229
230
231
# File 'app/models/catalog.rb', line 226

def self.for_amazon_seller_marketplace_identifier(marketplace_identifier)
  amz_mp = AmazonMarketplace.find_by(marketplace_identifier: marketplace_identifier)
  return nil unless amz_mp

  Catalog.amazon_sellers.where(amazon_marketplace_id: amz_mp.id).first
end

.for_countryActiveRecord::Relation<Catalog>

A relation of Catalogs that are for country. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



112
# File 'app/models/catalog.rb', line 112

scope :for_country, ->(country) { includes(:store).where(stores: { country_iso3: country }) }

.for_google_feedActiveRecord::Relation<Catalog>

A relation of Catalogs that are for google feed. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



115
# File 'app/models/catalog.rb', line 115

scope :for_google_feed, -> { main_catalogs }

.locale_to_catalog(locale = nil) ⇒ Object



177
178
179
180
# File 'app/models/catalog.rb', line 177

def self.locale_to_catalog(locale = nil)
  locale ||= I18n.locale
  Catalog.find(locale_to_catalog_id(locale))
end

.locale_to_catalog_id(locale = nil) ⇒ Object



172
173
174
175
# File 'app/models/catalog.rb', line 172

def self.locale_to_catalog_id(locale = nil)
  locale ||= I18n.locale
  LOCALE_TO_CATALOG[locale.to_sym] || US_CATALOG_ID
end

.main_catalog_idsObject

These are the catalog that are offered on our site



252
253
254
# File 'app/models/catalog.rb', line 252

def self.main_catalog_ids
  [US_CATALOG_ID, CA_CATALOG_ID]
end

.main_catalogsActiveRecord::Relation<Catalog>

A relation of Catalogs that are main catalogs. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



113
# File 'app/models/catalog.rb', line 113

scope :main_catalogs, -> { where(id: Catalog.main_catalog_ids) }

.non_adminActiveRecord::Relation<Catalog>

A relation of Catalogs that are non admin. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



110
# File 'app/models/catalog.rb', line 110

scope :non_admin, -> { where(for_admin: false) }

.options_for_select(default_scope = nil, prioritize_main_catalogs: true, show_store_info: false) ⇒ Object



190
191
192
193
194
195
196
197
198
# File 'app/models/catalog.rb', line 190

def self.options_for_select(default_scope = nil, prioritize_main_catalogs: true, show_store_info: false)
  catalogs = (default_scope || Catalog.active.non_admin).includes(:store)
  catalogs = catalogs.order("catalogs.id NOT IN (#{Catalog.main_catalog_ids.join(',')})".sql_safe) if prioritize_main_catalogs
  catalogs.order(:name).map do |c|
    n = c.name
    n << " (#{c.store.short_name})" if show_store_info
    [n, c.id]
  end
end

.price_alert_catalog_idsObject

Catalogs that should have detailed line-by-line price change alerts
Includes main website catalogs plus Amazon Seller Central catalogs



258
259
260
# File 'app/models/catalog.rb', line 258

def self.price_alert_catalog_ids
  main_catalog_ids + AMAZON_SC_CATALOG_IDS
end

.seller_na_catalogsActiveRecord::Relation<Catalog>

A relation of Catalogs that are seller na catalogs. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



118
# File 'app/models/catalog.rb', line 118

scope :seller_na_catalogs, -> { where(id: AMAZON_NA_SELLER_IDS) }

.target_catalog_options_for_selectObject

Used in mass action assignment, showing the % off from the master catalog if any



213
214
215
216
217
218
219
220
221
222
223
224
# File 'app/models/catalog.rb', line 213

def self.target_catalog_options_for_select
  # where.not(id: main_catalog_ids).where.not(parent_catalog_id: nil)
  Catalog.order(:name).map do |catalog|
    n = catalog.name
    if catalog.parent_catalog
      n << " - #{catalog.parent_catalog_discount * 100} % off" if catalog.parent_catalog_discount && catalog.parent_catalog_discount.positive?
      n << " - #{catalog.parent_catalog_discount_refurb * 100} % off (refurb)" if catalog.parent_catalog_discount_refurb && catalog.parent_catalog_discount_refurb.positive?
    end

    [n, catalog.id]
  end
end

.us_catalogObject



160
161
162
# File 'app/models/catalog.rb', line 160

def self.us_catalog
  Catalog.find(US_CATALOG_ID).freeze
end

.vendorsActiveRecord::Relation<Catalog>

A relation of Catalogs that are vendors. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



119
# File 'app/models/catalog.rb', line 119

scope :vendors, -> { where(retailer_type: :vendor) }

.with_orchestrator_keyActiveRecord::Relation<Catalog>

A relation of Catalogs that are with orchestrator key. Active Record Scope

Returns:

  • (ActiveRecord::Relation<Catalog>)

See Also:



114
# File 'app/models/catalog.rb', line 114

scope :with_orchestrator_key, -> { where.not(orchestrator_key: [nil, '']) }

Instance Method Details

#amazon_catalog?Boolean

Returns:

  • (Boolean)


270
271
272
273
# File 'app/models/catalog.rb', line 270

def amazon_catalog?
  # id.in?(AMAZON_CATALOG_IDS)
  amazon_marketplace.present?
end

#amazon_fulfillable?Boolean

Returns:

  • (Boolean)


275
276
277
# File 'app/models/catalog.rb', line 275

def amazon_fulfillable?
  id.in?(AMAZON_SELLER_IDS)
end

#amazon_marketplaceAmazonMarketplace



78
# File 'app/models/catalog.rb', line 78

belongs_to :amazon_marketplace, optional: true, inverse_of: :catalogs

#apply_default_countryObject



431
432
433
434
435
# File 'app/models/catalog.rb', line 431

def apply_default_country
  return unless store

  self.country_iso3 ||= store.country.iso3
end

#apply_default_localesObject



422
423
424
425
426
427
428
429
# File 'app/models/catalog.rb', line 422

def apply_default_locales
  return if locales.present?

  default_locales = []
  default_locales = store.country.locales_for_country if store
  default_locales += parent_catalog.locales || [] if parent_catalog
  self.locales = default_locales & I18n.available_locales
end

#carrier_excluded?(carrier_name) ⇒ Boolean

Returns true if the given direct carrier name is excluded for this catalog.
Carrier names match ShippingOption#carrier values (e.g. "SpeedeeDelivery", "USPS", "FedEx").

Returns:

  • (Boolean)


388
389
390
391
392
# File 'app/models/catalog.rb', line 388

def carrier_excluded?(carrier_name)
  return false if excluded_carriers.blank?

  excluded_carriers.any? { |ec| ec.casecmp?(carrier_name.to_s) }
end

#catalog_itemsActiveRecord::Relation<CatalogItem>

Returns:

See Also:



85
# File 'app/models/catalog.rb', line 85

has_many :catalog_items, dependent: :destroy, inverse_of: :catalog

#check_for_item_restrictions?Boolean

This is for channel specific items (custom catalog)
Should this catalog requires check in pick item to make sure they don't pick
a restricted catalog item

Returns:

  • (Boolean)


236
237
238
# File 'app/models/catalog.rb', line 236

def check_for_item_restrictions?
  is_main_catalog?
end

#companyCompany

Returns:

See Also:



74
# File 'app/models/catalog.rb', line 74

belongs_to :company, inverse_of: :catalogs

#countryCountry

Returns:

See Also:



77
# File 'app/models/catalog.rb', line 77

belongs_to :country, foreign_key: 'country_iso3', primary_key: 'iso3'

#couponsActiveRecord::Relation<Coupon>

Returns:

  • (ActiveRecord::Relation<Coupon>)

See Also:



88
# File 'app/models/catalog.rb', line 88

has_many :coupons, through: :customer_filters

#customer_filtersActiveRecord::Relation<CustomerFilter>

Returns:

See Also:



80
# File 'app/models/catalog.rb', line 80

has_and_belongs_to_many :customer_filters

#customer_service_managerObject



356
357
358
# File 'app/models/catalog.rb', line 356

def customer_service_manager
  Employee.customer_service_manager
end

#customersActiveRecord::Relation<Customer>

Returns:

See Also:



83
# File 'app/models/catalog.rb', line 83

has_many :customers

#deep_dupObject



151
152
153
154
155
156
157
158
# File 'app/models/catalog.rb', line 151

def deep_dup
  deep_clone(
    include: :catalog_items,
    except: %i[created_at updated_at]
  ) do |original, copy|
    copy.name = "#{original.name} copy" if copy.is_a?(Catalog)
  end
end

#determine_retailer_part_number_labelObject



360
361
362
# File 'app/models/catalog.rb', line 360

def determine_retailer_part_number_label
  retailer_part_number_label || 'Third Party Part Number'
end

#discontinue_catalog_itemsObject



346
347
348
349
350
# File 'app/models/catalog.rb', line 346

def discontinue_catalog_items
  return unless is_discontinued_changed? && is_discontinued?

  catalog_items.each(&:discontinue)
end

#is_amazon?Boolean

Returns:

  • (Boolean)


370
371
372
# File 'app/models/catalog.rb', line 370

def is_amazon?
  CatalogConstants::AMAZON_CATALOG_IDS.include?(id)
end

#is_amazon_seller_central?Boolean

Returns:

  • (Boolean)


374
375
376
# File 'app/models/catalog.rb', line 374

def is_amazon_seller_central?
  CatalogConstants::AMAZON_SC_CATALOG_IDS.include?(id)
end

#is_amazon_vendor_central?Boolean

Returns:

  • (Boolean)


378
379
380
# File 'app/models/catalog.rb', line 378

def is_amazon_vendor_central?
  CatalogConstants::AMAZON_VC_CATALOG_IDS.include?(id)
end

#is_main_catalog?Boolean

Returns:

  • (Boolean)


266
267
268
# File 'app/models/catalog.rb', line 266

def is_main_catalog?
  Catalog.main_catalog_ids.include?(id)
end

#itemsActiveRecord::Relation<Item>

Returns:

  • (ActiveRecord::Relation<Item>)

See Also:



87
# File 'app/models/catalog.rb', line 87

has_many :items, through: :catalog_items

#load_orchestratorObject



382
383
384
# File 'app/models/catalog.rb', line 382

def load_orchestrator
  customers.map { |c| Edi::BaseOrchestrator.orchestrator_for_customer_id(c.id) }.compact.first
end

#locale_for_catalogObject



309
310
311
312
313
314
315
316
317
# File 'app/models/catalog.rb', line 309

def locale_for_catalog
  # TODO: I18n: multi countries and multi locale
  case currency
  when 'CAD'
    :'en-CA'
  else
    :'en-US'
  end
end

#locales_for_catalogObject

Better method which takes into consideration that certain country will have multiple locales



320
321
322
# File 'app/models/catalog.rb', line 320

def locales_for_catalog
  (locales.presence || country&.locales_for_country || store.country.locales_for_country) & I18n.available_locales
end

#marketplace_catalog?Boolean

Returns:

  • (Boolean)


247
248
249
# File 'app/models/catalog.rb', line 247

def marketplace_catalog?
  is_main_catalog?
end

#marketplace_rate_excluded?(service_code) ⇒ Boolean

Returns true if a marketplace rate's service code should be excluded.
Checks both the general excluded_marketplace_carriers list and the
independent sww_usps_excluded toggle for SWW USPS specifically.

Parameters:

  • service_code (String)

    e.g. "SWW_USPS_GROUND_ADVANTAGE", "AMZBS_SPEEDEE_DELIVERY"

Returns:

  • (Boolean)


400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'app/models/catalog.rb', line 400

def marketplace_rate_excluded?(service_code)
  code = service_code.to_s.upcase
  is_sww = code.start_with?('SWW_')
  is_amzbs = code.start_with?('AMZBS_')
  return false unless is_sww || is_amzbs

  # Independent SWW USPS toggle
  return true if is_sww && sww_usps_excluded? && code.start_with?('SWW_USPS')

  # General marketplace carrier exclusions
  return false if excluded_marketplace_carriers.blank?

  prefix = is_sww ? 'SWW_' : 'AMZBS_'
  excluded_marketplace_carriers.any? do |carrier|
    code.start_with?("#{prefix}#{carrier.upcase}")
  end
end

#ok_to_destroy?Boolean

Returns:

  • (Boolean)


352
353
354
# File 'app/models/catalog.rb', line 352

def ok_to_destroy?
  !LineItem.joins(:catalog_item).merge(catalog_items).exists?
end

#ordersActiveRecord::Relation<Order>

Returns:

  • (ActiveRecord::Relation<Order>)

See Also:



84
# File 'app/models/catalog.rb', line 84

has_many :orders, through: :customers

#parent_catalogCatalog

Returns:

See Also:



76
# File 'app/models/catalog.rb', line 76

belongs_to :parent_catalog, class_name: 'Catalog', optional: true

#parent_catalog_options_for_selectObject



303
304
305
306
307
# File 'app/models/catalog.rb', line 303

def parent_catalog_options_for_select
  catalogs = Catalog.main_catalogs
  catalogs = catalogs.where(store_id:) if store_id
  catalogs.pluck(:name, :id)
end

#product_line_ids_for_analysisObject



340
341
342
# File 'app/models/catalog.rb', line 340

def product_line_ids_for_analysis
  (product_lines_ids_from_catalog_items + product_line_ids).uniq.sort
end

#product_linesActiveRecord::Relation<ProductLine>

Returns:

See Also:



81
# File 'app/models/catalog.rb', line 81

has_and_belongs_to_many :product_lines

#product_lines_defined?Boolean

Returns:

  • (Boolean)


289
290
291
# File 'app/models/catalog.rb', line 289

def product_lines_defined?
  product_line_ids.present?
end

#product_lines_for_sales_portalObject

This method is used to render a list of product line publicly available on /all_products
We look at all product line available to sales portal, then remove any that don't have any
items returned by the standard product page api query



243
244
245
# File 'app/models/catalog.rb', line 243

def product_lines_for_sales_portal
  ProductLine.for_index
end

#product_lines_from_catalog_itemsObject



324
325
326
327
328
329
330
331
332
333
334
# File 'app/models/catalog.rb', line 324

def product_lines_from_catalog_items
  raw_sql = %{
    exists(select 1 from item_product_lines ipl
           inner join items i on i.id = ipl.item_id
           inner join store_items si on si.item_id = i.id
           inner join catalog_items ci on ci.store_item_id = si.id and ci.catalog_id = ?
           where ipl.product_line_id = product_lines.id and ipl.position = 1
         )
  }
  ProductLine.where(raw_sql, id).order(:lineage_expanded)
end

#product_lines_ids_from_catalog_itemsObject



336
337
338
# File 'app/models/catalog.rb', line 336

def product_lines_ids_from_catalog_items
  product_lines_from_catalog_items.pluck(:id)
end

#public_catalog_itemsObject

Alias for Catalog_items#public_catalog_items

Returns:

  • (Object)

    Catalog_items#public_catalog_items

See Also:



344
# File 'app/models/catalog.rb', line 344

delegate :public_catalog_items, to: :catalog_items

#reported_nameObject



262
263
264
# File 'app/models/catalog.rb', line 262

def reported_name
  public_name.presence || name.presence
end

#sales_managerEmployeeRecord



75
# File 'app/models/catalog.rb', line 75

belongs_to :sales_manager, foreign_key: 'sales_manager_employee_record_id', class_name: 'EmployeeRecord', optional: true

#storeStore

Returns:

See Also:



73
# File 'app/models/catalog.rb', line 73

belongs_to :store, inverse_of: :catalogs

#store_items_for_selectObject



293
294
295
# File 'app/models/catalog.rb', line 293

def store_items_for_select
  store.store_items.active.available.joins(:item).includes(:item).order('items.sku').map { |si| ["#{si.item.sku} - #{si.item.name}", si.id] }
end

#storesActiveRecord::Relation<Store>

Returns:

  • (ActiveRecord::Relation<Store>)

See Also:



89
# File 'app/models/catalog.rb', line 89

has_many :stores, -> { distinct }, through: :catalog_items

#stores_for_selectObject



297
298
299
300
301
# File 'app/models/catalog.rb', line 297

def stores_for_select
  return Store.none unless company

  company.stores.order(:name).pluck(:name, :id)
end

#stripe_keyObject



364
365
366
367
368
# File 'app/models/catalog.rb', line 364

def stripe_key
  Payment::Apis::Stripe.publishable_key(currency)
rescue ArgumentError
  nil
end

#tax_rateObject



279
280
281
# File 'app/models/catalog.rb', line 279

def tax_rate
  country&.tax_rate&.goods
end

#tax_rate_stringObject



283
284
285
# File 'app/models/catalog.rb', line 283

def tax_rate_string
  "#{tax_rate * 100}%" if tax_rate.present?
end

#to_sObject



287
# File 'app/models/catalog.rb', line 287

def to_s = "#{name} [#{id}]"

#view_product_catalogsActiveRecord::Relation<ViewProductCatalog>

Returns:

See Also:



86
# File 'app/models/catalog.rb', line 86

has_many :view_product_catalogs