Class: Spree::Admin::RelationsController
- Inherits:
-
ResourceController
- Object
- ResourceController
- Spree::Admin::RelationsController
- Defined in:
- app/controllers/spree/admin/relations_controller.rb
Overview
This controller manages the creation, updating, and deletion of product relations in the Spree e-commerce platform. It handles actions such as creating new relations, updating discount amounts, updating positions, and destroying relations.
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/spree/admin/relations_controller.rb', line 14 def create @relation = Relation.new(relation_params) @relation.relatable = @product @relation. = Spree::Variant.find(relation_params[:related_to_id]).product if @relation.save flash[:success] = else flash[:error] = @relation.errors..to_sentence end redirect_to((@relation.relatable)) end |
#update ⇒ Object
28 29 30 31 32 |
# File 'app/controllers/spree/admin/relations_controller.rb', line 28 def update @relation.update_attribute :discount_amount, relation_params[:discount_amount] || 0 flash[:success] = redirect_to((@relation.relatable)) end |
#update_positions ⇒ Object
34 35 36 37 |
# File 'app/controllers/spree/admin/relations_controller.rb', line 34 def update_positions @relation.insert_at(relation_params[:position].to_i) render json: { status: :ok } end |