Sha256: 1bece2fba1fafec4dbad186219c5e3dfb8eae79b418e54fe58043d1474d19ada

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

module ErpProducts
  module Shared
    class ProductFeaturesController < ActionController::Base

      def index
        product_features = []
        if params[:product_features]
          params[:product_features].each do |product_feature|
            found = ProductFeature.where(product_features: {product_feature_type_id: product_feature['type_id'].to_i, product_feature_value_id: product_feature['value_id'].to_i}).first
            product_features << found if found
          end
        end

        feature_type_arr = ProductFeature.get_feature_types(product_features)
        render :json => {results: feature_type_arr}
      end

      def get_values
        if params[:product_feature_type_id].present?
          product_feature_type = ProductFeatureType.find(params[:product_feature_type_id])

          if params[:product_features].present?
            product_features = []
            product_feature_params = params[:product_features].to_a.flatten.delete_if { |o| !o.is_a? Hash }
            product_feature_params.each do |product_feature_hash|
              product_features << ProductFeature.where('product_feature_type_id = ? and product_feature_value_id = ?',
                                                       product_feature_hash['product_feature_type_id'],
                                                       product_feature_hash['product_feature_value_id']).first
            end

            value_ids = ProductFeature.get_values(product_feature_type, product_features)
          else
            value_ids = ProductFeature.get_values(product_feature_type)
          end

        else
          value_ids = []
        end

        render :json => {results: value_ids.map { |id| ProductFeatureValue.find(id) }}
      end

    end # ErpProducts
  end # Shared
end # ProductFeaturesController

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
erp_products-4.2.0 app/controllers/erp_products/shared/product_features_controller.rb