Class: ExportedCatalogItemPacketAttribute
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ExportedCatalogItemPacketAttribute
- Defined in:
- app/models/exported_catalog_item_packet_attribute.rb
Overview
== Schema Information
Table name: exported_catalog_item_packet_attributes
Database name: primary
id :integer not null, primary key
attr_connected_to :string
attr_name :string
attr_position :integer
attr_rename :string
attr_type :string
attr_value :string
raw :boolean default(FALSE)
selected :boolean default(FALSE)
exported_catalog_item_packet_id :integer
Indexes
ecip_id_attr_name (exported_catalog_item_packet_id,attr_name)
idx_attr_ecip_id_selected (exported_catalog_item_packet_id,selected)
idx_ecip_id_attr_position (exported_catalog_item_packet_id,attr_position)
Constant Summary
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Belongs to collapse
Instance Method Summary collapse
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Method Details
#effective_name ⇒ Object
30 31 32 |
# File 'app/models/exported_catalog_item_packet_attribute.rb', line 30 def effective_name attr_rename.presence || attr_name.presence end |
#exported_catalog_item_packet ⇒ ExportedCatalogItemPacket
25 |
# File 'app/models/exported_catalog_item_packet_attribute.rb', line 25 belongs_to :exported_catalog_item_packet, optional: true |
#render_value(ec_item) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/models/exported_catalog_item_packet_attribute.rb', line 34 def render_value(ec_item) case attr_type when 'static' if attr_connected_to.nil? attr_value else 'Not Found' end when 'catalog' cip = ec_item.catalog_item case attr_name when 'name' cip.item.name.to_s.squish when 'description' cip.item.detailed_description.to_s.squish when 'catalog_price' if raw cip.amount else ActionController::Base.helpers.number_to_currency(cip.amount, unit: cip.catalog.currency_symbol).to_s end when 'parent_catalog_price' if raw cip.parent_catalog_item_amount else ActionController::Base.helpers.number_to_currency(cip.parent_catalog_item_amount, unit: begin cip.parent_catalog_item.amount_currency_symbol rescue StandardError "$" end) end when 'discount' if cip.parent_catalog_item parent_amount = cip.parent_catalog_item.amount if parent_amount == cip.amount 0 elsif parent_amount > 0 ((1 - (cip.amount / parent_amount)) * 100).round(2) else 100 end else 'N/A' end end when 'image' ec_images = ec_item.exported_catalog_item_images.where(excluded: false).to_a if (idx = attr_name[/image_url_(\d+)/, 1]) ec_images[idx.to_i - 1]&.image_url elsif (idx = attr_name[/image_name_(\d+)/, 1]) ec_images[idx.to_i - 1]&.file_name end else i = ec_item.catalog_item.item if raw begin i.rendered_product_specifications.dig(attr_name.to_sym, :raw) || i.send(attr_name) rescue StandardError nil end else begin i.rendered_product_specifications.dig(attr_name.to_sym, :output) || i.send(attr_name) rescue StandardError nil end end end end |