Sha256: d21560aac9dc5bca3d07dc5ec4b59744391555563d1a9336349054ed93f9b3f1

Contents?: true

Size: 789 Bytes

Versions: 1

Compression:

Stored size: 789 Bytes

Contents

module Spree
  Variant.class_eval do
    has_many :add_on_mall_prices, class_name: 'Spree::AddOnMallPrice'

#   builds add_on_maker_variants from created variant ids
    after_create :create_add_on_mall_prices_from_variants

#   enable variants to CRUD each own add_on_maker_variants by accept nesting as child
    accepts_nested_attributes_for :add_on_mall_prices, allow_destroy: true

    def create_add_on_mall_prices_from_variants
      if Spree::AddOnMall.exists?
        Spree::AddOnMallPrice.where(variant_id: self.id).first_or_initialize do |a|
          a.variant_id = self.id
          logger.info a.inspect
          if a.save
          logger.info "save completed"
          else
          logger.info "save imcompleted!"
          end
        end
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_malls-0.1.0 app/models/spree/variant_decorator.rb