Module: BaSpree::ProductDecorator
- Defined in:
- app/models/ba_spree/product_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.prepended(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/ba_spree/product_decorator.rb', line 3 def self.prepended(base) # Spree 5.3 以前は、商品ごとのオプション並び順(spree_product_option_types.position)を正にするため # `option_types` を reorder('spree_product_option_types.position') で上書きしていた。 # しかし through association の order/reorder に「他テーブルの列」を書くと、Rails が preload # (WHERE id IN (...)) で読む経路で JOIN が外れ ORDER 句だけ残るため、 # 「Unknown column 'spree_product_option_types.position' in 'order clause'」で # taxons#show(カテゴリページ)が 500 になる(5.3 で option_types を preload する経路が増え顕在化)。 # # この罠は through の order に他テーブル列を書く限り原理的に回避できないため、上書きを削除し # 5.3 core のデフォルト(`option_types, through: :product_option_types` + `product_option_types # -> order(:position)`)に委ねる。これにより並び順は # `spree_option_types.position`(グローバル順) → `spree_product_option_types.position`(商品ごと順) # の複合になり、「商品ごと順」は第2ソートキーへ後退する。 # ※ org4 の複数 option_type 商品 355 件すべてで両者の並び順が一致することを確認済み(実害なし)。 # 将来「商品ごとにオプション表示順を変える」運用が必要になった場合は、option_types を直接 # 並べ替えるのではなく product_option_types.order(:position) 経由で option_type を引く形に # 変更すること(preload 安全な書き方が必要)。 base.has_many :option_types_for_includes, -> { order(:id) }, through: :product_option_types, source: :option_type, class_name: 'Spree::OptionType' # ProductProperty -> metafields 移行用の読み書きヘルパー(Spree 5.4 の Property 削除対応) base.include Spree::ProductPropertyMetafields end |
Instance Method Details
#set_slug ⇒ Object
29 30 31 |
# File 'app/models/ba_spree/product_decorator.rb', line 29 def set_slug self.slug = generate_slug end |