fixes on addresses
This commit is contained in:
@@ -32,8 +32,13 @@ class LoginController extends Controller
|
|||||||
|
|
||||||
if ($this->guard()->attempt($credentials, $request->get('remember'))) {
|
if ($this->guard()->attempt($credentials, $request->get('remember'))) {
|
||||||
$request->session()->regenerate();
|
$request->session()->regenerate();
|
||||||
|
if (back()->getTargetUrl() === route('Shop.Orders.store')) {
|
||||||
|
$route = 'Shop.Orders.order';
|
||||||
|
} else {
|
||||||
|
$route = 'home';
|
||||||
|
}
|
||||||
|
|
||||||
return back()->getTargetUrl() === route('Shop.login') ? redirect()->intended(route('home')) : back();
|
return redirect()->intended(route($route));
|
||||||
}
|
}
|
||||||
|
|
||||||
return back()->withErrors([
|
return back()->withErrors([
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class RegisterController extends Controller
|
|||||||
|
|
||||||
public function register(RegisterCustomer $request)
|
public function register(RegisterCustomer $request)
|
||||||
{
|
{
|
||||||
$validatedData = $request->validateWithBag('Errors', [
|
$request->validateWithBag('Errors', [
|
||||||
'last_name' => 'required|max:255',
|
'last_name' => 'required|max:255',
|
||||||
'first_name' => 'required|max:255',
|
'first_name' => 'required|max:255',
|
||||||
'email' => 'required|email|max:255|unique:shop_customers,email,NULL,id,deleted_at,NULL',
|
'email' => 'required|email|max:255|unique:shop_customers,email,NULL,id,deleted_at,NULL',
|
||||||
@@ -32,20 +32,19 @@ class RegisterController extends Controller
|
|||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (back()->getTargetUrl() === route('Shop.Orders.store')) {
|
||||||
|
$route = 'Shop.Orders.order';
|
||||||
|
} else {
|
||||||
|
$route = 'home';
|
||||||
|
}
|
||||||
|
|
||||||
$user = $this->create($request->all());
|
$user = $this->create($request->all());
|
||||||
|
|
||||||
$this->guard()->login($user);
|
$this->guard()->login($user);
|
||||||
/*
|
|
||||||
$response = $this->registered($request, $user);
|
|
||||||
|
|
||||||
if ($response) {
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return $request->wantsJson()
|
return $request->wantsJson()
|
||||||
? new JsonResponse([], 201)
|
? new JsonResponse([], 201)
|
||||||
: redirect()->route('home');
|
: redirect()->route($route);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function emailVerify()
|
public function emailVerify()
|
||||||
|
|||||||
@@ -52,6 +52,6 @@ class CustomerController extends Controller
|
|||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
$customer = Customers::storeFull($data);
|
$customer = Customers::storeFull($data);
|
||||||
|
|
||||||
return response()->json(['error' => 0]);
|
return redirect()->route('Shop.Customers.edit');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,27 +12,35 @@ class CustomerAddresses
|
|||||||
public static function add($userId, $data)
|
public static function add($userId, $data)
|
||||||
{
|
{
|
||||||
$name = $data['company'] ? $data['company'] : $data['first_name'].' '.$data['last_name'];
|
$name = $data['company'] ? $data['company'] : $data['first_name'].' '.$data['last_name'];
|
||||||
if ($data['use_for_delivery'] ?? false) {
|
$delivery = $data['use_for_delivery'] ?? false;
|
||||||
return self::store([
|
|
||||||
'customer_id' => $userId,
|
|
||||||
'name' => $name,
|
|
||||||
'address' => $data['delivery_address'],
|
|
||||||
'address2' => $data['delivery_address2'],
|
|
||||||
'zipcode' => $data['delivery_zipcode'],
|
|
||||||
'city' => $data['delivery_city'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::store([
|
return self::store([
|
||||||
'customer_id' => $userId,
|
'customer_id' => $userId,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'address' => $data['address'],
|
'address' => $delivery ? $data['delivery_address'] : $data['address'],
|
||||||
'address2' => $data['address2'],
|
'address2' => $delivery ? $data['delivery_address2'] : $data['address2'],
|
||||||
'zipcode' => $data['zipcode'],
|
'zipcode' => $delivery ? $data['delivery_zipcode'] : $data['zipcode'],
|
||||||
'city' => $data['city'],
|
'city' => $delivery ? $data['delivery_city'] : $data['city'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function storeByCustomer($customer, $data)
|
||||||
|
{
|
||||||
|
$deliveries = $data['deliveries'] ?? false;
|
||||||
|
if ($deliveries && $deliveries['zipcode'] && $deliveries['city']) {
|
||||||
|
$deliveries['customer_id'] = $customer->id;
|
||||||
|
$deliveries['type'] = 1;
|
||||||
|
self::store($deliveries);
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoices = $data['invoices'] ?? false;
|
||||||
|
if ($invoices && $invoices['zipcode'] && $invoices['city']) {
|
||||||
|
$invoices['customer_id'] = $customer->id;
|
||||||
|
$invoices['type'] = 2;
|
||||||
|
self::store($invoices);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function toggleActive($id, $active)
|
public static function toggleActive($id, $active)
|
||||||
{
|
{
|
||||||
return self::update(['active' => $active], $id);
|
return self::update(['active' => $active], $id);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class Customers
|
|||||||
{
|
{
|
||||||
$customer = $id ? self::get($id) : self::getAuth();
|
$customer = $id ? self::get($id) : self::getAuth();
|
||||||
$file = self::makeAvatarFilename($customer);
|
$file = self::makeAvatarFilename($customer);
|
||||||
if (! File::checkFile($file)) {
|
if (!File::checkFile($file)) {
|
||||||
self::createAvatar($customer);
|
self::createAvatar($customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ class Customers
|
|||||||
public static function createAvatar($customer)
|
public static function createAvatar($customer)
|
||||||
{
|
{
|
||||||
$filename = self::makeAvatarFilename($customer);
|
$filename = self::makeAvatarFilename($customer);
|
||||||
$name = $customer->first_name.' '.$customer->last_name;
|
$name = $customer->first_name . ' ' . $customer->last_name;
|
||||||
$avatar = new Avatar();
|
$avatar = new Avatar();
|
||||||
|
|
||||||
return $avatar->create($name)
|
return $avatar->create($name)
|
||||||
@@ -97,7 +97,7 @@ class Customers
|
|||||||
{
|
{
|
||||||
$path = storage_path(self::getStorage());
|
$path = storage_path(self::getStorage());
|
||||||
if (File::checkDirOrCreate($path)) {
|
if (File::checkDirOrCreate($path)) {
|
||||||
$filename = $path.self::getAvatarFilename($customer);
|
$filename = $path . self::getAvatarFilename($customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $filename ?? false;
|
return $filename ?? false;
|
||||||
@@ -105,7 +105,7 @@ class Customers
|
|||||||
|
|
||||||
public static function getAvatarFilename($customer)
|
public static function getAvatarFilename($customer)
|
||||||
{
|
{
|
||||||
return 'user-'.$customer->uuid.'.png';
|
return 'user-' . $customer->uuid . '.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAddresses($id = false)
|
public static function getAddresses($id = false)
|
||||||
@@ -141,7 +141,7 @@ class Customers
|
|||||||
|
|
||||||
public static function isNotConnected()
|
public static function isNotConnected()
|
||||||
{
|
{
|
||||||
return ! self::isConnected();
|
return !self::isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isConnected()
|
public static function isConnected()
|
||||||
@@ -161,19 +161,26 @@ class Customers
|
|||||||
|
|
||||||
public static function storeFull($data)
|
public static function storeFull($data)
|
||||||
{
|
{
|
||||||
$saleChannels = $data['sale_channels'];
|
$data2 = $data;
|
||||||
|
if ($data['sale_channels'] ?? false) {
|
||||||
|
$saleChannels = $data['sale_channels'] ?? false;
|
||||||
unset($data['sale_channels']);
|
unset($data['sale_channels']);
|
||||||
$customer = self::store($data);
|
|
||||||
if ($customer) {
|
|
||||||
self::storeSaleChannels($customer->id, $saleChannels);
|
|
||||||
}
|
}
|
||||||
|
if ($data['deliveries'] ?? false) {
|
||||||
|
unset($data['deliveries']);
|
||||||
|
}
|
||||||
|
if ($data['invoices'] ?? false) {
|
||||||
|
unset($data['invoices']);
|
||||||
|
}
|
||||||
|
$customer = self::store($data);
|
||||||
|
CustomerAddresses::storeByCustomer($customer, $data2);
|
||||||
|
|
||||||
return $customer->id;
|
return $customer->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function storeDeliveries($customer, $deliveries)
|
public static function storeDeliveries($customer, $deliveries)
|
||||||
{
|
{
|
||||||
if (! $deliveries) {
|
if (!$deliveries) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$deliveries = collect($deliveries)->transform(function ($item) {
|
$deliveries = collect($deliveries)->transform(function ($item) {
|
||||||
@@ -220,14 +227,14 @@ class Customers
|
|||||||
{
|
{
|
||||||
$path = '/app/public/Customers/';
|
$path = '/app/public/Customers/';
|
||||||
|
|
||||||
return $filename ? $path.$filename : $path;
|
return $filename ? $path . $filename : $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPublic($filename = false)
|
public static function getPublic($filename = false)
|
||||||
{
|
{
|
||||||
$path = '/storage/Customers/';
|
$path = '/storage/Customers/';
|
||||||
|
|
||||||
return $filename ? $path.$filename : $path;
|
return $filename ? $path . $filename : $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function guard()
|
public static function guard()
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class OrderMails
|
|||||||
|
|
||||||
public static function sendOrderConfirmed($orderId)
|
public static function sendOrderConfirmed($orderId)
|
||||||
{
|
{
|
||||||
$order = Orders::get($orderId, ['customer', 'address']);
|
$order = Orders::get($orderId, ['customer', 'delivery_address']);
|
||||||
$mail = new ConfirmationCommande($order);
|
$mail = new ConfirmationCommande($order);
|
||||||
|
|
||||||
return Mail::to($order->customer->email)->send($mail);
|
return Mail::to($order->customer->email)->send($mail);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class Orders
|
|||||||
public static function saveOrder($data)
|
public static function saveOrder($data)
|
||||||
{
|
{
|
||||||
$basket = $data['basket'];
|
$basket = $data['basket'];
|
||||||
$invoice = $data['invoice'];
|
$invoice = $data['invoice'] ?? [];
|
||||||
unset($data['basket'], $data['invoice']);
|
unset($data['basket'], $data['invoice']);
|
||||||
$data += self::getSummaryOfBasket($basket);
|
$data += self::getSummaryOfBasket($basket);
|
||||||
$order = self::store($data);
|
$order = self::store($data);
|
||||||
|
|||||||
@@ -25,18 +25,15 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
$('.active-checkbox').bootstrapToggle();
|
$('.active-checkbox').bootstrapToggle();
|
||||||
$('.active-checkbox').off('change').on('change', function(e) {
|
$('.active-checkbox').off().change(function(e) {
|
||||||
var id = $('#id').val();
|
var id = $('#id').val();
|
||||||
// handleAdmin.toggle(id, $(this).prop('checked'));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
initChevron();
|
initChevron();
|
||||||
initEditor();
|
initEditor();
|
||||||
initSaveForm('#article-form');
|
initSaveForm('#article-form');
|
||||||
initSelect2();
|
initSelect2();
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
<a href="{{ route('Shop.Offers.show', ['id' => $offer['id']]) }}">
|
|
||||||
<div class="card">
|
|
||||||
<img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($offer['article']['image'] ?? false) }}" class="card-img-top" alt="...">
|
|
||||||
<div class="card-body">
|
|
||||||
<span class="card-title">{{ $offer['article']['name'] }}</span>
|
|
||||||
<span class="pull-right">
|
|
||||||
<i class="fa fa-heart"></i>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<p class="card-text">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-6">
|
|
||||||
3.50 €<br>
|
|
||||||
Semence
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-6">
|
|
||||||
1.65 €<br>
|
|
||||||
Plant
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
@include('Shop.Customers.partials.addresses', [
|
@include('Shop.Customers.partials.addresses', [
|
||||||
'prefix' => 'deliveries',
|
'prefix' => 'deliveries',
|
||||||
'addresses' => $customer['delivery_addresses'],
|
'addresses' => $customer['delivery_addresses'],
|
||||||
|
'with_name' => true,
|
||||||
])
|
])
|
||||||
</x-card>
|
</x-card>
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
@include('Shop.Customers.partials.addresses', [
|
@include('Shop.Customers.partials.addresses', [
|
||||||
'prefix' => 'invoices',
|
'prefix' => 'invoices',
|
||||||
'addresses' => $customer['invoice_addresses'],
|
'addresses' => $customer['invoice_addresses'],
|
||||||
|
'with_name' => true,
|
||||||
])
|
])
|
||||||
</x-card>
|
</x-card>
|
||||||
|
|
||||||
@@ -38,8 +40,8 @@
|
|||||||
</x-card>
|
</x-card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<x-save />
|
|
||||||
</form>
|
</form>
|
||||||
|
<x-save />
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@include('load.form.save')
|
@include('load.form.save')
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
@if ($with_name ?? false)
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
@include('components.form.input', [
|
||||||
|
'name' => $prefix ?? false ? $prefix . "['name']" : 'name',
|
||||||
|
'value' => $customer['name'] ?? '',
|
||||||
|
'label' => 'Nom',
|
||||||
|
])
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
@include('components.form.input', [
|
@include('components.form.input', [
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
val="{{ $address['id'] }}" id="address_{{ $address['id'] }}" />
|
val="{{ $address['id'] }}" id="address_{{ $address['id'] }}" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-11">
|
<div class="col-11">
|
||||||
|
@if ($with_name ?? false)
|
||||||
|
{{ $address['name'] }}<br />>
|
||||||
|
@endif
|
||||||
{{ $address['address'] }}<br />
|
{{ $address['address'] }}<br />
|
||||||
@if ($address['address2'])
|
@if ($address['address2'])
|
||||||
{{ $address['address2'] }}<br />
|
{{ $address['address2'] }}<br />
|
||||||
@@ -15,7 +18,7 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
<div id="add_address_container_{{ $prefix }}" class="green-dark d-none mb-3 mt-3">
|
<div id="add_address_container_{{ $prefix }}" class="green-dark d-none mb-3 mt-3">
|
||||||
<x-card classBody="bg-green-dark yellow" title="Nouvelle adresse">
|
<x-card classBody="bg-green-dark yellow" title="Nouvelle adresse" classTitle="h4">
|
||||||
@include('Shop.Customers.partials.address', [
|
@include('Shop.Customers.partials.address', [
|
||||||
'prefix' => $prefix,
|
'prefix' => $prefix,
|
||||||
'with_country' => false,
|
'with_country' => false,
|
||||||
@@ -29,7 +32,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 text-right">
|
<div class="col-12 text-right">
|
||||||
<x-form.button id="add_address_{{ $prefix }}" icon="fa-plus" txt="Ajouter une adresse"
|
<x-form.button id="add_address_{{ $prefix }}" icon="fa-plus" txt="Ajouter une adresse"
|
||||||
class="btn-warning btn-sm" />
|
class="btn-warning btn-sm mt-2" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
{!! $tools !!}
|
{!! $tools !!}
|
||||||
</div>
|
</div>
|
||||||
@endisset
|
@endisset
|
||||||
<h3 class="card-title {{ $classTitle ?? 'mb-0' }}">{{ $title ?? false }}</h3>
|
<p class="card-title {{ $classTitle ?? 'h3 mb-0' }}">{{ $title ?? false }}</p>
|
||||||
@endisset
|
@endisset
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
@@ -2,15 +2,25 @@
|
|||||||
@push('scripts')
|
@push('scripts')
|
||||||
<script>
|
<script>
|
||||||
function initSaveForm(form, sel) {
|
function initSaveForm(form, sel) {
|
||||||
|
console.log('ici');
|
||||||
|
if (typeof initValidator === 'function') {
|
||||||
initValidator();
|
initValidator();
|
||||||
|
}
|
||||||
var form = (typeof(form) == 'undefined') ? '#form' : form;
|
var form = (typeof(form) == 'undefined') ? '#form' : form;
|
||||||
var selector = (typeof(sel) == 'undefined') ? '.save' : sel;
|
var selector = (typeof(sel) == 'undefined') ? '.save' : sel;
|
||||||
$(selector).off().click(function(e) {
|
$(selector).off().click(function(e) {
|
||||||
|
if (typeof initValidator === 'function') {
|
||||||
|
console.log('click');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if ($(form).valid()) {
|
if ($(form).valid()) {
|
||||||
$(this).prop("disabled", true);
|
$(this).prop("disabled", true);
|
||||||
$(this).html($(this).data('loading-text'));
|
$(this).html($(this).data('loading-text'));
|
||||||
$(form).submit();
|
$(form).submit();
|
||||||
|
} else {
|
||||||
|
console.log('erreur');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$(form).submit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user