Fix to order when auth user ordered for existing account
This commit is contained in:
parent
8d9b0c7027
commit
90bcb7f5f1
@ -58,20 +58,23 @@ class OrderController extends Controller
|
|||||||
// Check we have the custom attributes for the product
|
// Check we have the custom attributes for the product
|
||||||
$options = $po->orderValidation($request);
|
$options = $po->orderValidation($request);
|
||||||
|
|
||||||
$uo = User::firstOrNew(['email'=>$request->input('order_email') ?: $request->input('order_email_manual')]);
|
if ($request->input('order_email_manual'))
|
||||||
|
|
||||||
// If this is a new client
|
|
||||||
if (! $uo->exists)
|
|
||||||
{
|
{
|
||||||
// @todo Make this automatic
|
$uo = User::firstOrNew(['email'=>$request->input('order_email_manual')]);
|
||||||
$uo->site_id = config('SITE_SETUP')->id;
|
|
||||||
$uo->active = FALSE;
|
// If this is a new client
|
||||||
$uo->firstname = '';
|
if (! $uo->exists)
|
||||||
$uo->lastname = '';
|
{
|
||||||
$uo->country_id = config('SITE_SETUP')->country_id; // @todo This might be wrong
|
// @todo Make this automatic
|
||||||
$uo->parent_id = Auth::id() ?: 1; // @todo This should be configured to a default user
|
$uo->site_id = config('SITE_SETUP')->id;
|
||||||
$uo->active = 1;
|
$uo->active = FALSE;
|
||||||
$uo->save();
|
$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 we have a new account.
|
||||||
@ -88,10 +91,7 @@ class OrderController extends Controller
|
|||||||
$uo->accounts()->save($ao);
|
$uo->accounts()->save($ao);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// @todo This logic may be wrong, if account_id is not set, it'll pick the first account, which may be wrong.
|
$ao = Account::findOrFail($request->input('account_id'));
|
||||||
$ao = $request->input('account_id')
|
|
||||||
? $uo->accounts->where('account_id',$request->input('account_id'))
|
|
||||||
: $uo->accounts->first();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$so = new Service;
|
$so = new Service;
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane row fade in active" id="account_exist">
|
<div class="tab-pane row fade in active" id="account_exist">
|
||||||
<div class="control-group form-group col-sm-12 {{ $errors->has('account_id') ? 'has-error' : '' }}">
|
<div class="control-group form-group col-sm-12 {{ $errors->has('account_id') ? 'has-error' : '' }}">
|
||||||
<label for="order_email">Client Account</label>
|
<label for="account_id">Client Account</label>
|
||||||
<select class="form-control" id="account_id" name="account_id">
|
<select class="form-control" id="account_id" name="account_id">
|
||||||
<option value=""> </option>
|
<option value=""> </option>
|
||||||
@foreach ($user->all_accounts()->sortBy('company') as $o)
|
@foreach ($user->all_accounts()->sortBy('company') as $o)
|
||||||
@ -108,7 +108,7 @@
|
|||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane row fade in active" id="account_exist">
|
<div class="tab-pane row fade in active" id="account_exist">
|
||||||
<div class="control-group form-group col-sm-12 {{ $errors->has('account_id') ? 'has-error' : '' }}">
|
<div class="control-group form-group col-sm-12 {{ $errors->has('account_id') ? 'has-error' : '' }}">
|
||||||
<label for="order_email">Existing Account</label>
|
<label for="account_id">Existing Account</label>
|
||||||
<select class="form-control" id="account_id" name="account_id">
|
<select class="form-control" id="account_id" name="account_id">
|
||||||
<option value=""> </option>
|
<option value=""> </option>
|
||||||
@foreach ($user->accounts->sortBy('company') as $o)
|
@foreach ($user->accounts->sortBy('company') as $o)
|
||||||
@ -185,7 +185,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="control-group form-group col-sm-6 {{ $errors->has('product_id') ? 'has-error' : '' }}">
|
<div class="control-group form-group col-sm-6 {{ $errors->has('product_id') ? 'has-error' : '' }}">
|
||||||
<label for="order_email">Product</label>
|
<label for="product_id">Product</label>
|
||||||
<select class="form-control" id="product_id" name="product_id">
|
<select class="form-control" id="product_id" name="product_id">
|
||||||
<option value=""> </option>
|
<option value=""> </option>
|
||||||
@php
|
@php
|
||||||
|
Loading…
Reference in New Issue
Block a user