Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added condition for inheriting controller from frontend #27

Open
wants to merge 18 commits into
base: 2024
Choose a base branch
from

Conversation

mausamp
Copy link
Collaborator

@mausamp mausamp commented Jun 11, 2024

No description provided.

@@ -1,24 +1,26 @@
class Spree::ProductQuestionsController < Spree::Api::V2::ResourceController
before_action :load_data
if Spree::Core::Engine.frontend_available?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will run into issue while running into problem as it is expected that class name is defined according to name of controller..

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module Spree
  if Spree::Core::Engine.frontend_available?
    class ProductQuestionsController < StoreController
      before_action :load_data

      def create
        question = @product.product_questions.new(allowed_params)
        question.user_id = current_spree_user.id
        if question.save
          flash[:notice] = t('question.sent')
          redirect_to @product
        else
          flash[:error] = question.errors.full_messages.to_sentence
          redirect_to @product
        end
      end

      private

      def load_data
        @product = Spree::Product.find(allowed_params[:product_id])
      end

      def allowed_params
        params.require(:product_question).permit(:content, :product_id)
      end
    end
  else
    class ProductQuestionsController
      # Dummy class to satisfy Zeitwerk autoloading
    end
  end
end

@mausamp I think this kind of approach would be better so we dont violate zeitwerk autoloading as well..
let me know your thoughts, here we are defining dummy ProductQuestionsController when frontend is not available in the project

@mausamp mausamp changed the base branch from features/changes-in-model-and-api to 2024 July 4, 2024 09:19
@poudelprakash
Copy link

@mausamp please take care of merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants