Merge branch 'issue-51' into 'develop'

style: 💄 upgrade view of recap basket by component #51

See merge request ldc-web/projets/boutique-cnc-sable!63
This commit is contained in:
Vincent BRIDIER 2025-01-16 11:16:00 +00:00
commit 2da57afa29
6 changed files with 248 additions and 191 deletions

View file

@ -3,7 +3,6 @@
namespace App\Policies;
use App\Models\Product;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Auth\Access\Response;
use Illuminate\Support\Carbon;
@ -19,7 +18,7 @@ class ProductPolicy
* @return \Illuminate\Auth\Access\Response
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
*/
public function addtocart(?User $user, Product $product)
public function addtocart($user, Product $product)
{
// phpcs:enable
$now = Carbon::now();

View file

@ -58,6 +58,7 @@ Vue.component(
"basket-buttons",
require("./components/BasketButtons.vue").default
);
Vue.component("basket-recap", require("./components/BasketRecap.vue").default);
const store = new Vuex.Store({
state: {

View file

@ -0,0 +1,230 @@
<template>
<section id="basket-recap">
<div v-if="!emptybasket" class="d-flex flex-column-reverse flex-lg-column">
<table class="table m-0">
<thead class="d-none d-lg-table-header-group border-bottom border-dark">
<tr>
<td scope="col"></td>
<td scope="col" class="text-center align-middle">Quantité</td>
<td scope="col" class="text-center align-middle">Prix au KG TTC</td>
<td scope="col" class="text-center align-middle">Prix TTC</td>
<td scope="col" class="text-center align-middle">Sous-total TTC</td>
</tr>
</thead>
<tbody class="border-bottom border-dark">
<tr v-for="item in panier" class="position-relative">
<!-- CARD -->
<td class="card position-relative border-0 p-2 px-lg-0 py-lg-3">
<div class="d-flex flex-row justify-content-center justify-content-lg-start align-items-center p-0 w-100 m-0">
<div class="position-relative w-25">
<p class="position-absolute top-50 start-50 translate-middle font-Barlow-bold title-small text-uppercase d-none text-center m-0">bientôt disponible</p>
<img v-if="item.product.picture"
:src="'/images/produits/'+item.product.picture"
:alt="item.cartItem.name"
:title="item.cartItem.name"
class="img-fluid"
>
<img v-else
src="/img/pl_nophoto.png"
:alt="item.cartItem.name"
:title="item.cartItem.name"
class="img-fluid"
>
</div>
<div class="card-body d-flex flex-column justify-content-between justify-content-lg-center align-items-start w-75 h-100 ps-2">
<a :href="'/produit/'+item.product.slug"
class="text-decoration-none"
:title="item.product.name" target="_self">
<p class="title-small font-Barlow-bold stretched-link text-dark m-0">
{{ item.product.name }}
</p>
</a>
<div v-if="item.product.description" class="card-text" v-html="item.product.description"></div>
<p v-if="item.product.weight_variable" class="fst-italic text-muted">
*Produit vendu au kilo : {{ currencyFormatter(item.product.calculatedPrices.priceKgTtc) }}/kg
</p>
<p v-else class="fst-italic text-muted">
Prix au kilo : {{ currencyFormatter(item.product.calculatedPrices.priceKgTtc) }}/kg
</p>
<div class="card-action d-flex justify-content-between align-items-center w-100">
<div class="card-price d-flex flex-row justify-content-center align-items-center">
<span class="card-price-new d-block d-lg-none ms-1">
{{ currencyFormatter(item.product.calculatedPrices.discountedPriceTtc * item.cartItem.qty) }}
</span>
</div>
</div>
</div>
</div>
<div class="filtre position-absolute bottom-0 start-0 w-100 h-100 rounded-4"></div>
</td>
<!-- END CARD -->
<td class="d-none d-lg-table-cell title-small border-0 text-center align-middle font-Barlow-extra-bold">
<BasketButtons :productId="item.product.id" />
</td>
<td class="d-none d-lg-table-cell title-small border-0 text-center align-middle font-Barlow-extra-bold">
<template v-if="item.product.weight_variable">
{{ currencyFormatter(item.product.calculatedPrices.priceKgTtc) }}
</template>
</td>
<td class="position-relative d-none d-lg-table-cell title-small border-0 text-center align-middle">
<template v-if="item.product.weight_variable">
<span class="position-absolute top-0 start-50 translate-middle-x mt-4 pt-3 fs-7 text-muted">Environ*</span>
</template>
<span class="font-Barlow-extra-bold">{{ currencyFormatter(item.product.calculatedPrices.discountedPriceTtc) }}</span>
</td>
<td class="position-relative d-none d-lg-table-cell title-small border-0 text-center align-middle">
<template v-if="item.product.weight_variable">
<span class="position-absolute top-0 start-50 translate-middle-x mt-4 pt-3 fs-7 text-muted">Environ*</span>
</template>
<span class="font-Barlow-extra-bold">{{ currencyFormatter(item.product.calculatedPrices.discountedPriceTtc * item.cartItem.qty) }}</span>
</td>
<td class="w-0 p-0">
<button class="btn btn-cross position-absolute icon-medium icon-cross" @click="removeItem(item.cartItem.rowId)" :disabled="(disableBtn) ? true : false"></button>
</td>
</tr>
</tbody>
</table>
<table class="table-total table m-0 rounded-4">
<tr>
<td class="d-none d-lg-table-cell border-0"></td>
<td class="d-none d-lg-table-cell border-0"></td>
<td class="border-0 text-center align-middle p-0 p-lg-2">Total estimé TTC</td>
<td class="title-small border-0 text-center align-middle p-0 p-lg-2 font-Barlow-extra-bold">{{ currencyFormatter(cartTotals.totalTTC) }}</td>
</tr>
</table>
</div>
<p v-else class="alert alert-danger text-center w-100 m-0">Votre panier est vide</p>
<div class="recap-actions d-flex flex-row justify-content-between align-items-center w-100 my-5">
<a class="btn" :href="routeProducts">⟵ Continuer mes achats</a>
<template v-if="emptybasket">
<a class="btn btn-product w-100 w-lg-fit text-uppercase font-Barlow-extra-bold rounded-4" :href="routeOrders">Terminer une commande en attente ?</a>
</template>
<form v-else :action="propRouteSales" method="POST">
<input type="hidden" name="_token" :value="csrf">
<input type="submit" class="btn btn-product w-100 w-lg-fit text-uppercase font-Barlow-extra-bold rounded-4" value="Suivant >">
</form>
</div>
</section>
</template>
<script>
import BasketButtons from './BasketButtons.vue';
export default {
components: { BasketButtons },
props: ['propRouteProducts', 'propRouteSales', 'propRouteOrders'],
data() {
return {
success:false,
errors:false,
response: '',
promotion_slide: -1,
disableBtn: false,
routeProducts: this.propRouteProducts,
routeSales: this.propRouteSales,
routeOrders: this.propRouteOrders,
csrf: document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
}
},
computed: {
emptybasket() { return _.isEmpty(this.$store.state.panier); },
panier() { return this.$store.state.panier; },
cartTotals() { return this.$store.state.cartTotals; }
},
mounted() {
this.init();
console.log(this.propRouteProducts);
},
methods: {
init() {
axios.post('/ajax/get-cart', {
instance: 'panier',
}).then(response => {
let result = response.data;
this.updateStore(result);
}).catch(error => {
console.log(error);
})
},
addtocart(product_id,qtty) {
let breaker = false;
this.panier.forEach(element => {
if(element.cartItem.id == product_id) {
element.cartItem.qty += qtty;
}
if(element.cartItem.qty <= 0) {
this.removeItem(element.cartItem.rowId);
breaker = true;
}
});
if(!breaker) {
axios.post('/ajax/add-to-cart', {
id: product_id,
qty: qtty,
instance: 'panier',
}).then(
(response) => {
this.updateStore(response.data);
}
)
.catch(function (error) {
console.log(error);
this.response = "Erreur lors de la modification du panier.";
});
}
},
removeItem(rowId) {
this.disableBtn = true;
axios.post('/ajax/remove-from-cart', {
rowId: rowId,
instance: 'panier',
}).then(
(response) => {
this.updateStore(response.data);
this.disableBtn = false;
}
)
.catch(function (error) {
console.log(error);
this.response = "Erreur lors de la modification du panier.";
this.disableBtn = false;
});
},
emptyCart() {
axios.post('/ajax/empty-cart', {
instance: 'panier',
}).then(
(response) => {
this.updateStore(response.data);
}
)
.catch(function (error) {
console.log(error);
this.response = "Erreur lors de la modification du panier.";
});
},
updateStore(result) {
if (result[0].length != this.panier.length) {
this.$store.commit({
type: 'updatePanier',
panier: result[0]
});
}
this.$store.commit({
type: 'updatePanier',
panier: result[0]
});
this.$store.commit({
type: 'updateCartTotals',
cartTotals: result[1]
});
},
// General purpose.
currencyFormatter(num) {
if (isNaN(num)) {
return num;
}
return new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(num);
},
}
}
</script>

View file

@ -1,24 +1,21 @@
<article class="order col-lg-3 position-fixed start-0 position-lg-relative p-0 p-lg-5">
<div class="row">
<div class="col-2 d-flex d-lg-none justify-content-start align-items-center p-0">
<a class="btn" href="{{ url()->previous() }}">⟵</a>
</div>
<div class="col-8 col-lg-12 p-0 p-lg-1 {{ $activestep == 1 ? "active" : ($activestep > 1 ? "step-done" : "") }}">
<div class="col-10 col-lg-12 {{ $activestep == 1 ? "active" : ($activestep > 1 ? "step-done" : "") }}">
<div class="row">
<span class="col-2 col-xl-1 d-none d-lg-block overflow-hidden font-Barlow-bold p-0">1-</span>
<p class="col p-0 m-0">Récapitulatif</p>
<p class="text-start col p-0 m-0">Récapitulatif</p>
</div>
</div>
<div class="col-8 col-lg-12 p-0 p-lg-1 {{ $activestep == 2 ? "active" : ($activestep > 2 ? "step-done" : "") }}">
<div class="col-10 col-lg-12 {{ $activestep == 2 ? "active" : ($activestep > 2 ? "step-done" : "") }}">
<div class="row">
<span class="col-2 col-xl-1 d-none d-lg-block overflow-hidden font-Barlow-bold p-0">2-</span>
<p class="col p-0 m-0">Réservation</p>
<p class="text-start col p-0 m-0">Réservation</p>
</div>
</div>
<div class="col-8 col-lg-12 p-0 p-lg-1 {{ $activestep == 3 ? "active" : ($activestep > 3 ? "step-done" : "") }}">
<div class="col-10 col-lg-12 {{ $activestep == 3 ? "active" : ($activestep > 3 ? "step-done" : "") }}">
<div class="row">
<span class="col-2 col-xl-1 d-none d-lg-block overflow-hidden font-Barlow-bold p-0">3-</span>
<p class="col p-0 m-0">Confirmation</p>
<p class="text-start col p-0 m-0">Confirmation</p>
</div>
</div>
<span class="col-2 d-flex d-lg-none justify-content-end align-items-center">{{ $activestep }}/3</span>

View file

@ -15,107 +15,11 @@
@endif
@include('partials.tunnel-stepper')
<article class="col mt-6 m-lg-0">
<p class="d-none d-lg-block title-regular text-center text-lg-end text-uppercase font-Barlow-extra-bold m-3">Récapitulatif de votre panier</p>
<div class="d-flex flex-column-reverse flex-lg-column">
<table class="table m-0">
<thead class="d-none d-lg-table-header-group border-bottom border-dark">
<tr>
<td scope="col"></td>
<td scope="col" class="text-center align-middle">Quantité</td>
<td scope="col" class="text-center align-middle">Prix au KG TTC</td>
<td scope="col" class="text-center align-middle">Prix TTC</td>
<td scope="col" class="text-center align-middle">Sous-total TTC</td>
</tr>
</thead>
<tbody class="border-bottom border-dark">
@foreach ($cart as $cartItem)
<tr class="position-relative">
<!-- CARD -->
<td class="card position-relative border-0 p-2 px-lg-0 py-lg-3">
<div class="d-flex flex-row justify-content-center justify-content-lg-start align-items-center p-0 w-100 m-0">
<div class="position-relative w-25">
<p class="position-absolute top-50 start-50 translate-middle font-Barlow-bold title-small text-uppercase d-none text-center m-0">bientôt disponible</p>
@if (isset($cartItem->model->picture))
<img src="{{ asset('/images/produits/' . $cartItem->model->picture) }}"
alt="{{ $cartItem->name }}" class="img-fluid">
@else
<img src="{{ asset(config('app.theme') . '/img/pl_nophoto.png') }}"
alt="{{ $cartItem->name }}" class="img-fluid">
@endif
</div>
<div class="card-body d-flex flex-column justify-content-between justify-content-lg-center align-items-start w-75 h-100 ps-2">
<a href="{{ route('product', ['productSlug' => $cartItem->model->slug]) }}"
class="text-decoration-none"
title="{{ $cartItem->name }}" target="_self">
<p class="title-small font-Barlow-bold stretched-link text-dark m-0">
{{ $cartItem->name }}
</p>
</a>
@if($cartItem->model->description) <div class="card-text">{!! $cartItem->model->description !!}</div> @endif
@if ($cartItem->model->weight_variable)
<p class="fst-italic text-muted">*Produit vendu au kilo : @fmt_currency($cartItem->model->priceKgTtc)/kg</p>
@else
<p class="fst-italic text-muted">Prix au kilo : @fmt_currency($cartItem->model->priceKgTtc)/kg</p>
@endif
<div class="card-action d-flex justify-content-between align-items-center w-100">
<div class="card-price d-flex flex-row justify-content-center align-items-center">
{{-- @if ($cartItem->model->promotions->count())
<span class="card-price-original position-relative">@fmt_currency($cartItem->model->priceTtc)</span>
@endif --}}
<span class="card-price-new d-block d-lg-none {{-- @if ($cartItem->model->promotions->count()) text-red @endif --}} ms-1">
{{ sprintf('%s €', number_format($cartItem->model->discountedPriceTtc * $cartItem->qty, 2, ',', ' ')) }}
</span>
</div>
{{--<div class="d-block d-lg-none">
<basket-buttons :product-id='{{ $cartItem->model->id }}'></basket-buttons>
</div>--}}
</div>
</div>
</div>
<div class="filtre position-absolute bottom-0 start-0 w-100 h-100 rounded-4"></div>
</td>
<!-- END CARD -->
<td class="d-none d-lg-table-cell title-small border-0 text-center align-middle font-Barlow-extra-bold">{{ $cartItem->qty }}</td>
<td class="d-none d-lg-table-cell title-small border-0 text-center align-middle font-Barlow-extra-bold">
@if ($cartItem->model->weight_variable) @fmt_currency($cartItem->model->priceKgTtc) @endif
</td>
<td class="position-relative d-none d-lg-table-cell title-small border-0 text-center align-middle">
@if ($cartItem->model->weight_variable) <span class="position-absolute top-0 start-50 translate-middle-x mt-4 pt-3 fs-7 text-muted">Environ*</span> @endif
<span class="font-Barlow-extra-bold">@fmt_currency($cartItem->model->discountedPriceTtc)</span>
</td>
<td class="position-relative d-none d-lg-table-cell title-small border-0 text-center align-middle">
@if ($cartItem->model->weight_variable) <span class="position-absolute top-0 start-50 translate-middle-x mt-4 pt-3 fs-7 text-muted">Environ*</span> @endif
<span class="font-Barlow-extra-bold">{{ sprintf('%s €', number_format($cartItem->model->discountedPriceTtc * $cartItem->qty, 2, ',', ' ')) }}</span>
</td>
<td class="w-0 p-0">
<button class="btn btn-cross position-absolute icon-medium icon-cross" type="button" value="{{ $cartItem->rowId }}"></button>
</td>
</tr>
@endforeach
</tbody>
</table>
<table class="table-total table m-0 rounded-4">
<tr>
<td class="d-none d-lg-table-cell border-0"></td>
<td class="d-none d-lg-table-cell border-0"></td>
<td class="border-0 text-center align-middle p-0 p-lg-2">Total estimé TTC</td>
<td class="title-small border-0 text-center align-middle p-0 p-lg-2 font-Barlow-extra-bold">{{ sprintf('%s €', number_format($cartInfos['totalTTC'], 2, ',', ' ')) }}</td>
</tr>
</table>
</div>
<div class="recap-actions d-flex flex-row justify-content-between align-items-center w-100 my-5">
<a class="btn d-none d-lg-block" href="{{ route('products') }}">⟵ Continuer mes achats</a>
@if (count($cart) > 0)
<form action="{{ route('sales.order-init') }}" method="POST">
@csrf
<input type="submit" class="btn btn-product w-100 w-lg-fit text-uppercase font-Barlow-extra-bold rounded-4" value="Suivant >">
</form>
@else
<div class="alert alert-danger">Votre commande est vide.</div>
<a class="btn btn-product w-100 w-lg-fit text-uppercase font-Barlow-extra-bold rounded-4" href="{{ route('account.my-orders') }}">Terminer une commande en attente ?</a>
@endif
</div>
<h1 class="d-none d-lg-block title-regular text-center text-lg-end text-uppercase font-Barlow-extra-bold m-3">
Récapitulatif de votre panier
</h1>
<basket-recap :prop-route-products="'{{ route('products') }}'" :prop-route-sales="'{{ route('sales.order-init') }}'"
:prop-route-orders="'{{ route('account.my-orders') }}'"></basket-recap>
</article>
</div>
</main>

View file

@ -3,7 +3,7 @@
background-color: $medium-grey;
z-index: 1;
.col-8:not(.active) {
.col-10:not(.active) {
display: none;
}
@ -34,6 +34,8 @@
font-size: 1.5em;
font-family: 'Barlow_Extra_Bold';
background-color: $white;
position: sticky;
top: 8rem;
}
.btn-cross {
@ -47,45 +49,6 @@
z-index: $zindex-fixed;
}
}
// SSSSSSSSSSSSSSS MMMMMMMM MMMMMMMM
// SS:::::::::::::::SM:::::::M M:::::::M
// S:::::SSSSSS::::::SM::::::::M M::::::::M
// S:::::S SSSSSSSM:::::::::M M:::::::::M
// S:::::S M::::::::::M M::::::::::M
// S:::::S M:::::::::::M M:::::::::::M
// S::::SSSS M:::::::M::::M M::::M:::::::M
// SS::::::SSSSS M::::::M M::::M M::::M M::::::M
// SSS::::::::SS M::::::M M::::M::::M M::::::M
// SSSSSS::::S M::::::M M:::::::M M::::::M
// S:::::SM::::::M M:::::M M::::::M
// S:::::SM::::::M MMMMM M::::::M
// SSSSSSS S:::::SM::::::M M::::::M
// S::::::SSSSSS:::::SM::::::M M::::::M
// S:::::::::::::::SS M::::::M M::::::M
// SSSSSSSSSSSSSSS MMMMMMMM MMMMMMMM
@include media-breakpoint-up(sm) { //576px
//
}
// MMMMMMMM MMMMMMMMDDDDDDDDDDDDD
// M:::::::M M:::::::MD::::::::::::DDD
// M::::::::M M::::::::MD:::::::::::::::DD
// M:::::::::M M:::::::::MDDD:::::DDDDD:::::D
// M::::::::::M M::::::::::M D:::::D D:::::D
// M:::::::::::M M:::::::::::M D:::::D D:::::D
// M:::::::M::::M M::::M:::::::M D:::::D D:::::D
// M::::::M M::::M M::::M M::::::M D:::::D D:::::D
// M::::::M M::::M::::M M::::::M D:::::D D:::::D
// M::::::M M:::::::M M::::::M D:::::D D:::::D
// M::::::M M:::::M M::::::M D:::::D D:::::D
// M::::::M MMMMM M::::::M D:::::D D:::::D
// M::::::M M::::::MDDD:::::DDDDD:::::D
// M::::::M M::::::MD:::::::::::::::DD
// M::::::M M::::::MD::::::::::::DDD
// MMMMMMMM MMMMMMMMDDDDDDDDDDDDD
@include media-breakpoint-up(md) { //768px
//
}
// LLLLLLLLLLL GGGGGGGGGGGGG
// L:::::::::L GGG::::::::::::G
// L:::::::::L GG:::::::::::::::G
@ -107,7 +70,7 @@
.order {
background-color: transparent;
.col-8:not(.active) {
.col-10:not(.active) {
display: block;
}
@ -148,6 +111,7 @@
&-total {
font-size: 1em;
position: initial;
td:not(.font-Barlow-extra-bold) {
font-family: 'Barlow_Regular';
}
@ -159,41 +123,3 @@
}
}
}
// XXXXXXX XXXXXXXLLLLLLLLLLL
// X:::::X X:::::XL:::::::::L
// X:::::X X:::::XL:::::::::L
// X::::::X X::::::XLL:::::::LL
// XXX:::::X X:::::XXX L:::::L
// X:::::X X:::::X L:::::L
// X:::::X:::::X L:::::L
// X:::::::::X L:::::L
// X:::::::::X L:::::L
// X:::::X:::::X L:::::L
// X:::::X X:::::X L:::::L
// XXX:::::X X:::::XXX L:::::L LLLLLL
// X::::::X X::::::XLL:::::::LLLLLLLLL:::::L
// X:::::X X:::::XL::::::::::::::::::::::L
// X:::::X X:::::XL::::::::::::::::::::::L
// XXXXXXX XXXXXXXLLLLLLLLLLLLLLLLLLLLLLLL
@include media-breakpoint-up(xl) { //1200px
//
}
// XXXXXXX XXXXXXXXXXXXXX XXXXXXXLLLLLLLLLLL
// X:::::X X:::::XX:::::X X:::::XL:::::::::L
// X:::::X X:::::XX:::::X X:::::XL:::::::::L
// X::::::X X::::::XX::::::X X::::::XLL:::::::LL
// XXX:::::X X:::::XXXXXX:::::X X:::::XXX L:::::L
// X:::::X X:::::X X:::::X X:::::X L:::::L
// X:::::X:::::X X:::::X:::::X L:::::L
// X:::::::::X X:::::::::X L:::::L
// X:::::::::X X:::::::::X L:::::L
// X:::::X:::::X X:::::X:::::X L:::::L
// X:::::X X:::::X X:::::X X:::::X L:::::L
// XXX:::::X X:::::XXXXXX:::::X X:::::XXX L:::::L LLLLLL
// X::::::X X::::::XX::::::X X::::::XLL:::::::LLLLLLLLL:::::L
// X:::::X X:::::XX:::::X X:::::XL::::::::::::::::::::::L
// X:::::X X:::::XX:::::X X:::::XL::::::::::::::::::::::L
// XXXXXXX XXXXXXXXXXXXXX XXXXXXXLLLLLLLLLLLLLLLLLLLLLLLL
@include media-breakpoint-up(xxl) { //1400px
//
}