Module: Spree::Admin::StockLocationsControllerDecorator

Defined in:
app/controllers/spree/admin/stock_locations_controller_decorator.rb

Instance Method Summary collapse

Instance Method Details

#delhivery_pickupObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/spree/admin/stock_locations_controller_decorator.rb', line 4

def delhivery_pickup
  @stock_location = Spree::StockLocation.find(params[:id])
  
  # 1. Capture Params
  count = params[:count].to_i
  count = 1 if count <= 0
  
  date = params[:pickup_date] # Format: "YYYY-MM-DD" from HTML5 input
  time = params[:pickup_time] # Format: "HH:MM"
  
  # 2. Call Service
  # passing the named arguments your service expects
  service = SpreeDelhivery::PickupService.new(
    @stock_location, 
    date: date, 
    time: time, 
    count: count
  )
  
  result = service.call
  
  # 3. Handle Result
  if result.success?
    flash[:success] = result.message
  else
    flash[:error] = "Delhivery Error: #{result.message}"
  end
  
  redirect_to edit_admin_stock_location_path(@stock_location)
end