Fixes for ordering

This commit is contained in:
Deon George 2021-07-09 11:39:27 +10:00
parent 24ff62094a
commit a9f81373fa
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
5 changed files with 255 additions and 251 deletions

View File

@ -40,9 +40,7 @@ class OrderController extends Controller
public function submit(Request $request) public function submit(Request $request)
{ {
Validator::make($request->all(),[ Validator::make($request->all(),['product_id'=>'required|exists:ab_product,id'])
'product_id'=>'required|exists:ab_product,id',
])
// Reseller // Reseller
->sometimes('account_id','required|email',function($input) use ($request) { ->sometimes('account_id','required|email',function($input) use ($request) {
return is_null($input->account_id) AND is_null($input->order_email_manual); return is_null($input->account_id) AND is_null($input->order_email_manual);
@ -63,15 +61,13 @@ 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);
if ($request->input('order_email_manual')) if ($request->input('order_email_manual')) {
{
$uo = User::firstOrNew(['email'=>$request->input('order_email_manual')]); $uo = User::firstOrNew(['email'=>$request->input('order_email_manual')]);
// If this is a new client // If this is a new client
if (! $uo->exists) if (! $uo->exists) {
{
// @todo Make this automatic // @todo Make this automatic
$uo->site_id = config('SITE')->id; $uo->site_id = config('SITE')->site_id;
$uo->active = FALSE; $uo->active = FALSE;
$uo->firstname = ''; $uo->firstname = '';
$uo->lastname = ''; $uo->lastname = '';
@ -83,12 +79,11 @@ class OrderController extends Controller
} }
// If we have a new account. // If we have a new account.
if (is_null($request->input('account_id'))) if (is_null($request->input('account_id'))) {
{
$ao = new Account; $ao = new Account;
//$ao->id = Account::NextId(); //$ao->id = Account::NextId();
// @todo Make this automatic // @todo Make this automatic
$ao->site_id = config('SITE')->id; $ao->site_id = config('SITE')->site_id;
$ao->country_id = config('SITE')->country_id; // @todo This might be wrong $ao->country_id = config('SITE')->country_id; // @todo This might be wrong
$ao->language_id = config('SITE')->language_id; // @todo This might be wrong $ao->language_id = config('SITE')->language_id; // @todo This might be wrong
$ao->currency_id = config('SITE')->currency_id; // @todo This might be wrong $ao->currency_id = config('SITE')->currency_id; // @todo This might be wrong
@ -102,15 +97,15 @@ class OrderController extends Controller
$so = new Service; $so = new Service;
// @todo Make this automatic // @todo Make this automatic
$so->site_id = config('SITE')->id; $so->site_id = config('SITE')->site_id;
$so->product_id = $request->input('product_id'); $so->product_id = $request->input('product_id');
$so->order_status = 'ORDER-SUBMIT'; $so->order_status = 'ORDER-SUBMIT';
$so->orderby_id = Auth::id(); $so->orderby_id = Auth::id();
$so->model = get_class($options); $so->model = get_class($options);
if ($options->order_info) if ($options->order_info) {
{
$so->order_info = $options->order_info; $so->order_info = $options->order_info;
unset($options->order_info); unset($options->order_info);
} }

View File

@ -43,7 +43,7 @@ trait OrderServiceOptions
$o->forceFill(array_undot($x)); $o->forceFill(array_undot($x));
// @todo Make this automatic // @todo Make this automatic
$o->site_id = config('SITE')->id; $o->site_id = config('SITE')->site_id;
return $o; return $o;
} }

View File

@ -1,263 +1,267 @@
@extends('layouts.app') @extends('metronic::layouts.app')
@section('htmlheader_title') @section('htmlheader_title')
{{ trans('message.home') }} Order Service
@endsection @endsection
@section('main-content') @section('main-content')
<div class="col-md-12"> <div class="main">
<h1>Order Service</h1> <div class="container">
<div class="col-12">
<h1>Order Service</h1>
<div class="order-page" id="order-page"> <div class="order-page" id="order-page">
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-3">
<ul class="tabbable faq-tabbable"> <ul class="tabbable faq-tabbable">
<li class="active"> <li class="active">
<a href="#order_1" data-toggle="tab" aria-expanded="true">Order Service</a> <a href="#order_1" data-toggle="tab" aria-expanded="true">Order Service</a>
</li> </li>
</ul> </ul>
</div> </div>
<div class="col-md-9"> <div class="col-9">
<div class="tab-content" style="padding:0; background: #fff;"> <div class="tab-content" style="padding:0; background: #fff;">
<div class="tab-pane active" id="order_1"> <div class="tab-pane active" id="order_1">
<div class="panel-group" id="accordion1"> <div class="panel-group" id="accordion1">
<form role="form" method="POST" enctype="multipart/form-data"> <form role="form" method="POST" enctype="multipart/form-data">
{{ csrf_field() }} {{ csrf_field() }}
<div id="accordion"> <div id="accordion">
<!-- Reseller Choose Client --> <!-- Reseller Choose Client -->
@if (Auth::user() AND Auth::user()->isReseller()) @if (Auth::user() AND Auth::user()->isReseller())
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h4 class="panel-title"> <h4 class="panel-title">
Account Account
</h4> </h4>
</div> </div>
<div class="panel-collapse"> <div class="panel-collapse">
<div class="panel-body"> <div class="panel-body">
<div class="col-md-12 margin-bottom-20"> <div class="col-12 margin-bottom-20">
<div class="col-md-6"> <div class="col-6">
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li class="active"> <li class="active">
<a href="#account_exist" data-toggle="tab">Existing Account</a> <a href="#account_exist" data-toggle="tab">Existing Account</a>
</li> </li>
<li> <li>
<a href="#client_new" data-toggle="tab">New Client</a> <a href="#client_new" data-toggle="tab">New Client</a>
</li> </li>
</ul> </ul>
<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="account_id">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="">&nbsp;</option> <option value="">&nbsp;</option>
@foreach ($user->all_accounts()->sortBy('name') as $o) @foreach ($user->all_accounts()->sortBy('name') as $o)
<option value="{{ $o->id }}" @if($o->id == old('account_id')) selected @endif>{{ $o->name }}</option> <option value="{{ $o->id }}" @if($o->id == old('account_id')) selected @endif>{{ $o->name }}</option>
@endforeach @endforeach
</select> </select>
<span class="help-block">{{ $errors->first('account_id') }}</span> <span class="help-block">{{ $errors->first('account_id') }}</span>
</div>
</div>
<div class="tab-pane row fade" id="client_new">
<div class="control-group form-group col-sm-12 {{ $errors->has('order_email_manual') ? 'has-error' : '' }}">
<label for="order_email_manual">New Client Email</label>
<input type="email" class="form-control" id="order_email_manual" name="order_email_manual" placeholder="New Client Email" value="{{ old('order_email_manual') }}">
<span class="help-block">{{ $errors->first('order_email_manual') }}</span>
</div>
</div>
</div> </div>
</div> </div>
</div>
<div class="tab-pane row fade" id="client_new"> <div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div>
</div>
</div>
</div>
</div>
<!-- Non-Authed User -->
@elseif (Auth::user())
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
Account
</h4>
</div>
<div class="panel-collapse">
<div class="panel-body">
<div class="col-12 margin-bottom-20">
<div class="col-6">
<ul class="nav nav-tabs">
<li class="active">
<a href="#account_exist" data-toggle="tab">Existing Account</a>
</li>
<li>
<a href="#account_new" data-toggle="tab">New Account</a>
</li>
</ul>
<div class="tab-content">
<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' : '' }}">
<label for="account_id">Existing Account</label>
<select class="form-control" id="account_id" name="account_id">
<option value="">&nbsp;</option>
@foreach ($user->accounts->sortBy('name') as $o)
<option value="{{ $o->id }}" @if($o->id == old('account_id')) selected @endif>{{ $o->name }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('account_id') }}</span>
</div>
</div>
<div class="tab-pane row fade" id="account_new">
<div class="control-group form-group col-sm-12 {{ $errors->has('account_name') ? 'has-error' : '' }}">
<label for="account_name">Account Name</label>
<input type="text" class="form-control" id="account_name" name="account_name" placeholder="New Account Name" value="{{ old('order_email_manual') }}" disabled>
<span class="help-block">{{ $errors->first('account_name') }}</span>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div>
</div>
</div>
</div>
</div>
<!-- Non-Authed User -->
@else
@php
//dd($errors);
@endphp
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
Account
</h4>
</div>
<div class="panel-collapse">
<div class="panel-body">
<div class="col-12">
<div class="row col-6">
<div class="control-group form-group col-sm-12 {{ $errors->has('order_email_manual') ? 'has-error' : '' }}"> <div class="control-group form-group col-sm-12 {{ $errors->has('order_email_manual') ? 'has-error' : '' }}">
<label for="order_email_manual">New Client Email</label> <label for="order_email_manual">Email Address</label>
<input type="email" class="form-control" id="order_email_manual" name="order_email_manual" placeholder="New Client Email" value="{{ old('order_email_manual') }}"> <input type="email" class="form-control" id="order_email_manual" name="order_email_manual" placeholder="Email Address" value="{{ old('order_email_manual') }}">
<span class="help-block">{{ $errors->first('order_email_manual') }}</span> <span class="help-block">{{ $errors->first('order_email_manual') }}</span>
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div> <div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div> <div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div>
</div>
</div>
</div>
</div>
<!-- Non-Authed User -->
@elseif (Auth::user())
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
Account
</h4>
</div>
<div class="panel-collapse">
<div class="panel-body">
<div class="col-md-12 margin-bottom-20">
<div class="col-md-6">
<ul class="nav nav-tabs">
<li class="active">
<a href="#account_exist" data-toggle="tab">Existing Account</a>
</li>
<li>
<a href="#account_new" data-toggle="tab">New Account</a>
</li>
</ul>
<div class="tab-content">
<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' : '' }}">
<label for="account_id">Existing Account</label>
<select class="form-control" id="account_id" name="account_id">
<option value="">&nbsp;</option>
@foreach ($user->accounts->sortBy('name') as $o)
<option value="{{ $o->id }}" @if($o->id == old('account_id')) selected @endif>{{ $o->name }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('account_id') }}</span>
</div>
</div>
<div class="tab-pane row fade" id="account_new">
<div class="control-group form-group col-sm-12 {{ $errors->has('account_name') ? 'has-error' : '' }}">
<label for="account_name">Account Name</label>
<input type="text" class="form-control" id="account_name" name="account_name" placeholder="New Account Name" value="{{ old('order_email_manual') }}" disabled>
<span class="help-block">{{ $errors->first('account_name') }}</span>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div>
</div>
</div> </div>
</div> @endif
</div>
<!-- Non-Authed User --> <!-- Product -->
@else <div class="panel panel-default">
@php <div class="panel-heading">
//dd($errors); <h4 class="panel-title">Product</h4>
@endphp </div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
Account
</h4>
</div>
<div class="panel-collapse"> <div class="panel-collapse margin-bottom-20">
<div class="panel-body"> <div class="panel-body">
<div class="col-md-12"> <div class="col-12">
<div class="row col-md-6"> <div class="control-group form-group col-sm-12 {{ $errors->has('product_options') ? 'has-error' : '' }}">
<div class="control-group form-group col-sm-12 {{ $errors->has('order_email_manual') ? 'has-error' : '' }}"> <span class="help-block">{{ $errors->first('product_options') }}</span>
<label for="order_email_manual">Email Address</label> </div>
<input type="email" class="form-control" id="order_email_manual" name="order_email_manual" placeholder="Email Address" value="{{ old('order_email_manual') }}">
<span class="help-block">{{ $errors->first('order_email_manual') }}</span> <div class="control-group form-group col-sm-6 {{ $errors->has('product_id') ? 'has-error' : '' }}">
<label for="product_id">Product</label>
<select class="form-control" id="product_id" name="product_id">
<option value="">&nbsp;</option>
@php
$po = $selected = NULL;
@endphp
@foreach (\App\Models\Product::active()->get()->sortBy('name') as $o)
@php
if ($o->id == old('product_id'))
{
$selected = 'selected';
$po = $o;
} else {
$selected = NULL;
}
@endphp
<option value="{{ $o->id }}" {{ $selected }}>{{ $o->name }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('product_id') }}</span>
</div>
<div class="col-sm-6" id="product_info">
@if (old('product_id'))
@include('widgets.product_description',['o'=>$po])
@endif
</div> </div>
</div> </div>
</div>
<div class="row"> <div class="col-12" id="product_order">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div> @if (old('product_id'))
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div> @include('widgets.product_order',['o'=>$po])
@endif
</div>
<div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div>
</div>
</div> </div>
</div> </div>
</div>
<!-- Additional Notes -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Notes</h4>
</div>
<div class="panel-collapse margin-bottom-20">
<div class="panel-body">
<div class="col-12">
<div class="control-group form-group col-sm-12 {{ $errors->has('options.notes') ? 'has-error' : '' }}">
<label for="options.notes">Notes</label>
<textarea name="options[notes]" class="form-control" rows="4" placeholder="Enter any special instructions...">{{ old('options.notes') }}</textarea>
<span class="help-block">{{ $errors->first('options.notes') }}</span>
</div>
</div>
<div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2 pull-right"><input type="submit" class="btn btn-block btn-primary" value="Submit Order"></div>
</div>
</div>
</div>
</div> </div>
</div> </div>
@endif </form>
<!-- Product -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Product</h4>
</div>
<div class="panel-collapse margin-bottom-20">
<div class="panel-body">
<div class="col-md-12">
<div class="control-group form-group col-sm-12 {{ $errors->has('product_options') ? 'has-error' : '' }}">
<span class="help-block">{{ $errors->first('product_options') }}</span>
</div>
<div class="control-group form-group col-sm-6 {{ $errors->has('product_id') ? 'has-error' : '' }}">
<label for="product_id">Product</label>
<select class="form-control" id="product_id" name="product_id">
<option value="">&nbsp;</option>
@php
$po = $selected = NULL;
@endphp
@foreach (\App\Models\Product::active()->get()->sortBy('name') as $o)
@php
if ($o->id == old('product_id'))
{
$selected = 'selected';
$po = $o;
} else {
$selected = NULL;
}
@endphp
<option value="{{ $o->id }}" {{ $selected }}>{{ $o->name }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('product_id') }}</span>
</div>
<div class="col-sm-6" id="product_info">
@if (old('product_id'))
@include('widgets.product_description',['o'=>$po])
@endif
</div>
</div>
<div class="col-md-12" id="product_order">
@if (old('product_id'))
@include('widgets.product_order',['o'=>$po])
@endif
</div>
<div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div>
</div>
</div>
</div>
</div>
<!-- Additional Notes -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Notes</h4>
</div>
<div class="panel-collapse margin-bottom-20">
<div class="panel-body">
<div class="col-md-12">
<div class="control-group form-group col-sm-12 {{ $errors->has('options.notes') ? 'has-error' : '' }}">
<label for="options.notes">Notes</label>
<textarea name="options[notes]" class="form-control" rows="4" placeholder="Enter any special instructions...">{{ old('options.notes') }}</textarea>
<span class="help-block">{{ $errors->first('options.notes') }}</span>
</div>
</div>
<div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2 pull-right"><input type="submit" class="btn btn-block btn-primary" value="Submit Order"></div>
</div>
</div>
</div>
</div>
</div> </div>
</form> </div>
</div>
</div>
<div class="tab-pane" id="tab-2"> <div class="tab-pane" id="tab-2">
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -267,8 +271,8 @@
@endsection @endsection
@section('page-scripts') @section('page-scripts')
@js('/plugin/jqBootstrapValidation/jqBootstrapValidation.js','jq-validation','jquery') @js('plugin/jqBootstrapValidation/jqBootstrapValidation.js','jq-validation','jquery')
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script> @js('//code.jquery.com/ui/1.12.1/jquery-ui.js','jquery-ui-js','jqery')
<script> <script>
$(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation(); } ); $(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation(); } );

View File

@ -1,12 +1,16 @@
@extends('layouts.app') @extends('metronic::layouts.app')
@section('htmlheader_title') @section('htmlheader_title')
{{ trans('message.home') }} Order Received
@endsection @endsection
@section('main-content') @section('main-content')
<div class="col-md-12"> <div class="main">
<h2>Order Service</h2> <div class="container">
<p>Your order has been received - #{{ $o->id }}. An email will be sent to you with as your order progresses.</p> <div class="col-12">
<h2>Order Service</h2>
<p>Your order has been received - #{{ $o->id }}. An email will be sent to you with as your order progresses.</p>
</div>
</div>
</div> </div>
@endsection @endsection

View File

@ -5,6 +5,7 @@ use App\Http\Controllers\{AdminController,
CheckoutController, CheckoutController,
HomeController, HomeController,
MediaController, MediaController,
OrderController,
PaypalController, PaypalController,
SearchController, SearchController,
WelcomeController}; WelcomeController};
@ -98,12 +99,12 @@ Route::group(['middleware'=>['theme:adminlte-be'],'prefix'=>'u'],function() {
// Frontend Routes (Non-Authed Users) // Frontend Routes (Non-Authed Users)
Route::group(['middleware'=>['theme:metronic-fe']],function() { Route::group(['middleware'=>['theme:metronic-fe']],function() {
Route::get('/',[WelcomeController::class,'home']); Route::get('/',[WelcomeController::class,'home']);
Route::get('order','OrderController@index'); Route::get('order',[OrderController::class,'index']);
Route::post('order','OrderController@submit'); Route::post('order',[OrderController::class,'submit']);
}); });
Route::get('product_order/{o}','OrderController@product_order'); Route::get('product_order/{o}',[OrderController::class,'product_order']);
Route::get('product_info/{o}','OrderController@product_info'); Route::get('product_info/{o}',[OrderController::class,'product_info']);
Route::redirect('home','u/home'); Route::redirect('home','u/home');
Route::get('search',[SearchController::class,'search']); Route::get('search',[SearchController::class,'search']);