Sha256: fd9f0687eba559a7a7db8bc1bc5e166a057d421f717bd7fea0d0b0ef44e6332d

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

require 'spree/core'

require 'solidus_subscriptions'
require 'solidus_subscriptions/permitted_attributes'
require 'solidus_subscriptions/configuration'
require 'solidus_subscriptions/processor'

module SolidusSubscriptions
  class Engine < Rails::Engine
    include SolidusSupport::EngineExtensions

    isolate_namespace SolidusSubscriptions

    engine_name 'solidus_subscriptions'

    # use rspec for tests
    config.generators do |g|
      g.test_framework :rspec
    end

    initializer 'solidus_subscriptions.update_permitted_attributes' do
      ::Spree::PermittedAttributes.line_item_attributes << {
        subscription_line_items_attributes: PermittedAttributes.subscription_line_item_attributes | [:id],
      }

      ::Spree::PermittedAttributes.user_attributes << {
        subscriptions_attributes: PermittedAttributes.subscription_attributes | [:id],
      }
    end

    initializer 'solidus_subscriptions.register_promotion_rules', after: 'spree.promo.register.promotion.rules' do |app|
      app.config.spree.promotions.rules << 'SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder'
      app.config.spree.promotions.rules << 'SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder'
    end

    initializer 'solidus_subscriptions.configure_backend' do
      next unless ::Spree::Backend::Config.respond_to?(:menu_items)

      ::Spree::Backend::Config.configure do |config|
        config.menu_items << config.class::MenuItem.new(
          [:subscriptions],
          'repeat',
          url: :admin_subscriptions_path,
          condition: ->{ can?(:admin, SolidusSubscriptions::Subscription) },
          match_path: '/subscriptions'
        )
      end
    end
  end

  def self.table_name_prefix
    'solidus_subscriptions_'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_subscriptions-1.0.0 lib/solidus_subscriptions/engine.rb
solidus_subscriptions-1.0.0.rc1 lib/solidus_subscriptions/engine.rb