Class: Spree::Admin::PrivateSalesController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/private_sales_controller.rb

Overview

Managing private sales: which products, sold to whom, until when — and, on edit, how much of each variant to withhold.

New is deliberately thin: name, dates and three remote-search pickers, so opening it costs one query for roles and nothing else. Creating redirects straight to edit, which is where the allotment is actually set up now that the products are known.

Instance Method Summary collapse

Instance Method Details

#indexObject

GET /admin/private_sales



17
18
19
20
21
22
23
# File 'app/controllers/spree/admin/private_sales_controller.rb', line 17

def index
  # Off `collection`, which ResourceController already scoped with accessible_by(current_ability)
  # — going through model_class directly would discard that.
  @private_sales = collection.order(created_at: :desc).page(params[:page]).per(25)

  load_audience_names
end

#revokeObject

PATCH /admin/private_sales/:id/revoke

The point of storing the rule rather than signing it into the URL: one sale dies without touching the lock, so every other sale drawing on the same stock keeps working.



29
30
31
32
33
34
35
# File 'app/controllers/spree/admin/private_sales_controller.rb', line 29

def revoke
  # @private_sale is already loaded and authorized by ResourceController#load_resource.
  @private_sale.revoked!

  flash[:success] = t('.revoked')
  redirect_to admin_private_sales_path
end