Class: Catalog
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
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
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
#creator, #updater
Has and belongs to many
collapse
Delegated Instance Attributes
collapse
Class Method Summary
collapse
Instance Method Summary
collapse
amazon_catalog?, amazon_seller_catalog?, costco_catalog?, home_depot_catalog?, marketplace_catalog?, price_check_enabled?, vendor_catalog?, walmart_catalog?, wayfair_catalog?
#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
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Instance Attribute Details
#company_id ⇒ Object
91
|
# File 'app/models/catalog.rb', line 91
validates :name, :currency, :currency_symbol, :store_id, :company_id, presence: true
|
#currency ⇒ Object
91
|
# File 'app/models/catalog.rb', line 91
validates :name, :currency, :currency_symbol, :store_id, :company_id, presence: true
|
#currency_symbol ⇒ Object
91
|
# File 'app/models/catalog.rb', line 91
validates :name, :currency, :currency_symbol, :store_id, :company_id, presence: true
|
#default_catalog_item_state ⇒ Object
93
|
# File 'app/models/catalog.rb', line 93
validates :default_catalog_item_state, presence: true
|
#explode_product_lines ⇒ Object
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
|
#name ⇒ Object
91
|
# File 'app/models/catalog.rb', line 91
validates :name, :currency, :currency_symbol, :store_id, :company_id, presence: true
|
#parent_catalog_id ⇒ Object
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_delay ⇒ Object
92
|
# File 'app/models/catalog.rb', line 92
validates :price_sync_delay, presence: { if: :price_sync_timed? }
|
#price_sync_policy ⇒ Object
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_id ⇒ Object
91
|
# File 'app/models/catalog.rb', line 91
validates :name, :currency, :currency_symbol, :store_id, :company_id, presence: true
|
Class Method Details
.active ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are active. Active Record Scope
109
|
# File 'app/models/catalog.rb', line 109
scope :active, -> { where(is_discontinued: false) }
|
.amazon_sellers ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are amazon sellers. Active Record Scope
117
|
# File 'app/models/catalog.rb', line 117
scope :amazon_sellers, -> { where(id: AMAZON_SELLER_IDS) }
|
.amazons ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are amazons. Active Record Scope
116
|
# File 'app/models/catalog.rb', line 116
scope :amazons, -> { where(id: AMAZON_CATALOG_IDS) }
|
.bom_enabled ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are bom enabled. Active Record Scope
111
|
# File 'app/models/catalog.rb', line 111
scope :bom_enabled, -> { where(bom_enabled: true) }
|
.ca_catalog ⇒ Object
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
.eu_catalog ⇒ Object
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_country ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are for country. Active Record Scope
112
|
# File 'app/models/catalog.rb', line 112
scope :for_country, ->(country) { includes(:store).where(stores: { country_iso3: country }) }
|
.for_google_feed ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are for google feed. Active Record Scope
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_ids ⇒ Object
These are the catalog that are offered on our site
.main_catalogs ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are main catalogs. Active Record Scope
.non_admin ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are non admin. Active Record Scope
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_ids ⇒ Object
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_catalogs ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are seller na catalogs. Active Record Scope
118
|
# File 'app/models/catalog.rb', line 118
scope :seller_na_catalogs, -> { where(id: AMAZON_NA_SELLER_IDS) }
|
.target_catalog_options_for_select ⇒ Object
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
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_catalog ⇒ Object
160
161
162
|
# File 'app/models/catalog.rb', line 160
def self.us_catalog
Catalog.find(US_CATALOG_ID).freeze
end
|
.vendors ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are vendors. Active Record Scope
119
|
# File 'app/models/catalog.rb', line 119
scope :vendors, -> { where(retailer_type: :vendor) }
|
.with_orchestrator_key ⇒ ActiveRecord::Relation<Catalog>
A relation of Catalogs that are with orchestrator key. Active Record Scope
114
|
# File 'app/models/catalog.rb', line 114
scope :with_orchestrator_key, -> { where.not(orchestrator_key: [nil, '']) }
|
Instance Method Details
#amazon_catalog? ⇒ Boolean
270
271
272
273
|
# File 'app/models/catalog.rb', line 270
def amazon_catalog?
amazon_marketplace.present?
end
|
#amazon_fulfillable? ⇒ Boolean
275
276
277
|
# File 'app/models/catalog.rb', line 275
def amazon_fulfillable?
id.in?(AMAZON_SELLER_IDS)
end
|
78
|
# File 'app/models/catalog.rb', line 78
belongs_to :amazon_marketplace, optional: true, inverse_of: :catalogs
|
#apply_default_country ⇒ Object
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_locales ⇒ Object
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").
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_items ⇒ ActiveRecord::Relation<CatalogItem>
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
236
237
238
|
# File 'app/models/catalog.rb', line 236
def check_for_item_restrictions?
is_main_catalog?
end
|
74
|
# File 'app/models/catalog.rb', line 74
belongs_to :company, inverse_of: :catalogs
|
77
|
# File 'app/models/catalog.rb', line 77
belongs_to :country, foreign_key: 'country_iso3', primary_key: 'iso3'
|
#coupons ⇒ ActiveRecord::Relation<Coupon>
88
|
# File 'app/models/catalog.rb', line 88
has_many :coupons, through: :customer_filters
|
#customer_filters ⇒ ActiveRecord::Relation<CustomerFilter>
80
|
# File 'app/models/catalog.rb', line 80
has_and_belongs_to_many :customer_filters
|
#customer_service_manager ⇒ Object
356
357
358
|
# File 'app/models/catalog.rb', line 356
def customer_service_manager
Employee.customer_service_manager
end
|
#customers ⇒ ActiveRecord::Relation<Customer>
83
|
# File 'app/models/catalog.rb', line 83
has_many :customers
|
#deep_dup ⇒ Object
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_label ⇒ Object
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_items ⇒ Object
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_seller_central? ⇒ Boolean
#is_amazon_vendor_central? ⇒ Boolean
#is_main_catalog? ⇒ Boolean
266
267
268
|
# File 'app/models/catalog.rb', line 266
def is_main_catalog?
Catalog.main_catalog_ids.include?(id)
end
|
#items ⇒ ActiveRecord::Relation<Item>
87
|
# File 'app/models/catalog.rb', line 87
has_many :items, through: :catalog_items
|
#load_orchestrator ⇒ Object
#locale_for_catalog ⇒ Object
309
310
311
312
313
314
315
316
317
|
# File 'app/models/catalog.rb', line 309
def locale_for_catalog
case currency
when 'CAD'
:'en-CA'
else
:'en-US'
end
end
|
#locales_for_catalog ⇒ Object
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
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.
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
return true if is_sww && sww_usps_excluded? && code.start_with?('SWW_USPS')
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
352
353
354
|
# File 'app/models/catalog.rb', line 352
def ok_to_destroy?
!LineItem.joins(:catalog_item).merge(catalog_items).exists?
end
|
#orders ⇒ ActiveRecord::Relation<Order>
84
|
# File 'app/models/catalog.rb', line 84
has_many :orders, through: :customers
|
#parent_catalog ⇒ Catalog
76
|
# File 'app/models/catalog.rb', line 76
belongs_to :parent_catalog, class_name: 'Catalog', optional: true
|
#parent_catalog_options_for_select ⇒ Object
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_analysis ⇒ Object
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_lines ⇒ ActiveRecord::Relation<ProductLine>
81
|
# File 'app/models/catalog.rb', line 81
has_and_belongs_to_many :product_lines
|
#product_lines_defined? ⇒ Boolean
289
290
291
|
# File 'app/models/catalog.rb', line 289
def product_lines_defined?
product_line_ids.present?
end
|
#product_lines_for_sales_portal ⇒ Object
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_items ⇒ Object
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_items ⇒ Object
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_items ⇒ Object
Alias for Catalog_items#public_catalog_items
344
|
# File 'app/models/catalog.rb', line 344
delegate :public_catalog_items, to: :catalog_items
|
#reported_name ⇒ Object
262
263
264
|
# File 'app/models/catalog.rb', line 262
def reported_name
public_name.presence || name.presence
end
|
75
|
# File 'app/models/catalog.rb', line 75
belongs_to :sales_manager, foreign_key: 'sales_manager_employee_record_id', class_name: 'EmployeeRecord', optional: true
|
73
|
# File 'app/models/catalog.rb', line 73
belongs_to :store, inverse_of: :catalogs
|
#store_items_for_select ⇒ Object
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
|
#stores ⇒ ActiveRecord::Relation<Store>
89
|
# File 'app/models/catalog.rb', line 89
has_many :stores, -> { distinct }, through: :catalog_items
|
#stores_for_select ⇒ Object
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_key ⇒ Object
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_rate ⇒ Object
279
280
281
|
# File 'app/models/catalog.rb', line 279
def tax_rate
country&.tax_rate&.goods
end
|
#tax_rate_string ⇒ Object
283
284
285
|
# File 'app/models/catalog.rb', line 283
def tax_rate_string
"#{tax_rate * 100}%" if tax_rate.present?
end
|
#to_s ⇒ Object
287
|
# File 'app/models/catalog.rb', line 287
def to_s = "#{name} [#{id}]"
|
#view_product_catalogs ⇒ ActiveRecord::Relation<ViewProductCatalog>
86
|
# File 'app/models/catalog.rb', line 86
has_many :view_product_catalogs
|