use Cubist\Backpack\app\Http\Controllers\CubistFrontController;
use Cubist\Backpack\app\Magic\PageData;
use Cubist\Backpack\app\Magic\Search;
+//use Cubist\Util\ObjectUtil;
use Illuminate\Validation\ValidationException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
];
$data = $this->validation_form($request, $validation);
- $data['status'] = 0;
- $data['password'] = Hash::make($data['password']);
if (!strstr($data['vat'], $data['siren']) || substr($data['vat'], '-9') !== $data['siren']) {
throw ValidationException::withMessages(['siren' => __('Le numero de siren est incorrect')]);
}
+ /**
+ *
+ * The following block of code format address data with good format of database [{'...','...'}]
+ * to make it same in the database, readable and editable later in front
+ *
+ */
+ $address = '[';
+ $counter = 0;
+ foreach ($data['address'] as $key => $value) {
+ $counter++;
+ $address .= json_encode($data['address'][$key]);
+ if($counter !== sizeof($data['address'])){
+ $address .= ',';
+ }
+ }
+ $address .= ']';
+ /**
+ * End of block
+ */
+
+ $data['address'] = $address;
+ $data['status'] = 0;
+ $data['password'] = Hash::make($data['password']);
+
$client = new Client($data);
$client->save();
$address = Auth::guard('web-clients')->user()->address;
$addressToArray = json_decode($address);
+
unset($addressToArray[$index]);
$addressToString = json_encode($addressToArray);
+
$email = Auth::guard('web-clients')->user()->email;
$client = Client::where('email', $email)->update(['address' => $addressToString]);
+
+ return $addressToString;
}
public function getuser() {
$user = Auth::guard('web-clients')->user();
if($user) {
- $addressToArray = json_decode($user->address);
+ $addressToArray = json_decode($user->address, true);
$checkBillingAddress = array_filter($addressToArray, function ($n) {
- return $n->billing_address;
+ return $n['billing_address'];
});
$checkDeliveryAddress = array_filter($addressToArray, function ($n) {
- return $n->delivery_address;
+ return $n['delivery_address'];
});
$data = [
'type' => 'Text'
]);
+ $this->addField([
+ 'name' => 'company',
+ 'label' => "Société",
+ 'type' => 'Text'
+ ]);
+
$this->addField([
'name' => 'address',
'label' => "Adresse",
* building robust, powerful web applications using Vue and Laravel.
*/
-import {forEach} from "../../public/vendor/adminlte/bower_components/mocha/mocha";
+import {forEach, indexOf} from "../../public/vendor/adminlte/bower_components/mocha/mocha";
require('./bootstrap');
require('./menu');
});
},
+ watch: {
+ errorsForm: function(newValue, old) {
+ this.errorsForm = newValue ??= old
+ }
+ },
+
computed: {
cartItemCount() {
// Todo: See if this should count just number of items or make a sum of all quantities? What is more useful? The sum of quantities can be found using map/reduce functions but this needs to be adapted for the object structure using Object.keys as the source.
* The following functions are used for login,register and account page
*
*/
- resetUrlAccount() {
- // Remove hash to url if exist to prevent to stay in same tab
+ lockTab(tab) {
+ // Add hash to url to stay in same tab when page is reloading
// It used in account page when we navigate between different tab
- let hash = window.location.hash,
- fullUrl = window.location.origin+window.location.pathname
+ let fullUrl = window.location.origin+window.location.pathname
+ history.pushState("", "", fullUrl+'#'+tab);
+ },
+ activeTab(tab) {
+ this.tab = tab
+ this.lockTab(tab)
- if(hash)
- history.pushState("", "", fullUrl);
+ this.errorsForm = {}
+ this.removeErrorsForm()
},
toggleType(el) {
this.type[el] = this.type[el] === "password" ? "text" : "password"
errorInput[i].classList.remove('error');
}
},
- errorHandling(data, root){
+ errorHandling(data, root, form){
if (data.response) {
- let errors = data.response.data.errors
+ let errors = { 'errors': data.response.data.errors, 'id': form }
root.errorsForm = errors
-
root.removeErrorsForm()
- for (let k in errors) {
+ for (let k in errors['errors']) {
if(k.indexOf('.')){
let keys = k.split('.')
for(let i = 0; i < keys.length; i++){
}
}
let el = document.querySelector('[name*="' + k + '"]')
+
+ if(form)
+ el = document.querySelector(form+' [name*="' + k + '"]')
+
el.classList.add('error')
}
}
}
)
},
- activeTab(tab) {
- this.tab = tab
- this.errorsForm = {}
- this.removeErrorsForm()
- this.resetUrlAccount()
- },
getUser() {
let root = this
axios.post('/ajax/getuser')
.then(function (response) {
- //
root.user = response.data['user']
root.addresses = JSON.parse(root.user.address)
- root.default_billing_address = 'billing'+response.data['address_billing']
- root.default_delivery_address = 'delivery'+response.data['address_delivery']
+
+ // Assign default values to each address, if the field is empty
+ // It useful during the first connexion to his account
+ for(let i = 0; i < root.addresses.length; i++) {
+ root.addresses[i]['name'] = root.addresses[i]['name'] ?? 'Adresse '+root.addresses[i]['city']
+ root.addresses[i]['company'] = root.addresses[i]['company'] ?? root.user['company']
+ root.addresses[i]['firstname'] = root.addresses[i]['firstname'] ?? root.user['firstname']
+ root.addresses[i]['lastname'] = root.addresses[i]['lastname'] ?? root.user['lastname']
+ }
+
+ root.default_billing_address = 'billing' + response.data['address_billing']
+ root.default_delivery_address = 'delivery' + response.data['address_delivery']
})
.catch(function (error) {
}
this.addresses.push(newAddress)
- // Disabled the click to add address at most once
+ // Disabled the click, to add address, at most once
let target = event.target
target.setAttribute('disabled', 'disabled')
axios.post('/ajax/update', data)
.then(function (response) {
- //
root.removeErrorsForm()
root.validateForm = true
root.form[id] = response.data
updateAddress(id) {
let root = this,
form = document.getElementById(id),
+ formId = '#'+form.getAttribute('id'),
data = new FormData(form)
axios.post('/ajax/updateAddress', data)
root.validateForm = true
})
.catch(function (error) {
- root.errorHandling(error, root)
+ root.errorHandling(error, root, formId)
}
)
},
deleteAddress(index, form) {
let root = this,
form_ = document.getElementById(form),
- data = {
- index: index
- }
+ data = { index: index }
axios.post('/ajax/deleteaddress', data)
.then(function (response) {
- //
+ if(response.data)
+ root.addresses = response.data
+
form_.animate([
{ opacity: 1 },
{ opacity: 0 }
}, 1000)
})
.catch(function (error) {
-
}
)
}
-<form :id="'update-address-'+key" class="form-portal max-w-half-form" @submit.prevent="updateAddress('update-address-'+key)">
- <div class="form-errors mb-10" v-if="Object.keys(errorsForm).length > 0">
+<form :id="'update-address-'+index" class="form-portal max-w-half-form" @submit.prevent="updateAddress('update-address-'+index)">
+ <div class="form-errors mb-10" v-if="errorsForm['id'] === '#update-address-'+index">
<ul class="list-disc list-inside text-red">
- <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+ <li class="leading-5" v-for="(errorName,errorKey) in errorsForm['errors']" :key="errorKey">
@{{ errorName[0] }}
</li>
</ul>
{{ __('Société') }}<span>*</span>
<input class="py-3 mt-3" type="text" v-model="address.company" required="required" name="address[company]" />
</label>
- <label class="form-input half text-navy">
- {{ __('Nom') }}<span>*</span>
- <input class="py-3 mt-3" type="text" v-model="address.lastname" required="required" name="address[lastname]" />
- </label>
<label class="form-input half text-navy">
{{ __('Prénom') }}<span>*</span>
<input class="py-3 mt-3" type="text" v-model="address.firstname" required="required" name="address[firstname]" />
</label>
+ <label class="form-input half text-navy">
+ {{ __('Nom') }}<span>*</span>
+ <input class="py-3 mt-3" type="text" v-model="address.lastname" required="required" name="address[lastname]" />
+ </label>
<label class="form-input text-navy">
{{ __('Adresse') }}<span>*</span>
<textarea class="py-3 mt-3" required="required" v-model="address.address" name="address[address]">
</div>
<div class="form-group">
<label class="label-checkbox flex">
- <input type="radio" :checked="default_billing_address !== 'billing'+key ? false : true" class="w-4 h-4" name="address[billing_address]" @click="default_billing_address = 'billing'+key" />
+ <input type="radio" :checked="default_billing_address !== 'billing'+index ? false : true" class="w-4 h-4" name="address[billing_address]" @click="default_billing_address = 'billing'+index" />
<span class="ml-4">{{ __('Adresse de facturation par défaut') }}</span>
</label>
<label class="label-checkbox flex mb-6">
- <input type="radio" :checked="default_delivery_address !== 'delivery'+key ? false : true" class="w-4 h-4" name="address[delivery_address]" @click="default_delivery_address = 'delivery'+key" />
+ <input type="radio" :checked="default_delivery_address !== 'delivery'+index ? false : true" class="w-4 h-4" name="address[delivery_address]" @click="default_delivery_address = 'delivery'+index" />
<span class="ml-4">{{ __('Adresse de livraison par défaut') }}</span>
</label>
</div>
- <input type="hidden" :value="key" name="index">
+ <input type="hidden" :value="index" name="index">
<div class="form-footer flex flex-wrap-reverse justify-between items-center">
<span class="form-required-legend inline-block my-4 mr-3 text-grey-dark xs:self-start xs:mt-5">
*{{ __('Champs obligatoires') }}
{{ __('Enregistrer les modifications') }}
</button>
</div>
- <button class="flex items-center mt-12" @click.prevent="deleteAddress(key, 'update-address-'+key)" v-if="addresses.length > 1">
+ <button class="flex items-center mt-12" @click.prevent="deleteAddress(index, 'update-address-'+index)" v-if="addresses.length > 1">
@svg('icon-trash')
<span class="ml-3">Supprimer cette adresse</span>
</button>
<div class="ajax-form flex flex-col pt-12">
<h2 class="text-2xl m-0">{{ __('Mes coordonnées') }}</h2>
<form id="update-details" class="form-portal max-w-half-form" @submit.prevent="update('update-details')">
- <div class="form-errors my-10" v-if="Object.keys(errorsForm).length > 0">
+
+ <div class="form-errors my-10" v-if="errorsForm['errors']">
<ul class="list-disc list-inside text-red">
- <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+ <li class="leading-5" v-for="(errorName,errorKey) in errorsForm['errors']" :key="errorKey">
@{{ errorName[0] }}
</li>
</ul>
</div>
+
<div class="form-group fields grid">
- <label class="form-input half text-navy">
- {{ __('Nom') }}<span>*</span>
- <input class="py-3 mt-3" type="text" v-model="user.lastname" required="required" name="lastname" />
- </label>
<label class="form-input half text-navy">
{{ __('Prénom') }}<span>*</span>
<input class="py-3 mt-3" type="text" v-model="user.firstname" required="required" name="firstname" />
</label>
+ <label class="form-input half text-navy">
+ {{ __('Nom') }}<span>*</span>
+ <input class="py-3 mt-3" type="text" v-model="user.lastname" required="required" name="lastname" />
+ </label>
</div>
<div class="form-group">
<label class="form-input half text-navy">
@svg('icon-white-add')
</button>
</div>
- <div class="ajax-form flex flex-col pt-12" v-for="(address, key, index) in addresses" :key="key">
+ <div class="ajax-form flex flex-col pt-12" v-for="(address, index) in addresses" :key="index">
<address-form />
</div>
</div>
<div class="pb-12 border-b border-b-light-b">
<h2 class="text-2xl m-0">{{ __('Modifier mon mot de passe') }}</h2>
</div>
- <div class="signup-form-errors mb-10" v-if="Object.keys(errorsForm).length > 0">
+ <div class="signup-form-errors mb-10" v-if="errorsForm['errors']">
<ul class="list-disc list-inside text-red">
- <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+ <li class="leading-5" v-for="(errorName,errorKey) in errorsForm['errors']" :key="errorKey">
@{{ errorName[0] }}
</li>
</ul>
<div class="form-info text-navy mb-10">
<h1 class="text-4xl m-0">Se connecter</h1>
</div>
- <div class="signup-form-errors mb-10" v-if="Object.keys(errorsForm).length > 0">
+ <div class="form-errors mb-10" v-cloak v-if="errorsForm['errors']">
<ul class="list-disc list-inside text-red">
- <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+ <li class="leading-5" v-for="(errorName,errorKey) in errorsForm['errors']" :key="errorKey">
@{{ errorName[0] }}
</li>
</ul>
</div>
<form id="signin-form" class="form-portal" @submit.prevent="signin">
- <div class="form-errors mb-10" v-if="Object.keys(errorsForm).length > 0">
+
+ <div class="form-errors mb-10" v-cloak v-if="errorsForm['errors']">
<ul class="list-disc list-inside text-red">
- <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+ <li class="leading-5" v-for="(errorName,errorKey) in errorsForm['errors']" :key="errorKey">
@{{ errorName[0] }}
</li>
</ul>
</div>
+
@csrf
<div class="form-group mb-6">
<label class="form-input text-navy">
<h1 class="text-4xl m-0">{{ __("Créer un compte") }}</h1>
</div>
- <div class="signup-form-errors mb-10" v-if="Object.keys(errorsForm).length > 0">
+ <div class="form-errors mb-10" v-if="errorsForm['errors']">
<ul class="list-disc list-inside text-red">
- <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+ <li class="leading-5" v-for="(errorName,errorKey) in errorsForm['errors']" :key="errorKey">
@{{ errorName[0] }}
</li>
</ul>
<a href="/mon-compte">
<span>{{ __('Mon compte') }}</span>
</a>
- <ul>
+ <!--<ul>
<li :class="{ active : tab === 'address' }">
<a href="/mon-compte#address" @click.stop="tab = 'address'">
<span>{{ __('Mes adresses') }}</span>
</a>
</li>
- </ul>
+ </ul>-->
</li>
<li class="{{ Request::is('mes-commandes') ? "active" : '' }}">
<a href="">