|
|
|
@@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
use App\Models\{Product,Service};
|
|
|
|
|
use App\Models\{Account,Product,Service};
|
|
|
|
|
use App\User;
|
|
|
|
|
|
|
|
|
|
class OrderController extends Controller
|
|
|
|
@@ -37,33 +37,70 @@ class OrderController extends Controller
|
|
|
|
|
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);
|
|
|
|
|
// Reseller
|
|
|
|
|
->sometimes('account_id','required|email',function($input) use ($request) {
|
|
|
|
|
return is_null($input->account_id) AND is_null($input->order_email_manual);
|
|
|
|
|
})
|
|
|
|
|
->sometimes('order_email_manual','required|email',function($input) use ($request) {
|
|
|
|
|
return $input->order_email_manual AND ! $input->order_email;
|
|
|
|
|
})->validate();
|
|
|
|
|
// Un-Authed User
|
|
|
|
|
->sometimes('order_email_manual','required|email|unique:users,email,NULL,id',function($input) use ($request) {
|
|
|
|
|
return (is_null($input->order_email_manual) AND ! isset($input->account_id)) OR $input->order_email_manual;
|
|
|
|
|
})
|
|
|
|
|
// Authed User
|
|
|
|
|
->sometimes('account_id','required|email',function($input) use ($request) {
|
|
|
|
|
return is_null($input->account_id) AND ! isset($input->order_email_manual);
|
|
|
|
|
})
|
|
|
|
|
->validate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check the plugin details.
|
|
|
|
|
$po = Product::findOrFail($request->post('product_id'));
|
|
|
|
|
$po = Product::findOrFail($request->input('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();
|
|
|
|
|
$uo = User::firstOrNew(['email'=>$request->input('order_email') ?: $request->input('order_email_manual')]);
|
|
|
|
|
|
|
|
|
|
$ao = $request->input('account_id')
|
|
|
|
|
? $uo->accounts->where('account_id',$request->input('account_id'))
|
|
|
|
|
: $uo->accounts->first();
|
|
|
|
|
// If this is a new client
|
|
|
|
|
if (! $uo->exists)
|
|
|
|
|
{
|
|
|
|
|
// @todo Make this automatic
|
|
|
|
|
$uo->site_id = config('SITE_SETUP')->id;
|
|
|
|
|
$uo->active = FALSE;
|
|
|
|
|
$uo->firstname = '';
|
|
|
|
|
$uo->lastname = '';
|
|
|
|
|
$uo->country_id = config('SITE_SETUP')->country_id; // @todo This might be wrong
|
|
|
|
|
$uo->parent_id = Auth::id() ?: 1; // @todo This should be configured to a default user
|
|
|
|
|
$uo->active = 1;
|
|
|
|
|
$uo->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we have a new account.
|
|
|
|
|
if (is_null($request->input('account_id')))
|
|
|
|
|
{
|
|
|
|
|
$ao = new Account;
|
|
|
|
|
//$ao->id = Account::NextId();
|
|
|
|
|
// @todo Make this automatic
|
|
|
|
|
$ao->site_id = config('SITE_SETUP')->id;
|
|
|
|
|
$ao->country_id = config('SITE_SETUP')->country_id; // @todo This might be wrong
|
|
|
|
|
$ao->language_id = config('SITE_SETUP')->language_id; // @todo This might be wrong
|
|
|
|
|
$ao->currency_id = config('SITE_SETUP')->currency_id; // @todo This might be wrong
|
|
|
|
|
$ao->active = 1;
|
|
|
|
|
$uo->accounts()->save($ao);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// @todo This logic may be wrong, if account_id is not set, it'll pick the first account, which may be wrong.
|
|
|
|
|
$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->product_id = $request->input('product_id');
|
|
|
|
|
$so->order_status = 'ORDER-SUBMIT';
|
|
|
|
|
$so->orderby_id = Auth::user()->id;
|
|
|
|
|
$so->orderby_id = Auth::id();
|
|
|
|
|
|
|
|
|
|
if ($options->order_info)
|
|
|
|
|
{
|
|
|
|
|