{% extends 'base_front.html.twig' %}
{% block meta %}
<title>Mon panier</title>
<meta name="description" content="{{ products|length }} produits pour le moment">
{% endblock %}
{% block style %}
<style>
.indicationSupp:hover {
}
.inputQtyOpt {
width: 63px;
height: 39px;
padding: 0 5px;
text-align: center;
background-color: transparent;
border: 1px solid #efefef;
}
.imgOptModal {
height:50px;
border-radius:2px
}
.modifProdSess {
color: white !important;
display: flex;
align-items: center;
}
{# css loading... #}
#MyLoading {
visibility: hidden;
}
#MyLoading.MyShow {
visibility: visible;
}
@media screen and (max-width: 576px) {
.modifProdSess {
padding: 8px 7px;
font-size: 7px;
}
.indicationSupp {
padding: 10px 15px;
}
}
{# modadl option #}
@media screen and (min-width: 800px) {
.myWidth {
max-width: 800px;
}
}
{# choice option #}
.labold {
font-weight: 500;
font-size: 18px;
}
.mt9 {
margin-top: 9px;
}
.myPadding {
padding: 8px 0px;
}
</style>
{% endblock %}
{% block body %}
<!-- Modal -->
{# Modal modif groupe d'option #}
<div class="modal fade" id="modalOptionGP" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog myWidth" role="document">
<div class="modal-content">
{# <form action=""> #}
<div class="modal-header">
<h5 class="modal-title" id="">Modifier les groupes d'options</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row" id="valeurgropOption">
{# <input type="hidden" id="id_optionmodal">
<div class="col-lg-6 col-12" >
<div id="optionsimage">
{# <img src="{{ asset(constant('App\\Services\\File::IMAGE_PRODUCT_DIR') ~ product.photos.toArray()[0].url) }}" alt=""> #}
{# </div>
</div> #}
{# <div class="col-lg-6 col-12" style="display: block"> #}
{# <div class="row">
<div class="col-8">
<label for="" class="labold">Couleur</label>
<div class="custom-checkbox myPadding" style="position: relative">
<input type="checkbox" name="" id="vert" class="custom-control-input">
<label for="vert" class="custom-control-label" style="margin-left: 25px;">Vert (3€)</label>
</div>
<div class="custom-checkbox myPadding" style="position: relative">
<input type="checkbox" name="" id="rouge" class="custom-control-input">
<label for="rouge" class="custom-control-label" style="margin-left: 25px;">Rouge (4€)</label>
</div>
<div class="custom-checkbox myPadding" style="position: relative">
<input type="checkbox" name="" id="bleu" class="custom-control-input">
<label for="bleu" class="custom-control-label" style="margin-left: 25px;">Bleu (6€)</label>
</div>
</div>
<div class="col-4">
<label for="qt1" class="mt9">Quantité</label>
<input type="number" name="" min="0" id="" class="form-control">
<input type="number" name="" min="0" id="" class="form-control">
<input type="number" name="" min="0" id="" class="form-control">
</div>
</div><br>
<div class="row">
<div class="col-8">
<label class="labold" for="">Taille</label>
<select name="" id="" class="form-control wide" style="display: block !important;">
<option value="">M (6€)</option>
<option value="">L (8€)</option>
<option value="">XL (10€)</option>
</select>
</div>
<div class="col-4">
<label for="qt1" class="mt9">Quantité</label>
<input type="number" name="" min="0" id="" class="form-control">
</div>
</div><br>
<div class="row">
<div class="col-8">
<label class="labold" for="">Type tissu</label>
<select name="" id="" class="form-control wide" style="display: block !important;">
<option value="">Semi-cotton (2€)</option>
<option value="">Cotton (4€)</option>
<option value="">t-shirt rétréci (5€)</option>
</select>
</div>
<div class="col-4">
<label for="qt1" class="mt9">Quantité</label>
<input type="number" name="" min="0" id="" class="form-control">
</div>
</div><br> #}
{# </div> #}
</div>
</div>
{# {% endfor %}
{% endif %} #}
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>
<button type="submit" class="btn btn-primary" id="" onclick="validechoiModalGroupoption()">Ok</button>
</div>
{# </form> #}
</div>
</div>
</div>
{# Fin Modal modif groupe d'option #}
{# Modal faire part #}
<div class="modal fade" id="modifAchatFairePart" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
{% set idSessOpt = app.session.get('idProduit') %}
<div class="modal-dialog" role="document" style="max-width: 700px">
<div class="modal-content">
<form action="{{path('update_option')}}" method="POST">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modifier les options</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{# <span class="font-weight-bold">Options disponibles :</span><span id="MyLoadingFP"> Chargement en cours...</span> #}
<div class="containerOptionFP pl-3 row">
<div class="col-lg-5 col-12">
<input type="hidden" id="id_produit">
<input type="hidden" id="price_produit">
<input type="hidden" id="qte_produit">
<div id="tousOptions"></div>
</div>
<div class="col-lg-7 col-12">
<div class="m-info">Si vous souhaitez ajouter une option différente de celle d'avant, cochez votre choix et modifiez-le si nécessaire</div>
<div class="forme_options" style="display: none !important">
<form action="">
<input type="hidden" id="id_optionFP">
<input type="hidden" id="name_optionFP">
<input type="hidden" id="image_optionFP">
<div class="optionFP_color">
<label for="optionFP_color">Couleur</label>
<select name="" id="optionFP_color" class="wide form-control">
</select>
</div>
<div class="optionFP_format">
<label for="optionFP_format">Format</label>
<select name="" id="optionFP_format" class="wide form-control">
</select>
</div>
<div class="optionFP_finition">
<label for="optionFP_finition">Finition</label>
<select name="" id="optionFP_finition" class="wide form-control">
</select>
</div>
<div class="optionFP_papier">
<label for="optionFP_papier">Papier</label>
<select name="" id="optionFP_papier" class="wide form-control">
</select>
</div>
<div class="optionFP_etiquette">
<label for="optionFP_etiquette">Etiquette</label>
<select name="" id="optionFP_etiquette" class="wide form-control">
</select>
</div>
<div class="optionFP_ruban">
<label for="optionFP_ruban">Ruban</label>
<select name="" id="optionFP_ruban" class="wide form-control">
</select>
</div>
<div class="optionFP_quantite">
<label for="optionFP_quantite">Quantite</label>
<select name="" id="optionFP_quantite" class="wide form-control">
</select>
</div>
<div class="validerModifFP mt-3">
<button class="btn btn-secondary" type="button" onclick="Anulleroption()">Annuler</button>
<button class="btn btn-primary" type="button" onclick="validechoioption()">Valider</button>
</div>
</form>
</div>
</div>
</div>
{# {% endset %} #}
<!-- form modifsession prod -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>
<button type="submit" class="btn btn-primary" onclick="validechoiModaloption()">Modifier</button>
</div>
</form>
</div>
</div>
</div>
{# Fin modal faire Part #}
<div class="modal fade" id="modifAchatProd" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
{% set idSessOpt = app.session.get('idProduit') %}
<div class="modal-dialog" role="document">
<div class="modal-content">
<form action="{{path('update_option')}}" method="POST">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modifier les options</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- form modifsession prod -->
{# <div class="form-group">
<label for="quantity_product">Quantité</label><br>
<div class="quantity buttons_added">
<input type="button" value="-" class="minus">
<input id="quantity_product" type="number" step="1" min="1" max="" name="quantity" value="1" title="Qty" class="input-text qty text" size="4" pattern="" inputmode="">
<input type="button" value="+" class="plus">
</div>
</div> #}
<span class="font-weight-bold">Options disponibles :</span><span id="MyLoading"> Chargement en cours...</span>
<div class="containerOption pl-3 row">
<div class="oneOption col-12 row">
<div class="col-8">
<div class="row">
<div class="col-4">
<img src="/upload/produits/vernis-a-ongles-laques-fuchsia-fiesta-1-62a2e00ab1b53.jpeg" style="height:50px;border-radius:2px">
</div>
<div class="col-4">
<img src="/upload/produits/vernis-a-ongles-laques-fuchsia-fiesta-1-62a2e00ab1b53.jpeg" style="height:50px;border-radius:2px">
</div>
</div>
<div class="custom-checkbox" style="position: relative">
<input type="checkbox" data-price="" name="" value="" class="custom-control-input" id="checkbo">
<label class="custom-control-label" for="checkbo">
<strong style="margin-left: 31px;">10 €</strong>
<span>-
Name option</span>
</label>
</div>
</div>
<div class="col-4">
<div style="height:36px"></div>
<input type="number" name="" id="" class="inputQtyOpt" min="1" value="1"/>
</div>
</div>
<div class="oneOption col-12 row">
<div class="col-8">
<div class="row">
<div class="col-4">
<img src="/upload/produits/vernis-a-ongles-laques-fuchsia-fiesta-1-62a2e00ab1b53.jpeg" style="height:50px;border-radius:2px">
</div>
<div class="col-4">
<img src="/upload/produits/vernis-a-ongles-laques-fuchsia-fiesta-1-62a2e00ab1b53.jpeg" style="height:50px;border-radius:2px">
</div>
</div>
<div class="custom-checkbox" style="position: relative">
<input type="checkbox" data-price="" name="" value="" class="custom-control-input" id="checkbo1">
<label class="custom-control-label" for="checkbo1">
<strong style="margin-left: 31px;">10 €</strong>
-
Name option</label>
</div>
</div>
<div class="col-4">
<div style="height:36px"></div>
<input type="number" name="" id="" class="inputQtyOpt" min="1" value="1"/>
</div>
</div>
<div class="oneOption col-12 row">
<div class="col-8">
<div class="row">
<div class="col-4">
<img src="/upload/produits/vernis-a-ongles-laques-fuchsia-fiesta-1-62a2e00ab1b53.jpeg" style="height:50px;border-radius:2px">
</div>
<div class="col-4">
<img src="/upload/produits/vernis-a-ongles-laques-fuchsia-fiesta-1-62a2e00ab1b53.jpeg" style="height:50px;border-radius:2px">
</div>
</div>
<div class="custom-checkbox" style="position: relative">
<input type="checkbox" data-price="" name="" value="" class="custom-control-input" id="checkbo2">
<label class="custom-control-label" for="checkbo2">
<strong style="margin-left: 31px;">10 €</strong>
-
Name option</label>
</div>
</div>
<div class="col-4">
<div style="height:36px"></div>
<input type="number" name="" id="" class="inputQtyOpt" min="1" value="1"/>
</div>
</div>
</div>
{# {% endset %} #}
<!-- form modifsession prod -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>
<button type="submit" class="btn btn-primary">Modifier</button>
</div>
{# {% endfor %}
{% endif %} #}
</form>
</div>
</div>
</div>
<!-- Modal -->
<div class="content mt-5 mb-5" style="margin-bottom:100px!important">
<div class="container">
<div class="row mb-5">
<div class="tab-pane fade active show" id="allguest" role="tabpanel" aria-labelledby="allguest-tab" style="width:100%">
<div class="card-body row justify-content-between">
<h3>Mon panier ({{ products|length }}
produit
{% if products|length > 1 %}s
{% endif %})</h3>
<a href="{{path('pdf_generate')}} " class="btn btn-primary float-right">Télécharger mon devis</a>
</div>
<div class="table-responsive" style="width:100%">
<table class="table mt-4">
<thead>
<tr>
<th class="wedding-budget-event">Designation</th>
<th class="wedding-budget-estimate">Aperçu</th>
<th class="wedding-budget-estimate">Prix à l'unité</th>
<th class="wedding-budget-actual">Quantité</th>
<th class="wedding-budget-paid">Total produit</th>
<th class="wedding-budget-paid"></th>
</tr>
</thead>
<tbody>
{% if pack %}
<tr>
<td>{{ pack.name }}</td>
<td><img src="{{ asset(constant('App\\Services\\File::IMAGE_PRODUCT_DIR')) ~ pack.image }}" style="height:50px;border-radius:2px"></td>
<td>
<span class="total-amount">{{ pack.price|number_format(2, '.') }}€</span>
</td>
<td>1</td>
<td>
<span class="total-amount">{{ pack.price|number_format(2, '.') }}€</span>
</td>
<td class="paid-total">
<a href="{{ path('front_my_basket_remove_pack', {'id': pack.id}) }}" class="btn btn-rounded btn-default">Supprimer du panier</a>
</td>
</tr>
{% endif %}
{% set TotalPriceProduct = 0 %}
{% set totOpt = 0 %}
{% set totGpOpt = 0 %}
{% for product in products %}
{% set optionObjectByProd = filter_service.getProductOptionByProduit(product.product) %}
{# Product added #}
<tr class="border-bottom" style="border-top: 1px solid #dee2e6 !important;">
<td>{{ product.product.name }}
{% set isClothing = null %}
{% for subcategory in product.product.subCategories %}
{% if subcategory.isClothing %}
{% set isClothing = true %}
{% endif %}
{% endfor %}
{% if isClothing %}
<br><strong>Taille :
{{ product.size }}</strong>
{% endif %}
{% set isColor = null %}
{% for subcategory in product.product.subCategories %}
{% if subcategory.isColor %}
{% set isColor = true %}
{% endif %}
{% endfor %}
{% if isColor %}
<br><strong>Couleur :
{{ product.color }}</strong>
{% endif %}
</td>
<td>
{% if product.product.photos.first != false %}
<img src="{{ asset(constant('App\\Services\\File::IMAGE_PRODUCT_DIR')) ~ product.product.photos.first.url }}" style="height:50px;border-radius:2px">
{% else %}
<img src="{{ asset('images/vecteezy_vector-gear-logo-design-with-multi-colors-range_6172776.jpg') }}" style="height:50px;border-radius:2px">
{% endif %}
</td>
{% if product.promo %}
{% set ProductPrice = product.product.price - product.promo %}
{% else %}
{% set ProductPrice = product.product.price %}
{% endif %}
<td class="estimate-total">
<span class="total-amount">
{% if product.promo %}
<small>
<del>{{ product.product.price|number_format(2, '.') }}€</del>
</small>
<strong>{{ ProductPrice|number_format(2, '.') }}€</strong>
{% else %}
{{ ProductPrice|number_format(2, '.') }}€
{% endif %}
</span><br>
{% if product.promo %}(code promo -{{ product.promo }}€)
{% endif %}
</td>
{# Quantity product #}
<td class="actual-total">{{ product.quantity }}</td>
{% set TotalWithQuantity = product.quantity * ProductPrice %}
{% set TotalPriceProduct = TotalPriceProduct + TotalWithQuantity %}
<td class="paid-total">
<span class="total-amount">{{ TotalWithQuantity|number_format(2, '.') }}€</span>
</td>
<td class="paid-total d-flex justify-content-around" style="column-gap: 5px;">
<a href="{{ path('front_my_basket_remove_product', {'id': product.product.id}) }}" class="btn btn-rounded btn-danger indicationSupp" title="Supprimer du panier" style="font-size: 17px;display: flex;align-items: center;"><i class="fa fa-trash" aria-hidden="true"></i></a>
{# Supprimer du panier #}
{# onclick="getOptionByIdProd({{product.product.id}})" data-id="{{product.product.id}}" #}
<!-- Button trigger modal -->
{% for subcategory in product.product.subCategories %}
{% if subcategory.subCategorySlug != "faire-part" %}
<a onclick="getGroupOption({{product.product.id}})" data-id="{{product.product.id}}" class="btn btn-rounded btn-default modifProdSess" data-toggle="modal" data-target="#modalOptionGP">
Ajouter des options
</a>
{% else %}
<a onclick="ajouterOptions('{{product.product.id}}','{{product.quantity}}','{{ProductPrice}}','{{ app.request.getSchemeAndHttpHost() }}');" id="ajoutOption" class="btn btn-rounded btn-default modifProdSess" data-toggle="modal">
Ajouter des options
</a>
{# data-target="#modifAchatFairePart" #}
{% endif %}
{% endfor %}
</td>
</tr>
{# Fin Product added #}
{# Option #}
{% for subCategories in product.product.subCategories.snapshot %}
{% if subCategories.subCategorySlug != "faire-part" %}
{% for key,option in product.options %}
{% set optionObject = filter_service.getProductOption(key) %}
{# {% set TotalPriceProduct = TotalPriceProduct + optionObject.price %} #}
<tr class="" style="background:#fff">
<td class="pl-4">
<strong>Option :</strong>
{{ optionObject.name }}</td>
{# {% if isClothing %}
<br><strong>Taille :
{{ product.size }}</strong>
{% endif %} #}
<td>
{# {% if optionObject.image1 %}
<img src="{{ asset(constant('App\\Services\\File::IMAGE_PRODUCT_DIR')) ~ optionObject.image1 }}" style="height:50px;border-radius:2px">
{% endif %} #}
</td>
<td class="estimate-total">
{# <span class="total-amount">{{ optionObject.price|number_format(2, '.') }}€</span> #}
<span class="total-amount"></span>
</td>
{# qty option #}
<td></td>
{# {% set totalOpt = null %}
{% for key,qty in product.qtyOption %}
{% if optionObject.id == key %}
<td class="actual-total">{{qty}}</td>
{% set totqtyOpt = optionObject.price * qty %}
<td class="paid-total">
<span class="total-amount">{{ totqtyOpt|number_format(2, '.') }}€</span>
</td>
{% set totOpt = totOpt + totqtyOpt %}
{% endif %}
{% endfor %} #}
{# qty option #}
<td class="paid-total"></td>
</tr>
{% for valOption in option %}
<tr>
<td class="pl-5">{{ valOption["valeur"] }}</td>
<td></td>
<td class="estimate-total"><span class="total-amount">{{ valOption["prix"] }} €</span></td>
<td>{{ valOption["qte"] ? valOption["qte"] : 1 }}</td>
{# <pre>
{{ dump(valOption["qte"]) }}
</pre> #}
{% set totval = valOption["prix"] * (valOption["qte"] ? valOption["qte"] : 1) %}
<td class="estimate-total"><span class="total-amount">{{ totval }} €</spna></td>
{% set totGpOpt = totGpOpt + totval %}
</tr>
{% endfor %}
{% endfor %}
{% else %}
{% if product.options_farep is defined %}
{% for option in product.options_farep %}
<tr style="background:#fff">
<td class="pl-4">
<strong>Option :</strong>
{{ option.nomoption }}
{# <br><strong>Format :
{{ option.form }}</strong>
<br><strong>Finition :
{{ option.finition }}</strong>
<br><strong>Papier :
{{ option.papier}}</strong>
<br><strong>Etiquette :
{{ option.etiquette}} #}
</strong></td>
<td>
{% if option.imageoption %}
<img src="{{ asset(constant('App\\Services\\File::IMAGE_PRODUCT_DIR')) ~ option.imageoption }}" style="height:50px;border-radius:2px">
{% endif %}
</td>
<td class="estimate-total">
<span class="total-amount">{{ option.price|number_format(2, '.') }}€</span>
</td>
{# qty option #}
{# {% set totalOpt = null %}#}
<td class="actual-total">{{option.quantite}}</td>
{% set totqtyOpt = option.price * option.quantite %}
<td class="paid-total">
<span class="total-amount">{{ totqtyOpt|number_format(2, '.') }}€</span>
</td>
{% set totOpt = totOpt + totqtyOpt %}
<td class="paid-total"></td>
</tr>
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}
{# Fin Option #}
{% endfor %}
{% if pack or products is not empty %}
<tr>
<td>TOTAL :</td>
<td></td>
<td></td>
<td></td>
{% if pack %}
{% set TotalPriceProduct = TotalPriceProduct + pack.price %}
{% endif %}
{% set totOptions = totOpt + totGpOpt %}
<td>{{ (TotalPriceProduct + totOptions)|number_format(2, '.') }}€</td>
</tr>
{% endif %}
{% if not pack and products is empty %}
<tr>
<td>Aucun produit ajouté au panier</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
<div class="card-footer" style="height:70px">
{% if products|length > 0 or pack is not null %}
{% if is_granted('ROLE_ENTERPRISE') == false %}
<div class="float-left">
{{ form_start(form, {'attr': {'class': 'form-inline'}}) }}
<div class="form-group">
{{ form_widget(form.codePromo) }}
</div>
<button type="submit" class="btn btn-default ml-3">Valider</button>
{{ form_end(form) }}
{% if isMessagePromo is defined and isMessagePromo %}
<span style="color:green">Code promo valide !</span>
{% endif %}
</div>
<div class="float-right">
<a href="{{ path('front_command_livraison') }}" class="btn btn-primary">Commander</a>
</div>
{% endif %}
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block javascript %}
<script>
function wcqib_refresh_quantity_increments() {
jQuery("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").each(function (a, b) {
var c = jQuery(b);
c.addClass("buttons_added"),
c.children().first().before('<input type="button" value="-" class="minus" />'),
c.children().last().after('<input type="button" value="+" class="plus" />')
})
}
String.prototype.getDecimals || (String.prototype.getDecimals = function () {
var a = this,
b = ("" + a).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
return b ? Math.max(0, (b[1] ? b[1].length : 0) - (b[2] ? + b[2] : 0)) : 0
}),
jQuery(document).ready(function () {
wcqib_refresh_quantity_increments()
}),
jQuery(document).on("updated_wc_div", function () {
wcqib_refresh_quantity_increments()
}),
jQuery(document).on("click", ".plus, .minus", function () {
var a = jQuery(this).closest(".quantity").find(".qty"),
b = parseFloat(a.val()),
c = parseFloat(a.attr("max")),
d = parseFloat(a.attr("min")),
e = a.attr("step");
b && "" !== b && "NaN" !== b || (b = 0),
"" !== c && "NaN" !== c || (c = ""),
"" !== d && "NaN" !== d || (d = 0),
"any" !== e && "" !== e && void 0 !== e && "NaN" !== parseFloat(e) || (e = 1),
jQuery(this).is(".plus") ? c && b >= c ? a.val(c) : a.val((b + parseFloat(e)).toFixed(e.getDecimals())) : d && b <= d ? a.val(d) : b > 0 && a.val((b - parseFloat(e)).toFixed(e.getDecimals())),
a.trigger("change")
});
</script>
<script>
{# Lading script... #}
const loader = document.querySelector('#MyLoading');
function afficheLoading() {
loader.classList.add('MyShow');
}
function cacherLoading() {
loader.classList.remove('MyShow');
}
{# Fin Lading script... #}
const containerOpt = document.querySelector('.containerOption');
function getOptionByIdProd(idProd) {
afficheLoading();
const data = {
idProd: idProd
};
let datas = new FormData();
datas.append("data", JSON.stringify(data));
if (containerOpt.children) {
var first = containerOpt.firstElementChild;
while (first) {
first.remove();
first = containerOpt.firstElementChild;
}
}
fetch(`/get-option/${idProd}`)
.then(response => response.json())
.then(data => {
cacherLoading();
console.log(data);
data[0].map((item)=>{
//console.log("idOpt vao miditra",item.id);
let objQty = data[1].qty;
let idProd = document.createElement('input');
idProd.type = "hidden";
idProd.value = data[2];
idProd.setAttribute('name','idProd');
let oneOpt = document.createElement('div');
oneOpt.classList.add('col-12');
oneOpt.classList.add('row');
let col8 = document.createElement('div');
col8.classList.add('col-8');
let row = document.createElement('div');
row.classList.add('row');
let col4a = document.createElement('div');
col4a.classList.add('col-4');
let col4b = document.createElement('div');
col4b.classList.add('col-4');
let img1 = document.createElement('img');
img1.classList.add('imgOptModal');
// image
if (item.image1 == null){
img1.style.display = "none";
} else {
img1.src = `/upload/produits/${item.image1}`;
}
let img2 = document.createElement('img');
img2.classList.add('imgOptModal');
if (item.image2 == null){
img2.style.display = "none";
} else {
img2.src = `/upload/produits/${item.image2}`;
}
let customCheckBox = document.createElement('div');
customCheckBox.classList.add('custom-checkbox');
customCheckBox.style.position = "relative";
let inputCheckBox = document.createElement('input');
inputCheckBox.type = "checkbox";
inputCheckBox.classList.add('custom-control-input');
inputCheckBox.classList.add('option-checkbox');
inputCheckBox.setAttribute('id',`idCheck${item.id}`);
inputCheckBox.setAttribute('name',`options[${item.id}]`);
inputCheckBox.setAttribute('value',`${item.price}`);
// checked if already in session
for (const idOpt in objQty) {
if(item.id == idOpt){
inputCheckBox.checked = true;
}
}
let customControlLabel = document.createElement('label');
customControlLabel.classList.add('custom-control-label');
customControlLabel.setAttribute('for',`idCheck${item.id}`);
let nameStrong = document.createElement('strong');
nameStrong.innerHTML = `${item.price} €`;
nameStrong.style.marginLeft = "31px";
let nameSpan = document.createElement('span');
nameSpan.innerHTML = `- ${item.name}`;
let nameSpan2 = document.createElement('span');
nameSpan2.innerHTML = `<button type="button">modif</button>`;
let col4 = document.createElement('div');
col4.classList.add('col-4');
let myheight = document.createElement('div');
myheight.style.height = "36px";
let inputQty = document.createElement('input');
inputQty.type = "number";
inputQty.classList.add('inputQtyOpt');
inputQty.setAttribute('min','1');
inputQty.setAttribute('id',`QtyidCheck${item.id}`);
inputQty.setAttribute('name',`QtyOption[${item.id}]`);
inputQty.setAttribute('value','1');
// get value qty in session
for (const idOpt in objQty) {
if(item.id == idOpt) {
inputQty.setAttribute('value',`${objQty[idOpt]}`);
}
}
col4.appendChild(myheight);
col4.appendChild(inputQty);
col4a.appendChild(img1);
col4b.appendChild(img2);
row.appendChild(col4a);
row.appendChild(col4b);
customControlLabel.appendChild(nameStrong);
customControlLabel.appendChild(nameSpan);
customCheckBox.appendChild(inputCheckBox);
customCheckBox.appendChild(customControlLabel);
col8.appendChild(row);
col8.appendChild(customCheckBox);
oneOpt.appendChild(idProd);
oneOpt.appendChild(col8);
oneOpt.appendChild(col4);
containerOpt.appendChild(oneOpt);
});
/*let idp = document.createElement("p");
idp.textContent = data;
containerOpt.appendChild(idp);*/
/*fetch('/get-option')
.then(obj => obj.json())
.then(objjs => console.log(objjs));*/
if(data) {
const optionCheckbox = document.querySelectorAll('.option-checkbox');
for (var i = 0; i < optionCheckbox.length; i++) {
let qtyOpt = document.getElementById(`Qty${optionCheckbox[i].id}`);
// disable unchecked checkbox
if(!optionCheckbox[i].checked) {
qtyOpt.disabled = true;
qtyOpt.style.display = "none";
}
optionCheckbox[i].addEventListener('change', (optMod) => {
if (optMod.target.checked) {
qtyOpt.disabled = false;
qtyOpt.style.display = "block";
} else {
qtyOpt.disabled = true;
qtyOpt.style.display = "none";
}
})
}
}
});
}
</script>
<script>
function getGroupOption(id_prod) {
// console.log('kokokoko',url);
console.log('isID',id_prod);
// var id_product=314;
$("#valeurgropOption").html("");
fetch(`/tous-options-groups/${id_prod}`)
.then(response=> response.json())
.then(data=>{
console.log('tous option', data);
$("#valeurgropOption").append(data);
});
}
function validechoiModalGroupoption() {
// $("#modalOptionGP").modal("hide");
var url = window.location.href.split('/');
var param_url = url[0]+'//'+url[2];
const formData = new FormData();
var idProduit = $('#id_produit').val();
console.log("id_porduit",idProduit);
var goption= document.getElementsByClassName('goption');
var labels =new Array();
for (let i = 0; i < goption.length; i++) {
var id_goption = goption[i].id.split("_");
var label= document.getElementsByClassName('label_'+id_goption[1]);
var hidden= document.getElementsByClassName('hidden_'+id_goption[1]);
var qte= document.getElementsByClassName('qte_'+id_goption[1]);
// console.log('labeb',label);
var compter=0;
var lab =new Array();
var qt =new Array();
for (let l = 0; l < label.length; l++) {
console.log('type', label[l].type);
if (label[l].type=="checkbox" && label[l].checked) {
lab[compter] = hidden[l].value;
qt[compter] = qte[l].value;
compter++
}
if (label[l].type=="select-one" && label[l].value != "") {
lab[compter] = label[l].value;
qt[compter] = qte[l].value;
compter++
}
}
labels[i] = {idoption: id_goption[1], labelo: lab, qte: qt};
}
console.log('valin label',labels);
// localStorage.setItem('produit_groups', JSON.stringify(labels));
formData.append("modifGroupOption", JSON.stringify(labels));
fetch(`${param_url}/updateOptionGroups/${idProduit}`, {
method: "POST",
body: formData
})
.then(response=> response.json())
.then(data=>{
console.log('data_io',data);
if (data.message == "ok") {
window.location.reload();
}
$("#modalOptionGP").modal("hide");
});
}
</script>
<script>
function ajouterOptions(idproduit,qte,prix,url) {
fetch(`${url}/tousoption/${idproduit}`)
.then(response=> response.json())
.then(data=>{
var templ="";
var tousId=[];
console.log("cocher",data.opt_pre);
for (let i = 0; i < data.options.length; i++) {
tousId.push(data.options[i].id);
templ+=`<div class="oneOptionFP">
<div class="row">
<div class="col-4">
<img id="optionbtn1img" src="/upload/produits/${data.options[i].image1}" style="height:50px;border-radius:2px">
</div>
<div class="col-4">
<img id="optionbtn1img" src="/upload/produits/${data.options[i].image2}" style="height:50px;border-radius:2px">
</div>
</div>
<div class="custom-checkbox my-1" style="position: relative">
<input type="checkbox" data-price="${data.options[i].price}" data-id="${data.options[i].id}" name="" value="" class="custom-control-input checkboxFP" id="checkboFP_${[i]}">
<label class="custom-control-label position-relative" for="checkboFP_${[i]}">
<strong style="margin-left: 31px;">${data.options[i].price}</strong>
<span>-
${data.options[i].name}</span>
</label>
<button class="btn" id="boutonModif_${[i]}" onclick="modifOption('${data.options[i].id}');" type="button" style="display: none">Modifier</button>
</div>
</div>`;
}
$('#id_produit').val(idproduit);
$('#price_produit').val(prix);
$('#qte_produit').val(qte);
$('#modifAchatFairePart').modal("show");
$('#tousOptions').html(templ);
for (let k = 0; k < tousId.length; k++) {
console.log('atooo',tousId,tousId.length);
console.log('dataio',data.opt_pre);
// for (let a = 0; a < data.opt_pre.length; a++) {
// console.log('avvvvvi',data.opt_pre.length);
for(var i in data.opt_pre) {
if(tousId[k]== data.opt_pre[i].idoption){
console.log("tonga aty ihany");
$('#checkboFP_'+[k]).prop('checked', true);
}
}
// }
for (const key in $('#checkboFP_'+[k])) {
if ($('#checkboFP_'+[k])[key].checked) {
$('#boutonModif_'+[k]).attr("style", "display: block !important");
}
else{
var evt = document.getElementById('checkboFP_'+[k]);
evt.addEventListener('change',(event) => {
if (event.target.checked) {
$('#boutonModif_'+[k]).attr("style", "display: block !important");
}else{
$('#boutonModif_'+[k]).attr("style", "display: none !important");
$(".forme_options").attr("style", "display: none !important")
$(".m-info").attr("style", "display: block !important")
}
});
}
}
}
});
}
function modifOption(idopt) {
var url = window.location.href.split('/');
var param_url = url[0]+'//'+url[2];
fetch(`${param_url}/option/${idopt}`)
.then(response=> response.json())
.then(data=>{
$(".m-info").attr("style", "display: none !important")
$(".forme_options").attr("style", "display: block !important")
$(".nice-select").attr("style", "display: none !important");
$("#id_optionFP").val(idopt);
$("#name_optionFP").val(data.options.name);
$("#image_optionFP").val(data.options.image1);
if ( typeof data.options.colorsOption != "undefined" && data.options.colorsOption != null && data.options.colorsOption.length != null && data.options.colorsOption.length > 0) {
var colorso ="";
for (let i = 0; i < data.options.colorsOption.length; i++) {
colorso +='<option>'+ data.options.colorsOption[i]+'</option>'
}
$("#optionFP_color").html(colorso);
$(".optionFP_color").attr("style", "display: block !important");
$("#optionFP_color").attr("style", "display: block !important");
}
else{
$(".optionFP_color").attr("style", "display: none !important");
}
if (typeof data.options.format != "undefined" && data.options.format != null && data.options.format.length != null && data.options.format.length > 0) {
var formatopt ="";
for (let i = 0; i < data.options.format.length; i++) {
formatopt +='<option>'+data.options.format[i]+'</option>'
}
$("#optionFP_format").html(formatopt);
$(".optionFP_format").attr("style", "display: block !important");
$("#optionFP_format").attr("style", "display: block !important");
}
else{
$(".optionFP_format").attr("style", "display: none !important");
}
if (typeof data.options.finition != "undefined" && data.options.finition != null && data.options.finition.length != null && data.options.finition.length > 0) {
var finitions ="";
for (let i = 0; i < data.options.finition.length; i++) {
finitions +='<option>'+data.options.finition[i]+'</option>'
}
$("#optionFP_finition").html(finitions);
$(".optionFP_finition").attr("style", "display: block !important");
$("#optionFP_finition").attr("style", "display: block !important");
}
else{
$(".optionFP_finition").attr("style", "display: none !important");
}
if (typeof data.options.papier != "undefined" && data.options.papier != null && data.options.papier.length != null && data.options.papier.length > 0) {
var papiers ="";
for (let i = 0; i < data.options.papier.length; i++) {
papiers +='<option>'+data.options.papier[i]+'</option>'
}
$("#optionFP_papier").html(papiers);
$(".optionFP_papier").attr("style", "display: block !important");
$("#optionFP_papier").attr("style", "display: block !important");
}
else{
$(".optionFP_papier").attr("style", "display: none !important");
}
if (typeof data.options.quantite != "undefined" && data.options.quantite != null && data.options.quantite.length != null && data.options.quantite.length > 0) {
var quantites ="";
for (let i = 0; i < data.options.quantite.length; i++) {
quantites +='<option>'+data.options.quantite[i]+'</option>'
}
$("#optionFP_quantite").html(quantites);
$(".optionFP_quantite").attr("style", "display: block !important");
$("#optionFP_quantite").attr("style", "display: block !important");
}
else{
$(".optionFP_quantite").attr("style", "display: none !important");
}
if (typeof data.options.etiquette != "undefined" && data.options.etiquette != null && data.options.etiquette.length != null && data.options.etiquette.length > 0) {
var etiquettes ="";
for (let i = 0; i < data.options.etiquette.length; i++) {
etiquettes +='<option>'+data.options.etiquette[i]+'</option>'
}
$("#optionFP_etiquette").html(etiquettes);
$(".optionFP_etiquette").attr("style", "display: block !important");
$("#optionFP_etiquette").attr("style", "display: block !important");
}
else{
$(".optionFP_etiquette").attr("style", "display: none !important");
}
if (typeof data.options.ruban != "undefined" && data.options.ruban != null && data.options.ruban.length != null && data.options.ruban.length > 0) {
var rubans ="";
for (let i = 0; i < data.options.ruban.length; i++) {
rubans +='<option>'+data.options.ruban[i]+'</option>'
}
$("#optionFP_ruban").html(rubans);
$(".optionFP_ruban").attr("style", "display: block !important");
$("#optionFP_ruban").attr("style", "display: block !important");
}
else{
$(".optionFP_ruban").attr("style", "display: none !important");
}
});
}
function Anulleroption() {
$(".forme_options").attr("style", "display: none !important")
$(".m-info").attr("style", "display: block !important")
}
function validechoioption() {
$(".forme_options").attr("style", "display: none !important")
$(".m-info").attr("style", "display: block !important")
const data = {
idoption: $("#id_optionFP").val(),
nomoption: $("#name_optionFP").val(),
imageoption: $("#image_optionFP").val(),
color: $("#optionFP_color").val(),
form: $("#optionFP_format").val(),
finition: $("#optionFP_finition").val(),
papier: $("#optionFP_papier").val(),
quantite: $("#optionFP_quantite").val(),
etiquette: $("#optionFP_etiquette").val(),
ruban: $("#optionFP_ruban").val(),
};
localStorage.setItem($("#id_optionFP").val(), JSON.stringify(data));
}
function validechoiModaloption() {
var url = window.location.href.split('/');
var param_url = url[0]+'//'+url[2];
const formData = new FormData();
var idProduit = $('#id_produit').val();
formData.append("quantity",$('#qte_produit').val());
formData.append("price",$('#price_produit').val());
if (Object.keys(localStorage).length != 0) {
var values = [],
keys = Object.keys(localStorage),
i = keys.length;
while ( i-- ) {
values.push( localStorage.getItem(keys[i]) );
localStorage.removeItem(keys[i]);
}
formData.append("tail",values.length);
console.log("zzzzz",values);
for (let j = 0; j < values.length; j++) {
formData.append("OpId_"+j, values[j]);
}
}
var checkOpt = document.querySelectorAll('.checkboxFP');
console.log("fff", checkOpt);
console.log("eee", checkOpt.length);
var valeur=[];
for (var p = 0; p < checkOpt.length; p++) {
if (checkOpt[p].checked) {
var idOpt = checkOpt[p].getAttribute('data-id');
valeur.push(idOpt);
}
}
formData.append("idoptions",valeur);
fetch(`${param_url}/updateOptionFairepart/${idProduit}`, {
method: "POST",
body: formData
})
.then(response=> response.json())
.then(data=>{
console.log('data_io',data);
if (data.message == "ok") {
window.location.reload();
}
$("#modifAchatFairePart").modal("hide");
});
}
</script>
{% endblock %}