templates/frontoffice_bundle/panier/panier.html.twig line 1
{% extends "frontoffice_bundle/base.html.twig" %}
{% block body %}
<style>
.error{
color:red;
}
.cart_quantity_delete{
cursor: pointer !important;
}
</style>
<div class="container-fluid page-header py-5">
<h1 class="text-center text-white display-6">Panier</h1>
<ol class="breadcrumb justify-content-center mb-0">
<li class="breadcrumb-item"><a href="/">Acceuil</a></li>
{# <li class="breadcrumb-item"><a href="#">Pages</a></li> #}
<li class="breadcrumb-item active text-white">Panier</li>
</ol>
</div>
<section id="cart_items">
<div class="container mt-2">
<div class="successMsg" id="successMsg" style="display: none;">
</div>
<div class="error" id="errorMsg" style="display: none;">
</div>
<br/>
{% if articles|length > 0 %}
<div class="table-responsive cart_info">
<form method="POST" id="updateForm">
<input type="hidden" name="formName" value="updateQte" />
<table class="table table-condensed">
<thead>
<tr class="cart_menu">
<td class="image">Article</td>
<td class="description"></td>
<td class="price">Prix</td>
<td class="quantity">Quantité</td>
<td class="total">Total</td>
<td></td>
</tr>
</thead>
<tbody>
{% for a in articles %}
<input type="hidden" name="ids[]" value="{{ a["obj"].id }}" />
<tr>
<td class="cart_product">
<img src="{{ asset(a["obj"].imgPrincipale) }}" style="max-height: 100px;max-width: 100px;" alt="">
</td>
<td class="cart_description">
<h4>{{ a["pan"].designation }}</h4>
<p>Unité : {{ a["pan"].unite }}</p>
</td>
<td class="cart_price">
<p>{{ a["pan"].prixU }} DH</p>
<input type="hidden" name="prix_u" id="prix_u" value="{{ a["pan"].prixU }}"/>
</td>
<td class="cart_quantity">
<div class="input-group" style="width: 50%;">
<div class="input-group-btn">
<button type="button" class="btn btn-default btn-number" disabled="disabled" data-type="minus" data-field="quant-{{ a["obj"].id }}">
<i class="fa fa-minus"></i>
</button>
</div>
<input type="text" name="quant-{{ a["obj"].id }}" class="form-control input-number" onchange="calculTotal(this)" id="qte" value="{{ a["pan"].qte }}" min="{{ a["obj"].minQte }}" max="150" unite="{{ a["obj"].unite }}">
<div class="input-group-btn">
<button type="button" class="btn btn-default btn-number" data-type="plus" data-field="quant-{{ a["obj"].id }}">
<i class="fa fa-plus"></i>
</button>
</div>
</div>
</td>
<td class="cart_total">
<input class="cart_total_price" disabled type="text" name="total_price" id="total_price" value="{{ a["pan"].prixTotal }}"/>
{# <p class="cart_total_price">{{ a["pan"].prixTotal }} DH</p> #}
</td>
<td class="cart_delete">
<a class="cart_quantity_delete text-danger" onclick="deleteFromPanier({{ a["obj"].id }})"><i class="fa fa-times"></i></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
</div>
{% else %}
<div class="text-center">
<img src="{{ asset("bundles/Frontoffice/img/emptyCart.webp") }}" /><br/>
<a href="/" class="btn btn-primary text-white">Votre panier est vide Veuillez cliquer ici pour faire vos achats</a><br/><br/>
</div>
{% endif %}
</div>
</section> <!--/#cart_items-->
{% if articles|length > 0 %}
<section id="do_action">
<div class="container">
<div class="heading">
<h3></h3>
<p></p>
</div>
<div class="row">
<div class="col-sm-6">
<div class="chose_area signup-form" style="padding-left: 15px;">
<form method="POST">
<input type="hidden" name="formName" value="codePromo">
<span class="total ">Code promo : </span>
<input type="text" class="form-control" name="codePromo" style="width: 100%;margin-bottom: 5px;margin-top: 8px;" value="{{ codePromo }}">
<button type="submit" class="validateAchat text-white btn btn-primary">Valider</button>
{% if response != "OK" and response != "" %}
<div class="error">
{{ response }}
</div>
{% endif %}
</form>
</div>
</div>
<div class="col-lg-6" align="right ">
<b>Total : </b> {{ total|number_format(2, '.', '') }} DH<br/><br/>
<b>Livraison : </b> {{ livraison }} DH<br/><br/>
{% if totalPromo != 0 %}
<b>Promotion : </b> {{ totalPromo|number_format(2, '.', '') }} DH<br/><br/>
{% endif %}
<span style="font-weight: bold;" class="text-secondary">
<b>Total à payer : </b> {{ total + livraison + totalPromo }} DH<br/><br/>
</span>
</div>
<div class="row">
<div class="total_area text-center">
<a class="btn btn-info update text-white" onclick="document.getElementById('updateForm').submit();">Mettre à jour</a>
<a class="btn btn-primary check_out text-white" onclick="commander()">Commander</a>
</div>
</div>
</div>
</div>
</section>
{% endif %}
{% endblock %}
{% block js %}
<script type="text/javascript">
{% if articles|length > 0 %}
var codePromo = "{{ codePromo }}";
/*----------*/
$('.btn-number').click(function(e){
e.preventDefault();
fieldName = $(this).attr('data-field');
type = $(this).attr('data-type');
var input = $("input[name='"+fieldName+"']");
var currentVal = parseFloat(input.val());
if (!isNaN(currentVal)) {
var toAddOrDel = 0.5;
if(input.attr('unite').toLowerCase().replace(/\s/g, '') == "u" || input.attr('unite').toLowerCase().replace(/\s/g, '') == "unité" || input.attr('unite').toLowerCase().replace(/\s/g, '') == "unite"){
toAddOrDel = 1;
}
if(type == 'minus') {
if(currentVal > input.attr('min')) {
input.val(currentVal - toAddOrDel).change();
}
if(parseFloat(input.val()) == input.attr('min')) {
$(this).attr('disabled', true);
}
} else if(type == 'plus') {
if(currentVal < input.attr('max')) {
input.val(currentVal + toAddOrDel).change();
}
if(parseFloat(input.val()) == input.attr('max')) {
$(this).attr('disabled', true);
}
}
} else {
input.val(0);
}
});
$('.input-number').focusin(function(){
$(this).data('oldValue', $(this).val());
});
{# $('.input-number').change(function() {
minValue = parseFloat($(this).attr('min'));
maxValue = parseFloat($(this).attr('max'));
valueCurrent = parseFloat($(this).val());
console.log(minValue);
name = $(this).attr('name');
if(valueCurrent >= minValue) {
$(".btn-number[data-type='minus'][data-field='"+name+"']").removeAttr('disabled')
} else {
console.log('error');
Swal.fire({
icon: 'error',
title: 'Oops...',
text: "Désolé, la valeur minimale a été atteinte",
});
$(this).val($(this).data('oldValue'));
}
if(valueCurrent <= maxValue) {
$(".btn-number[data-type='plus'][data-field='"+name+"']").removeAttr('disabled')
} else {
console.log('error');
Swal.fire({
icon: 'error',
title: 'Oops...',
text: "Désolé, la valeur maximale a été atteinte",
});
$(this).val($(this).data('oldValue'));
}
}); #}
$(".input-number").keydown(function (e) {
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
(e.keyCode == 65 && e.ctrlKey === true) ||
(e.keyCode >= 35 && e.keyCode <= 39)) {
return;
}
// Ensure that it is a number and stop the keypress
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
});
function calculTotal(input)
{
var row = input.closest("tr");
var cart_price = row.querySelector(".cart_price");
var prix_u = parseFloat(cart_price.querySelector("input[name='prix_u']").value.replace(",", "."));
var cart_quantity = row.querySelector(".cart_quantity");
var qte = parseFloat(cart_quantity.querySelector("input[id='qte']").value.replace(",", "."));
var cart_quantity = row.querySelector(".cart_total");
var total_price_input = cart_quantity.querySelector("input[name='total_price']") ;
var minQte = parseInt(input.getAttribute('min'));
var maxQte = parseInt(input.getAttribute('max'));
if (!isNaN(prix_u) && !isNaN(qte) && qte >= minQte && qte <= maxQte) {
var total_price = (prix_u * qte).toFixed(2);
total_price_input.value = total_price;
document.getElementById('updateForm').submit();
}
}
//------------
function deleteFromPanier(id){
Swal.fire({
title: "Êtes-vous sûr ?",
text: "La suppression du produit.",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#3085d6",
confirmButtonText: "Supprimer",
cancelButtonText: "Annuler",
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: 'get',
url: '/deleteFromPanier/?id='+id,
success: function (data) {
if(data == 'OK')
{
window.location.reload();
}
else
{
Swal.fire({
icon: 'error',
title: 'Oops...',
text: data,
})
}
},
error: function (xhr, ajaxOptions, thrownError) {
Swal.fire({
icon: 'error',
title: 'Oops...',
text: "une erreur s'est produite",
})
}
});
}
});
}
function commander(){
window.location= "/validerCommande/?p={{ codePromo }}";
/*noty({
text: 'Etes vous sûr de vouloir valider votre commande ?',
type: 'confirm',
theme: 'relax',
layout: 'center',
animation: {
open: 'animated bounceInDown',
close: 'animated bounceOutUp', // jQuery animate function property object
easing: 'swing', // easing
speed: 200 // opening & closing animation speed
},
buttons : [
{addClass: 'btn btn-success', text: 'Oui', onClick: function ($noty) {
$.ajax({
type: 'get',
url: '/commander/?codePromo='+codePromo,
success: function(data){
if(data == "OK"){
var msg = "Votre commande est enregistrée avec succès";
document.getElementById("successMsg").innerHTML = msg;
$("#successMsg").css("display","block");
$("#errorMsg").css("display","none");
setTimeout(function(){ window.location.href="/mesCommandes/" ;} , 1000);
}
else if(data == "NO1"){
var msg = "Veillez vous connecter avant de valider votre commande <br><a href='/account/'>Cliquez ici</a>";
document.getElementById("errorMsg").innerHTML = msg;
$("#successMsg").css("display","none");
$("#errorMsg").css("display","block");
}
else{
var msg = data;
document.getElementById("errorMsg").innerHTML = msg;
$("#successMsg").css("display","none");
$("#errorMsg").css("display","block");
}
}
});
$noty.close();
}
},
{
addClass: 'btn btn-danger', text: 'Non', onClick: function ($noty) {
$noty.close();
}
}
]
});*/
}
{% endif %}
</script>
{% endblock %}