}) : 0;
$basicPriceByProductId = $data['products'][$keyRefs]["basic_selling_price"];
- $price = floatval(($basicPriceByProductId + $totalOptionsPrice) * $quantity);
- $data['products'][$keyRefs]["price"] = $total[] = $price;
+ $price = floatval($basicPriceByProductId + $totalOptionsPrice);
+ $total[] = floatval($price * $quantity);
+ $data['products'][$keyRefs]["price"] = $price;
}
+ $checkUnavailableEcommerceProduct = array_filter($data['products'], function($n) {
+ return !$n['price'];
+ });
+
$ht = array_reduce($total, function($carry, $item) { return $carry + $item; });
- $ht += ($total > 1000) ? 20 : 0;
+ $ht += ($ht > 1000) ? 20 : 0;
$tva = $ht * 0.2;
$ttc = $ht + $tva;
- $data['total'] = $ttc;
+ $data['total'] = !$checkUnavailableEcommerceProduct ? $ttc : null;
//
$data['addresses'] = json_encode($data['addresses']);
$id = $panier->getOriginal('id');
$request->session()->put('last_selection', $id);
} else {
- Panier::where('id', $lastCartRefs)->update($data);
+
+ Panier::where('id', $lastCartId)->update($data);
}
return __('Le panier a été enregistré avec succès !');
}
public function savedCartToCurrent(Request $request) {
+ $request->validate([
+ 'id' => 'required|numeric'
+ ]);
+
+ $cartId = $request->input('id');
- //$this->cart()
+ $cart = Panier::find($cartId)->toArray();
+
+ $clientIdInRequest = intval($cart['user_id']);
+ $clientId = Client::getClientConnected()->id;
+
+ if($clientIdInRequest === $clientId) {
+ $cartData = json_decode($cart['products'],true);
+
+ // Clear cart session
+ $request->session()->forget('cart_items');
+
+ // Save back to the session
+ $request->session()->put('cart_items', $cartData);
+ $request->session()->put('last_selection', intval($cartId));
+ return "success";
+ }
+ return false;
}
}
emailExist: false,
validateEmail: false,
address_choice: true,
- validateForm: false,
+ validateAction: false,
tab: 'infos',
addresses: [{}],
user: '',
statusConfig: false,
statusText: '',
//
- nameSaved: {}
+ nameSaved: {},
+ confirmMessageCart: ''
},
beforeMount() {
axios.post('/ajax/signup', data)
.then(function (response) {
- root.validateForm = true
+ root.validateAction = true
// Reset form
root.email_signin = ''
axios.post('/ajax/update', data)
.then(function (response) {
root.removeErrorsForm()
- root.validateForm = true
+ root.validateAction = true
root.form[id] = response.data
})
.catch(function (error) {
axios.post('/ajax/updateAddress', data)
.then(function (response) {
root.removeErrorsForm()
- root.validateForm = true
+ root.validateAction = true
})
.catch(function (error) {
root.errorHandling(error, root, formId)
axios.post('/ajax/storecart', data)
.then(function (response) {
- console.log(response)
+ root.validateAction = true
+ root.confirmMessageCart = response.data;
})
.catch(function (error) {
console.log(error)
.catch(function (error) {
})
},
- savedCartToCurrent() {
- const data = {
+ savedCartToCurrent(event) {
+ const id = event.target.dataset.id,
+ homeUrl = window.location.origin;
- }
+ axios.post('/ajax/savedCartToCurrent', {id: id})
+ .then(function (response) {
+ //root.animateDelete(el)
+ window.location.replace(homeUrl+'/ma-selection')
+ })
+ .catch(function (error) {
+ })
}
},
/**
const vm = vnode.context;
Window.event = (e) => {
if (!el.contains(e.target) || e.key === "Escape") {
- vm.validateForm = false
+ vm.validateAction = false
}
}
document.body.addEventListener('click', Window.event)
-<div class="modal-confirm fixed top-0 left-0 flex items-center" v-cloak v-if="validateForm">
+<div class="modal-confirm fixed top-0 left-0 flex items-center" v-cloak v-if="validateAction">
<div class="modal-confirm-text relative text-2xl bg-white p-24 text-center mx-auto" v-close-outside>
- <button class="modal-confirm-close absolute" @click.prevent="validateForm = false">
+ <button class="modal-confirm-close absolute" @click.prevent="validateAction = false">
@svg('icon-close-thin', 'w-4')
</button>
{{ $slot }}
</div>
</content>
-
+ <modal-confirm>
+ <p>@{{ confirmMessageCart }}</p>
+ </modal-confirm>
@endsection
<div id="cart-saved-{{ $cart['id'] }}" class="cartsave bg-grey-200 pr-2v pl-2v">
<div class="cartsave-name">
<div>
- <textarea id="cart-name-{{ $cart['id'] }}" class="readonly" value="{{ $cart['name'] }}" readonly />
+ <input id="cart-name-{{ $cart['id'] }}" class="readonly" value="{{ $cart['name'] }}" readonly />
</div>
<a href="#" data-input="{{ $cart['id'] }}" class="inline-block animated-underline" data-defaulttext="{{ __('Editer le nom du panier') }}" data-edittext="{{ __('Sauvegarder le nom du panier') }}" @click.prevent.self="toggleName">
{{ __('Editer le nom du panier') }}
</button>
<div class="flex items-center">
- <a href="" class="animated-underline mr-10 xs:mr-0">{{ __('Modifier ce panier') }}</a>
+ <a href="#" data-id="{{ $cart['id'] }}" class="animated-underline mr-10 xs:mr-0" @click.self.prevent="savedCartToCurrent">
+ {{ __('Modifier ce panier') }}
+ </a>
@isset($cart['total'])
<a href="" class="btn">{{ __('Passer commande') }}</a>
@else