Sha256: 7e57b31dd7f0a93fd2127b4fbf991ceb73220e1516fefcaf57e1ccd1e4313e12

Contents?: true

Size: 616 Bytes

Versions: 11

Compression:

Stored size: 616 Bytes

Contents

# frozen_string_literal: true

module Alchemy
  class EssenceSpreeProduct < ActiveRecord::Base
    PRODUCT_ID = /\A\d+\z/

    belongs_to :product, class_name: 'Spree::Product',
      optional: true, foreign_key: 'spree_product_id'

    acts_as_essence(ingredient_column: :product)

    def ingredient=(product_or_id)
      case product_or_id
      when PRODUCT_ID
        self.spree_product_id = product_or_id
      when Spree::Product
        self.product = product_or_id
      else
        super
      end
    end

    def preview_text(_maxlength)
      return unless product
      product.name
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
alchemy-solidus-3.3.0 app/models/alchemy/essence_spree_product.rb
alchemy-solidus-3.2.2 app/models/alchemy/essence_spree_product.rb
alchemy-solidus-3.2.1 app/models/alchemy/essence_spree_product.rb
alchemy-solidus-3.2.0 app/models/alchemy/essence_spree_product.rb
alchemy-solidus-3.1.1 app/models/alchemy/essence_spree_product.rb
alchemy-solidus-3.1.0 app/models/alchemy/essence_spree_product.rb
alchemy-solidus-3.0.2 app/models/alchemy/essence_spree_product.rb
alchemy-solidus-3.0.1 app/models/alchemy/essence_spree_product.rb
alchemy-solidus-3.0.0 app/models/alchemy/essence_spree_product.rb
alchemy-solidus-2.5.1 app/models/alchemy/essence_spree_product.rb
alchemy-solidus-2.5.0 app/models/alchemy/essence_spree_product.rb