Sha256: daeb148f7f63429d6c85513b8c10aefd5d11bd58bf3035f4d71ad1e8363a9e3d

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module Comee
  module Core
    class ProductsController < ApplicationController
      include Common

      def index
        super do
          Product.leafs
        end
      end

      def show
        super do
          Comee::Core::Product.with_attached_images.find(params[:id])
        end
      end

      def master_prices
        data = MasterPrice.includes(:product_lookup, :supplier, :product)
                          .where(product_id: price_params[:product_ids])
        render_content(data)
      end

      def client_prices
        data = ClientPrice.where(product_id: price_params[:product_ids])
        render_content(data)
      end

      def categories
        root = Product.find_by(code: "root")
        render_content(root.children)
      end

      def customers
        clients = ProductLookup.where(product_id: params[:id], itemable_type: "Comee::Core::Client")
                               .map(&:itemable)
        render_content(clients)
      end

      def filter
        data = Product.ransack(params[:q]).result
        render_content(data)
      end

      private

      def model_params
        params.required(:payload).permit(:code, :name, :description, :parent_id, :thumbnail_image, :source_id, :weight,
                                         :weight_unit_id, :dimensions, :hs_code, :hs_description, images: [],
                                                                                                  preferred_units: %i[id code label])
      end

      def price_params
        params.require(:payload).permit(product_ids: [])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comee_core-0.2.75 app/controllers/comee/core/products_controller.rb