app/controllers/spree/admin/adjustments_controller.rb in spree_backend-4.2.0.beta vs app/controllers/spree/admin/adjustments_controller.rb in spree_backend-4.2.0.rc1
- old
+ new
@@ -9,10 +9,12 @@
skip_before_action :load_resource, only: [:toggle_state, :edit, :update, :destroy]
before_action :find_adjustment, only: [:destroy, :edit, :update]
+ after_action :delete_promotion_from_order, only: [:destroy], if: -> { @adjustment.destroyed? && @adjustment.promotion? }
+
def index
@adjustments = @order.all_adjustments.eligible.order(created_at: :asc)
end
private
@@ -28,9 +30,15 @@
# Override method used to create a new instance to correctly
# associate adjustment with order
def build_resource
parent.adjustments.build(order: parent)
+ end
+
+ def delete_promotion_from_order
+ return if @adjustment.source.nil?
+
+ @order.promotions.delete(@adjustment.source.promotion)
end
end
end
end