83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Igaster\LaravelTheme\Facades\Theme;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use App\Models\{Product,Service};
|
|
use App\User;
|
|
|
|
class OrderController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return view('order');
|
|
}
|
|
|
|
public function product_order(Product $o)
|
|
{
|
|
Theme::set('metronic-fe');
|
|
|
|
return view('widgets.product_order',['o'=>$o]);
|
|
}
|
|
|
|
public function product_info(Product $o)
|
|
{
|
|
Theme::set('metronic-fe');
|
|
|
|
return view('widgets.product_description',['o'=>$o]);
|
|
}
|
|
|
|
public function submit(Request $request)
|
|
{
|
|
Validator::make($request->all(),[
|
|
'product_id'=>'required|exists:ab_product,id',
|
|
])
|
|
->sometimes('order_email','required|email',function($input) use ($request) {
|
|
return ($input->order_email AND ! $input->order_email_manual) OR (! $input->order_email_manual);
|
|
})
|
|
->sometimes('order_email_manual','required|email',function($input) use ($request) {
|
|
return $input->order_email_manual AND ! $input->order_email;
|
|
})->validate();
|
|
|
|
// Check the plugin details.
|
|
$po = Product::findOrFail($request->post('product_id'));
|
|
|
|
// Check we have the custom attributes for the product
|
|
$options = $po->orderValidation($request);
|
|
|
|
$uo = User::where('email','=',$request->post('order_email') ?: $request->post('order_email_manual'))->firstOrFail();
|
|
|
|
$ao = $request->input('account_id')
|
|
? $uo->accounts->where('account_id',$request->input('account_id'))
|
|
: $uo->accounts->first();
|
|
|
|
$so = new Service;
|
|
$so->id = Service::NextId();
|
|
|
|
// @todo Make this automatic
|
|
$so->site_id = config('SITE_SETUP')->id;
|
|
$so->product_id = $request->post('product_id');
|
|
$so->order_status = 'ORDER-SUBMIT';
|
|
$so->orderby_id = Auth::user()->id;
|
|
|
|
if ($options->order_info)
|
|
{
|
|
$so->order_info = $options->order_info;
|
|
unset($options->order_info);
|
|
}
|
|
|
|
$so = $ao->services()->save($so);
|
|
|
|
if ($options instanceOf Model) {
|
|
$options->service_id = $so->id;
|
|
$options->save();
|
|
}
|
|
|
|
return view('order_received',['o'=>$so]);
|
|
}
|
|
} |