src/Flexy/FrontBundle/Themes/IlaveU/templates/cart/cart.html.twig line 1

  1. {% extends "@Flexy/FrontBundle/Themes/IlaveU/templates/layout.html.twig"  %}
  2. {% block stylesheets %}
  3.     {{parent()}}
  4.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.css" integrity="sha512-wJgJNTBBkLit7ymC6vvzM1EcSWeM9mmOu+1USHaRBbHkm6W9EgM0HY27+UtUaprntaYQJF75rc8gjxllKs5OIQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
  5.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css" integrity="sha512-tS3S5qG0BlhnQROyJXvNjeEM4UpMXHrQfTGmbQ1gKmelCxlSEBUaxhRBj/EFTzpbP4RVSrpEikbmdJobCvhE3g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
  6.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.min.css" integrity="sha512-sMXtMNL1zRzolHYKEujM2AqCLUR9F2C4/05cdbxjjLSRvMQIciEPCQZo++nk7go3BtSuK9kfa/s+a4f4i5pLkw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
  7. {% endblock %}
  8. {% block body %}
  9.     <style>
  10. #collectMap,#shippingMap {
  11.   width: 100%;
  12.   height: 400px;
  13. }
  14.     .pay-with-wallet .item{
  15.         padding:10px 7px;
  16.         margin:0 10px;
  17.         font-weight:bold;
  18.         background:#45dae9;
  19.         color:white;
  20.         border-radius:50px;
  21.         text-align:center;
  22.         font-size:14px;
  23.     }
  24.     .pay-with-wallet .item.selected{
  25.         
  26.         background:#febc4a;
  27.     }
  28.     .tips-shipping-agent .item{
  29.         padding:10px 15px;
  30.         margin:0 10px;
  31.         font-weight:bold;
  32.         background:#45dae9;
  33.         color:white;
  34.         border-radius:50px;
  35.         text-align:center;
  36.     }
  37.     .tips-shipping-agent .item.selected{
  38.         
  39.         background:#febc4a;
  40.     }
  41. .owl-carousel .owl-nav button.owl-next, .owl-carousel .owl-nav button.owl-prev, .owl-carousel button.owl-dot{
  42.     background:#d5d5d5;
  43. }
  44. .owl-dots {
  45.      bottom:-35px; 
  46. }
  47.     .choices-shipping{
  48.         font-size:13px;
  49.     }
  50.    .choices-shipping div div {
  51.     /* border: 2px dotted #ccc; */
  52.     padding: 20px;
  53.     background: #f2f2f2;
  54. }
  55.     .choices-shipping div div.active {
  56.     background-color: #45dae9;
  57.     border-color: #29cedf;
  58.     color: white;
  59. }
  60.     
  61.     .jq-toast-wrap {
  62.     display: block;
  63.     position: fixed;
  64.     width: 500px;
  65.     pointer-events: none!important;
  66.     letter-spacing: normal;
  67.     z-index: 9000!important;
  68. }
  69. .jq-icon-warning {
  70.     
  71.     background-color: #9a0062;
  72. }
  73.     </style>
  74.     <div 
  75.         class="body-wrapper" >
  76.         <!-- Begin Li's Breadcrumb Area -->
  77.         <div class="breadcrumb-area">
  78.             <div class="container">
  79.                 <ul id="progressbar">
  80.                     <li class="active">Livraison
  81.                     </li>
  82.                     <li>Paiement et coordonnées</li>
  83.                     <li>Resumé</li>
  84.                 </ul>
  85.             </div>
  86.         </div>
  87.         <!-- Li's Breadcrumb Area End Here -->
  88.         <!--Shopping Cart Area Strat-->
  89.         <div class="Shopping-cart-area pt-60 pb-60">
  90.             <div class="container">
  91.                 <div class="row ">
  92.                     <div class="col-12">
  93.                         <form action="#">
  94.                             <div class="table-content table-responsive d-none">
  95.                                 <table class="table table-striped">
  96.                                     <thead>
  97.                                         <tr>
  98.                                             <th class="li-product-remove">Supprimer</th>
  99.                                             <th class="li-product-thumbnail">images</th>
  100.                                             <th class="cart-product-name">Product</th>
  101.                                             <th class="li-product-price">Prix unitaire</th>
  102.                                             <th class="li-product-quantity">Quantité</th>
  103.                                             <th class="li-product-subtotal">Total</th>
  104.                                         </tr>
  105.                                     </thead>
  106.                                     <tbody
  107.                                         class="cart"><!-- LocalStorage Cart Items -->
  108.                                     </tbody>
  109.                                 </table>
  110.                             </div>
  111.                             
  112.                                                 
  113.                             <div class="row">
  114.                                 <div class="col-md-7 ">
  115.                                     <div class="row">
  116.                                     <div class="col-12">
  117.                                     <!--Accordion Start-->
  118.                                 <p style="font-weight:bold;">Avez-vous un code promo? <span id="showcoupon" style="cursor:pointer;">Cliquez ici pour saisir votre code</span></p>
  119.                                 <div id="checkout_coupon" class="coupon-checkout-content">
  120.                                     <div class="coupon-info">
  121.                                         <div class="input-group">
  122.                                             <input type="text" class="form-control" placeholder="Votre code promo" data-coupon-value="0" data-coupon-type="amount" name="codeCoupon" aria-label="Recipient's username" aria-describedby="button-codeCoupon" value="">
  123.                                             <button class="btn btn-success orderPreview" type="button" id="button-codeCoupon">Appliquer</button>
  124.                                         </div>
  125.                                         </div>
  126.                                     </div>
  127.                                     </div>
  128.                                 </div>
  129.                                 <!--Accordion End-->
  130.                                         
  131.                                     
  132.                                 
  133.                                     <div class="row choices-shipping" style="margin-bottom:40px; ">
  134.                                             {% for singleShippingMethod in shippingMethods %}
  135.                                                 <div  class="col-6 mt-4" >
  136.                                                    <div style="min-height:180px;" data-id="{{singleShippingMethod.id}}" class="shippingMethod {% if singleShippingMethod == shippingMethods|first %}active{% endif %}">
  137.                                                      <h4>{{singleShippingMethod.name}}</h4>
  138.                                                     <ul>
  139.                                                     <li>
  140.                                                         {% set shippingDurationValue = singleShippingMethod.shippingDuration %}
  141.                                                         {% set shippingDurationUnit = "H" %}
  142.                                                     {% if shippingDurationValue < 1 %}
  143.                                                         {% set shippingDurationValue = 60 * singleShippingMethod.shippingDuration  %}
  144.                                                         {% set shippingDurationUnit = "Min" %}
  145.                                                     {% endif %}
  146.                                                     Temps d’attente du Speeder <span class="float-right slot">{{shippingDurationValue}} {{shippingDurationUnit}}</span></li>
  147.                                                     <li  class="">Récuperation de la commande <span class="float-right">{{singleShippingMethod.preparationDuration}} H</span></li>
  148.                                                     <li>Livraison en <span class="float-right">{{singleShippingMethod.processingDuration}} H</span></li>
  149.                                                     {% if singleShippingMethod.shippingRules|length > 0 %}
  150.                                                     <li style="line-height: 15px;"><small>{{singleShippingMethod.description}}</small></li>
  151.                                                     {% endif %}
  152.                                                 </ul>
  153.                                                    </div>
  154.                                                 
  155.                                                 </div>
  156.                                                 {% endfor %}
  157.                                                 
  158.                                             </div>
  159.                                     <div class="row" >
  160.                                     <div class="item aos-init aos-animate  col-6" id="accordionRecovery" data-aos="fade-up">
  161.                                         <h6>Informations de récupération</h6>
  162.                                         <div class="bg-white">
  163.                                             <div class="row">
  164.                                                 <div class="box col-sm-5 col-md-12 col-lg-5">
  165.                                                     <label>Date</label>
  166.                                                     <div class="d-flex">
  167.                                                         <input type="text" class="form-control datedropper chooseDate"  data-dd-min-date="{{"now"|date('Y/m/d')}}" value="{{"now"|date('Y/m/d')}}" name="startProcessingAt"    />
  168.                                                         
  169.                                                     </div>
  170.                                                 </div>
  171.                                                 <div class="box col-sm-7 col-md-12 col-lg-7">
  172.                                                     <label>Heure</label>
  173.                                                     <span id="recovery_slot">
  174.                                                         <select id="receive_time" class="custom-select custom-select-recieve" name="collectTime" data-day="0">
  175.                                                             <option value="08:00" >Sélectionner un crénau</option>
  176.                                                         </select>
  177.                                                     </span>
  178.                                                 </div>
  179.                                             </div>
  180.                                             
  181.                                             <div class="row justify-content-center">
  182.                                                 <div class="form-group box col-sm-12">
  183.                                                     <label>
  184.                                                         <b>Adresse de récupération</b>
  185.                                                     </label>
  186.                                                     <!-- Button trigger modal -->
  187.                                                     
  188.                                                         <select class="mb-2" name="collectCityRegion" >
  189.                                                             {% for cityRegion in cityRegions %}
  190.                                                                 <option data-lat="{{cityRegion.lat}}" data-lng="{{cityRegion.lng}}" value="{{cityRegion.id}}">{{cityRegion.name}}</option>
  191.                                                             {% endfor %}
  192.                                                         </select>
  193.                                                         <input type="text" id="collect_address" name="collect_address" value="Maarif, Casablanca, Maroc" class="form-control w-100" >
  194.                                                         <a  href="#" id="modalShippingMap" type="button"  data-bs-toggle="modal" data-bs-target="#collectMapModal" class="btn btn-success mt-2"  style="" ><i class="fa-solid fa-location-dot"></i> Location</a>
  195.     
  196.                                                 </div>
  197.                                             </div>
  198.                                         </div>
  199.                                     </div>
  200.                                     <div class="item aos-init aos-animate col-6" id="accordionRecovery" data-aos="fade-up">
  201.                                         <h6>Informations de livraison</h6>
  202.                                         <div class="bg-white"> 
  203.                                             
  204.                                             <div class="row">
  205.                                                 <div class="box col-sm-5 col-md-12 col-lg-5">
  206.                                                     <label>Date</label>
  207.                                                     <div class="d-flex">
  208.                                                         <input type="text" class="form-control datedropper chooseDate"  name="startDeliveryAt" value="{{"now"|date('Y/m/d')}}"   />
  209.                                                         
  210.                                                     </div>
  211.                                                 </div>
  212.                                                 <div class="box col-sm-7 col-md-12 col-lg-7">
  213.                                                     <label>Heure</label>
  214.                                                     <span id="recovery_slot">
  215.                                                         <select id="receive_time" class="custom-select custom-select-recieve" name="shippingTime" data-day="0">
  216.                                                             <option value="08:00" >Sélectionner un crénau</option>
  217.                                                         </select>
  218.                                                     </span>
  219.                                                 </div>
  220.                                             </div>
  221.                                             
  222.                                             <div class="row justify-content-center">
  223.                                                 <div class="form-group box col-sm-12">
  224.                                                     <label>
  225.                                                         <b>Adresse de livraison</b>
  226.                                                     </label>
  227.                                                     
  228.                                                         <select class="mb-2" name="shippingCityRegion" >
  229.                                                             {% for cityRegion in cityRegions %}
  230.                                                                 <option data-lat="{{cityRegion.lat}}" data-lng="{{cityRegion.lng}}" value="{{cityRegion.id}}">{{cityRegion.name}}</option>
  231.                                                             {% endfor %}
  232.                                                         </select>
  233.                                                         <input type="text" id="shipping_address" name="shipping_address" value="Maarif, Casablanca, Maroc" class="form-control w-100 " />
  234.                                                             
  235.                                                         
  236.                                                     
  237.                                                     <a href="#" id="modalShippingMap" type="button"  data-bs-toggle="modal" data-bs-target="#collectMapModal" class="btn btn-success mt-2" style="" ><i class="fa-solid fa-location-dot"></i> Location</a>
  238.                                                 </div>
  239.                                             </div>
  240.                                         </div>
  241.                                     </div>
  242.                                     
  243.                                     {% if is_granted("ROLE_CUSTOMER") and customer != null %}
  244.                                     <div class="col-12 mt-5" >
  245.                                         <h6>Payer avec ma wallet {{customer.credit}} DH</h6>
  246.                                         <div class="owl-carousel pay-with-wallet d-none mt-4">
  247.                                             {% if customer.credit > 0 %}
  248.                                             {% set counterCredit = 0 %}
  249.                                                     {% for i in 0..totalCart %}
  250.                                                         {% if
  251.                                                          (customer.credit >= i and customer.credit <= totalCart) or
  252.                                                          (customer.credit >= i and customer.credit >= totalCart)
  253.                                                          %}
  254.                                                             <div data-value="{{i}}" class="item"> {{i}} DH</div>
  255.                                                             {% set counterCredit = counterCredit + i %}
  256.                                                          {% endif %}
  257.                                                 
  258.                                             {% endfor %}
  259.                                             {% endif %}
  260.                                             
  261.                                             
  262.                                             </div>
  263.                                     </div>
  264.                                     {% endif %}
  265.                                     </div>
  266.                                     
  267.                                     <hr>
  268.                                     
  269.                                 </div>
  270.                                  <div class="col-lg-5 col-12">
  271.                             <div class="your-order">
  272.                                 <h3>Votre commande</h3>
  273.                                 <div class="shipping" >
  274.                                
  275.                                 </div>
  276.                                 <div class="your-order-table table-responsive">
  277.                                     <table class="table">
  278.                                         <thead>
  279.                                             <tr>
  280.                                                 <th class="cart-product-name">Produit</th>
  281.                                                 <th class="cart-product-total">Total</th>
  282.                                             </tr>
  283.                                         </thead>
  284.                                         <tbody class="cart-checkout">
  285.  
  286.                                         </tbody>
  287.                                         <tfoot>
  288.                                             <tr class="cart-subtotal">
  289.                                                 <th>Sous total</th>
  290.                                                 <td><span class="amount total-checkout total">0,00 MAD </span></td>
  291.                                             </tr>
  292.                                             <tr class="cart-subtotal promo">
  293.                                                 <th>Reduction coupon</th>
  294.                                                 <td><span class="amount codepromo">0,00 MAD </span></td>
  295.                                             </tr>
  296.                                             {# <tr class="cart-subtotal">
  297.                                                 <th>Paiement par wallet</th>
  298.                                                 <td><span class="amount wallet-payment">0,00 MAD </span></td>
  299.                                             </tr> #}
  300.                                             {# <tr class="cart-subtotal">
  301.                                                 <th>Pourboire pour le livreur</th>
  302.                                                 <td><span class="amount shipping-tips">0,00 MAD </span></td>
  303.                                             </tr> #}
  304.                                             
  305.                                             <tr class="cart-subtotal">
  306.                                                 <th>Frais de livraison</th>
  307.                                                 <td><span class="amount shipping-method-fees">0,00 MAD </span></td>
  308.                                             </tr>
  309.                                             <tr class="order-total">
  310.                                                 <th>Montant á payer</th>
  311.                                                 <td><strong><span class="amount total-checkout total-to-pay ">0,00 MAD</span></strong></td>
  312.                                             </tr>
  313.                                             
  314.                                             <tr>
  315.                                                 <td colspan="2" ><a href="#" class="save-button btn btn-primary d-block">Continuer</a></td>
  316.                                             </tr>
  317.                                         </tfoot>
  318.                                     </table>
  319.                                     
  320.                                 </div>
  321.                                 
  322.                             </div>
  323.                         </div>
  324.                             </div>
  325.                         </form>
  326.                     </div>
  327.                 </div>
  328.             </div>
  329.         </div>
  330.         <!--Shopping Cart Area End-->
  331.     </div>
  332.     <!-- Body Wrapper End Here -->
  333.     <!-- Button trigger modal -->
  334. {% endblock %}
  335. {% block javascripts %}
  336.     {{parent()}}
  337.     <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBFliT4Ug0Ugto5davRC7krsyMhTfkI-L4&libraries=places"></script>
  338.     <script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js" integrity="sha512-bPs7Ae6pVvhOSiIcyUClR7/q2OAsRiovw4vAkX+zJbw3ShAeeqezq50RIIcIURq7Oa20rW2n2q+fyXBNcU9lrw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  339.     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.js" integrity="sha512-zlWWyZq71UMApAjih4WkaRpikgY9Bz1oXIW5G0fED4vk14JjGlQ1UmkGM392jEULP8jbNMiwLWdM8Z87Hu88Fw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  340.     <script src="{{asset('flexy/js/datedropper/datedropper-javascript.js')}}"></script>
  341. <script src="{{asset('flexy/js/datedropper/datedropper-javascript-lang-FR.js')}}"></script>
  342.     <script>
  343.     document.addEventListener("turbo:load", function() {
  344. var isCollectReadyForCheckout = false;
  345. var isShippingReadyForCheckout = false;
  346. new dateDropper({
  347.   lang:"fr",
  348.   //format: "dd/m/y",
  349.   selector: "input[name='startProcessingAt']",
  350.   minDate: "{{"yesterday"|date("Y-m-d")}}",
  351.   //autoFill:false,
  352.   expandable: true,
  353.   onChange: function (res) {
  354.     $("input[name='startProcessingAt']").trigger("change");
  355.   }
  356. });
  357. new dateDropper({
  358.   lang:"fr",
  359.   //format: "dd/m/y",
  360.   selector: "input[name='startDeliveryAt']",
  361.   //autoFill:false,
  362.   expandable: true,
  363.   onChange: function (res) {
  364.     $("input[name='startProcessingAt']").trigger("change");
  365.   }
  366. });
  367. $(document).ready(function(){  
  368.     
  369.   $(".tips-shipping-agent").owlCarousel({
  370.     dots:true,
  371.     items:5,
  372.     nav:false,
  373.     onChanged:function(){
  374.         $(".tips-shipping-agent").removeClass("d-none");
  375.     }
  376.   });
  377.   $(".pay-with-wallet").owlCarousel({
  378.     dots:true,
  379.     items:7,
  380.     nav:false,
  381.     onChanged:function(){
  382.         $(".pay-with-wallet").removeClass("d-none");
  383.     }
  384.   });
  385.   
  386.     $(".pay-with-wallet .item").click(function(){
  387.     $(".pay-with-wallet .item").removeClass("selected");
  388.      $(this).addClass("selected");
  389.      walletPayment = parseFloat($(this).attr("data-value"));
  390.      
  391.      $(".wallet-payment").html( (walletPayment) + " DH");
  392.      $(".total-to-pay").html( ((total) - (amount) - (reductionCoupon) - (walletPayment)) + (shippingFees) + (shippingTips) + " DH");
  393.   });
  394.        var inputCollectAddress = document.getElementById('collect_address');
  395.        var inputShippingAddress = document.getElementById('shipping_address');
  396.        
  397. var optionsCollect = {
  398.   //types: ['(cities)'],
  399.   componentRestrictions: {country: 'ma'}
  400. };
  401. var optionsShipping = {
  402.   //types: ['(cities)'],
  403.   componentRestrictions: {country: 'ma'}
  404. };
  405.  var centerLatCollect = $("select[name='collectCityRegion']").find("option:selected").attr("data-lat"); // example latitude
  406.   var centerLngCollect = $("select[name='collectCityRegion']").find("option:selected").attr("data-lng"); // example longitude
  407.    var centerLatShipping =$("select[name='shippingCityRegion']").find("option:selected").attr("data-lat"); // example latitude
  408.   var centerLngShipping =$("select[name='shippingCityRegion']").find("option:selected").attr("data-lng"); // example longitude
  409. var centerPointCollect = new google.maps.LatLng(centerLatCollect, centerLngCollect);
  410. var centerPointShipping = new google.maps.LatLng(centerLatShipping, centerLngShipping);
  411. // Set the desired radius in meters
  412. var radius = 10000; // 10 kilometers
  413. var boundsCollect = new google.maps.Circle({ center: centerPointCollect, radius: radius }).getBounds();
  414. var boundsShipping = new google.maps.Circle({ center: centerPointCollect, radius: radius }).getBounds();
  415.   $("select[name='collectCityRegion']").change(function(){
  416.     centerLatCollect = $("select[name='collectCityRegion']").find("option:selected").attr("data-lat");
  417.     
  418.     centerLngCollect = $("select[name='collectCityRegion']").find("option:selected").attr("data-lng");
  419.      centerPointCollect = new google.maps.LatLng(centerLatCollect, centerLngCollect);
  420.      boundsCollect = new google.maps.Circle({ center: centerPointCollect, radius: radius }).getBounds();
  421.   });
  422.     $("select[name='shippingCityRegion']").change(function(){
  423.     centerLatShipping = $("select[name='shippingCityRegion']").find("option:selected").attr("data-lat");
  424.     centerLngShipping = $("select[name='shippingCityRegion']").find("option:selected").attr("data-lng");
  425.      centerPointShipping = new google.maps.LatLng(centerLatShipping, centerLngShipping);
  426.      boundsShipping = new google.maps.Circle({ center: centerPointCollect, radius: radius }).getBounds();
  427.     
  428.   });
  429. var autocompleteCollect = new google.maps.places.Autocomplete(inputCollectAddress, optionsCollect);
  430. var autocompleteShipping = new google.maps.places.Autocomplete(inputShippingAddress, optionsShipping);
  431. google.maps.event.addListener(autocompleteCollect, 'place_changed', function() {
  432.     
  433.     
  434.     var lngCollect = autocompleteCollect.getPlace().geometry.location.lng();
  435.     var latCollect = autocompleteCollect.getPlace().geometry.location.lat();
  436.         if (autocompleteCollect.getPlace() && boundsCollect && boundsCollect.contains(autocompleteCollect.getPlace().geometry.location)) {
  437.             // Place falls within the specified radius
  438.             isCollectReadyForCheckout = true;
  439.             console.log('Place collect is within the specified radius:', autocompleteCollect.getPlace());
  440.         } else {
  441.             isCollectReadyForCheckout = false;
  442.             // Place is outside the specified radius
  443.             console.log('Place collect is outside the specified radius:', autocompleteCollect.getPlace());
  444.         }
  445.     
  446. });
  447. google.maps.event.addListener(autocompleteShipping, 'place_changed', function() {
  448.     
  449.     
  450.     var lngShipping = autocompleteShipping.getPlace().geometry.location.lng();
  451.     var latShipping = autocompleteShipping.getPlace().geometry.location.lat();
  452.     if (autocompleteShipping.getPlace() && boundsShipping && boundsShipping.contains(autocompleteShipping.getPlace().geometry.location)) {
  453.             // Place falls within the specified radius
  454.             isShippingReadyForCheckout = true;
  455.             console.log('Place shipping is within the specified radius:', autocompleteShipping.getPlace());
  456.         } else {
  457.              isShippingReadyForCheckout = false;
  458.             // Place is outside the specified radius
  459.             console.log('Place shipping is outside the specified radius:', autocompleteShipping.getPlace());
  460.         }
  461.     
  462. });
  463.     
  464.     $(".choices-shipping div div").click(function(){
  465.         
  466.             $(".choices-shipping div div").removeClass("active");
  467.             $(this).addClass("active");
  468.         
  469.             total = cartLS.total();
  470.             var value = $(this).val();
  471.             //shippingFees = parseFloat($(this).find(":selected").attr("data-price")) ;
  472.             //$(".shipping-method-fees").html(shippingFees+ " DH");
  473.             //$(".total-to-pay").html(((total) - (amount) - (reductionCoupon)) + (shippingFees) + " DH");
  474.             //$("#cash").trigger("keyup");
  475.             $("input[name='startDeliveryAt']").val($("input[name='startProcessingAt']").val());
  476.             $("input[name='startProcessingAt']").trigger("change");
  477.     });
  478.     $(".save-button").click(function(){
  479.     
  480.     if((isCollectReadyForCheckout && isShippingReadyForCheckout) || 1 == 1){
  481.         
  482.    
  483.                         
  484.                         
  485. $.ajax({
  486.                             url:"{{path('pos_cart_checkout')}}",
  487.                             method:"POST",
  488.                             data:{
  489.                                 
  490.                                 
  491.                                 orderItems: cartLS.list(),
  492.                                 shippingMethod:$(".shippingMethod.active").attr("data-id"),
  493.                                 deliveryType:"collecte-and-delivery",
  494.                                 
  495.                                 
  496.                                 //reduction:$("#reduction").val(),
  497.                                 //payedAmount:$("#cash").val(),
  498.                                 codeCoupon:$("input[name=codeCoupon]").val(),
  499.                                 startProcessingAt: $("input[name=startProcessingAt]").val()+" "+$("select[name='collectTime']").find("option:selected").val(),
  500.                                 startDeliveryAt:$("input[name=startDeliveryAt]").val()+" "+$("select[name='shippingTime']").find("option:selected").val(),
  501.                                 shippingAddress:$("input[name=shipping_address]").val(),
  502.                                 collectAddress:$("input[name=collect_address]").val(),
  503.                                 cityRegionCollect:$("select[name='collectCityRegion']").find("option:selected").val(),
  504.                                 cityRegionShipping:$("select[name='shippingCityRegion']").find("option:selected").val(),
  505.                                 shippingTips:parseFloat($(".tips-shipping-agent .item.selected").attr("data-value")),
  506.                                 walletPaymentAmount:parseFloat($(".pay-with-wallet .item.selected").attr("data-value")),
  507.                                 isReadyForCheckout: true
  508.                                 
  509.                             },
  510.                             success:function(result){
  511.  
  512.                                if(result.status == "success");
  513.                                window.location.href = "{{path('checkout')}}";
  514.                             }
  515.                         });    
  516.  }else{
  517. $.toast({
  518.                                             heading: 'Merci de verifier vos cordonnées',
  519.                                             text: "Vos cordonnées quartiers ou adresses ne sont pas valident merci de verifier !",
  520.                                             showHideTransition: 'slide',
  521.                                             hideAfter:12000,
  522.                                             icon: 'warning',
  523.                                             loaderBg: '#1ca5df', 
  524.                                             position:"top-right",
  525.                                             allowToastClose: true,
  526.                                             stack: false
  527.                                     })
  528.  }
  529.    
  530. });
  531.     $("input[name='startProcessingAt']").change(function(){
  532.    
  533. $.toast().reset('all');
  534.     
  535.                         
  536.     $(".checkout-area").html("");
  537.     
  538.     var isWallet = 0;
  539.     if($("#isWallet").is(':checked')){
  540.         isWallet = 1;
  541.     }
  542.                         
  543. $.ajax({
  544.                             url:"{{path('pos_cart_checkout')}}",
  545.                             method:"POST",
  546.                             data:{
  547.                                 
  548.                                 orderItems: cartLS.list(),
  549.                                 shippingMethod:$(".shippingMethod.active").attr("data-id"),
  550.                                 deliveryType:"collecte-and-delivery",
  551.                                 
  552.                                 
  553.                                 //reduction:$("#reduction").val(),
  554.                                 //payedAmount:$("#cash").val(),
  555.                                 codeCoupon:$("input[name=codeCoupon]").val(),
  556.                                 startProcessingAt: $("input[name=startProcessingAt]").val()+" "+$("select[name='collectTime']").find("option:selected").val(),
  557.                                 startDeliveryAt:$("input[name=startDeliveryAt]").val()+" "+$("select[name='shippingTime']").find("option:selected").val(),
  558.                                 isChooseDatePreview: true
  559.                                 
  560.                             },
  561.                             success:function(result){
  562.                                 
  563.                                 $("input[name='startDeliveryAt']").attr("data-dd-opt-min-date",result.minDateShipping);
  564.                                 $("input[name='startDeliveryAt']").attr("data-dd-opt-max-date","{{ "next year"| date('Y-m-d') }}");
  565.                                 $("input[name='startDeliveryAt']").attr("data-dd-opt-default-date",result.shippingDate);
  566.                                 
  567.                                 //$("#shipping-method").find("option:selected").attr("data-price",result.shippingFees);
  568.                                 shippingFees = parseFloat(result.shippingFees) ;
  569.                                 $(".shipping-method-fees").html(shippingFees.toFixed(2)+ " DH");
  570.                                 $(".total-to-pay").html(((total) - (amount) - (reductionCoupon)) + (shippingFees) + (shippingTips) + " DH");
  571.                                 //$("select[name='collectTime']").modal('show');
  572.                                 $("select[name='collectTime']").html(result.collectHoursHTML);
  573.                                 $("select[name='shippingTime']").html(result.shippingHoursHTML);
  574.                                 $("input[name='startProcessingAt']").val(result.collectDate);
  575.                                 $("input[name='startDeliveryAt']").val(result.shippingDate);
  576.                                 
  577.                                 /*         
  578.                                 $("input[name='startDeliveryAt']").dateDropper({
  579.                                     large: true,
  580.                                     lang: 'fr',
  581.                                     theme: 'datedropper',
  582.                                     format: "d-m-Y",
  583.                                     expandable: true,
  584.                                     rangeStart: result.shippingDate,
  585.                                     rangeEnd: "{{ " next year "|date('Y/m/d') }}",
  586.                                     disabledDays: "{{settings.get().getExcludeDatesOnlyDates()|join(',')}}",
  587.                                     disabledWeekDays: '6'
  588.                                 });
  589.                                     */
  590.                                 
  591.                                 if(result.messages.length > 0){
  592.                                     $.toast({
  593.                                             heading: 'Décalage de date',
  594.                                             text: result.messages,
  595.                                             showHideTransition: 'slide',
  596.                                             hideAfter:12000,
  597.                                             icon: 'warning',
  598.                                             loaderBg: '#1ca5df', 
  599.                                             position:"top-right",
  600.                                             allowToastClose: true,
  601.                                             stack: false
  602.                                     })
  603.                                    
  604.                                 }
  605.                             }
  606.                         });                 
  607.     
  608. });
  609.     $("input[name='startDeliveryAt']").change(function(){
  610.    
  611. $.toast().reset('all');
  612.     
  613.     var isWallet = 0;
  614.     if($("#isWallet").is(':checked')){
  615.         isWallet = 1;
  616.     }
  617.                         
  618. $.ajax({
  619.                             url:"{{path('pos_cart_checkout')}}",
  620.                             method:"POST",
  621.                             data:{
  622.                                 
  623.                                 orderItems: cartLS.list(),
  624.                                 shippingMethod:$(".shippingMethod.active").attr("data-id"),
  625.                                 deliveryType:$("select[name='delivery-type'] option:selected").val(),
  626.                                 
  627.                                 
  628.                                 //reduction:$("#reduction").val(),
  629.                                 //payedAmount:$("#cash").val(),
  630.                                 startProcessingAt: $("input[name=startProcessingAt]").val()+" "+$("select[name='collectTime']").find("option:selected").val(),
  631.                                 startDeliveryAt:$("input[name=startDeliveryAt]").val()+" "+$("select[name='shippingTime']").find("option:selected").val(),
  632.                                 isChooseDatePreview: true
  633.                                 
  634.                             },
  635.                             success:function(result){
  636.                                 
  637.                                 $("input[name='startDeliveryAt']").attr("data-dd-opt-min-date",result.minDateShipping);
  638.                                 $("input[name='startDeliveryAt']").attr("data-dd-opt-max-date","{{ "next year"| date('Y-m-d') }}");
  639.                                 $("input[name='startDeliveryAt']").attr("data-dd-opt-default-date",result.shippingDate);
  640.                                 
  641.                                 //$("#shipping-method").find("option:selected").attr("data-price",result.shippingFees);
  642.                                 shippingFees = parseFloat(result.shippingFees) ;
  643.                                 $(".shipping-method-fees").html(shippingFees.toFixed(2)+ " DH");
  644.                                 $(".total-to-pay").html(((total) - (amount) - (reductionCoupon)) + (shippingFees) + (shippingTips) + " DH");
  645.                                 //$("select[name='collectTime']").modal('show');
  646.                                 //$("select[name='collectTime']").html(result.collectHoursHTML);
  647.                                 $("select[name='shippingTime']").html(result.shippingHoursHTML);
  648.                                 //$("input[name='startProcessingAt']").val(result.collectDate);
  649.                                 $("input[name='startDeliveryAt']").val(result.shippingDate);
  650.                                 $("select[name='shippingTime']").find("option:first").attr("selected",true);
  651.                                 
  652.                                 /*         
  653.                                 $("input[name='startDeliveryAt']").dateDropper({
  654.                                     large: true,
  655.                                     lang: 'fr',
  656.                                     theme: 'datedropper',
  657.                                     format: "d-m-Y",
  658.                                     expandable: true,
  659.                                     rangeStart: result.shippingDate,
  660.                                     rangeEnd: "{{ " next year "|date('Y/m/d') }}",
  661.                                     disabledDays: "{{settings.get().getExcludeDatesOnlyDates()|join(',')}}",
  662.                                     disabledWeekDays: '6'
  663.                                 });
  664.                                     */
  665.                                 
  666.                                 if(result.messages.length > 0){
  667.                                     $.toast({
  668.                                             heading: 'Décalage de date',
  669.                                             text: result.messages,
  670.                                             showHideTransition: 'slide',
  671.                                             hideAfter:12000,
  672.                                             icon: 'warning',
  673.                                             loaderBg: '#1ca5df', 
  674.                                             position:"top-right",
  675.                                             allowToastClose: true,
  676.                                             stack: false
  677.                                     })
  678.                                    
  679.                                 }
  680.                             }
  681.                         });                 
  682.     
  683. });
  684. $("select[name='collectTime']").change(function(){
  685.     
  686.                         
  687.                         
  688. $.ajax({
  689.                             url:"{{path('pos_cart_checkout')}}",
  690.                             method:"POST",
  691.                             data:{
  692.                                 
  693.                                 
  694.                                 orderItems: cartLS.list(),
  695.                                 shippingMethod:$(".shippingMethod.active").attr("data-id"),
  696.                                 deliveryType:$("select[name='delivery-type'] option:selected").val(),
  697.                                 
  698.                                 //reduction:$("#reduction").val(),
  699.                                 //payedAmount:$("#cash").val(),
  700.                                 startProcessingAt: $("input[name=startProcessingAt]").val()+" "+$("select[name='collectTime']").find("option:selected").val(),
  701.                                 startDeliveryAt:$("input[name=startDeliveryAt]").val(),
  702.                                 isChooseDatePreview: true
  703.                                 
  704.                             },
  705.                             success:function(result){
  706.                                 $("input[name='startDeliveryAt']").attr("data-dd-opt-min-date",result.minDateShipping);
  707.                                 $("input[name='startDeliveryAt']").attr("data-dd-opt-max-date","{{ "next year"| date('Y-m-d') }}");
  708.                                 $("input[name='startDeliveryAt']").attr("data-dd-opt-default-date",result.shippingDate);
  709.                                 //$("select[name='collectTime']").modal('show');
  710.                                 //$("select[name='collectTime']").html(result.collectHoursHTML);
  711.                                 $("select[name='shippingTime']").html(result.shippingHoursHTML);
  712.                                 //$("input[name='startProcessingAt']").val(result.collectDate);
  713.                                 $("input[name='startDeliveryAt']").val(result.shippingDate);
  714.                             }
  715.                         });                 
  716.    
  717. });
  718. $("input[name='startProcessingAt']").trigger("change");
  719. }); 
  720. $(".orderPreview").click(function(){
  721.     $(".checkout-area").html("");
  722.     
  723.     if(cartLS.list().length > 0){                        
  724. $.ajax({
  725.                             url:"{{path('pos_cart_checkout')}}",
  726.                             method:"POST",
  727.                             data:{
  728.                                 shippingMethod:$(".shippingMethod.active").attr("data-id"),
  729.                                 codeCoupon:$("input[name=codeCoupon]").val(),
  730.                                 isPromoPreview: true
  731.                             },
  732.                             success:function(result){
  733.                                 reductionCoupon = 0;
  734.                                 if(result.coupon ){
  735.                                     if(result.coupon.typeReduction=="percent"){
  736.                                         reductionCoupon = (total / 100) * result.coupon.valueReduction;
  737.                                     }else{
  738.                                         reductionCoupon = result.coupon.valueReduction;
  739.                                     }
  740.                                     $("input[name='codeCoupon']").attr("data-coupon-value",result.coupon.valueReduction);
  741.                                     $("input[name='codeCoupon']").attr("data-type-value",result.coupon.typeReduction);
  742.                                     
  743.                                     $.toast({
  744.                                             heading: result.coupon.code,
  745.                                             text: result.message,
  746.                                             showHideTransition: 'slide',
  747.                                             hideAfter:12000,
  748.                                             icon: 'success',
  749.                                             loaderBg: '#1ca5df', 
  750.                                             position:"top-right",
  751.                                             allowToastClose: true,
  752.                                             stack: false
  753.                                     })
  754.                                 }else{
  755.                                     $.toast({
  756.                                             heading: "Remarque",
  757.                                             text: result.message,
  758.                                             showHideTransition: 'slide',
  759.                                             hideAfter:12000,
  760.                                             icon: 'warning',
  761.                                             loaderBg: '#1ca5df', 
  762.                                             position:"top-right",
  763.                                             allowToastClose: true,
  764.                                             stack: false
  765.                                     })
  766.                                 }
  767.                                 $(".promo .codepromo").html(reductionCoupon.toFixed(2)+" DH");
  768.                                 $(".total-to-pay").html(((total) - (amount) - (reductionCoupon)) + (shippingFees) + (shippingTips) + " DH");
  769.                                 
  770.                             }
  771.                         });
  772.                
  773.     }
  774.     else{
  775.         alert("Veuillez rajouter des produit au panier");
  776.     }
  777.                             
  778.                     });
  779.   
  780. })
  781.     </script>
  782. <script>
  783. document.addEventListener("turbo:load", function() {
  784. var collectMap;
  785. var collectGeocoder;
  786. function initCollectMap() {
  787.   collectMap = new google.maps.Map(document.getElementById("collectMap"), {
  788.     center: { lat: centerLatCollect, lng: centerLngCollect }, // Set initial map center
  789.     zoom: 8, // Set initial zoom level
  790.   });
  791.   
  792.   collectMap.addListener("click", function (event) {
  793.     
  794.     collectPlaceMarker(event.latLng);
  795.     getCollectAddress(event.latLng);
  796.   });
  797. }
  798. window.addEventListener('resize', function() {
  799.   google.maps.event.trigger(collectMap, 'resize');
  800. });
  801. function collectPlaceMarker(location) {
  802.   var marker = new google.maps.Marker({
  803.     position: location,
  804.     map: collectMap,
  805.   });
  806.   collectMap.panTo(location);
  807. }
  808. function getCollectAddress(latLng) {
  809.     collectGeocoder = new google.maps.Geocoder();
  810.   collectGeocoder.geocode({ location: latLng }, function (results, status) {
  811.     console.log(results);
  812.     if (status === "OK") {
  813.       if (results[0]) {
  814.         console.log(results[0].formatted_address);
  815.       } else {
  816.         console.log("No results found");
  817.       }
  818.     } else {
  819.       console.log("Geocoder failed due to: " + status);
  820.     }
  821.   });
  822. }
  823. initCollectMap();
  824. var shippingMap;
  825. var shippingGeocoder;
  826. function initShippingMap() {
  827.   shippingMap = new google.maps.Map(document.getElementById("shippingMap"), {
  828.     center: { lat: centerLatShipping, lng: centerLngShipping }, // Set initial map center
  829.     zoom: 8, // Set initial zoom level
  830.   });
  831.   
  832.   shippingMap.addListener("click", function (event) {
  833.     
  834.     shippingPlaceMarker(event.latLng);
  835.     getShippingAddress(event.latLng);
  836.   });
  837. }
  838. window.addEventListener('resize', function() {
  839.   google.maps.event.trigger(shippingMap, 'resize');
  840. });
  841. function shippingPlaceMarker(location) {
  842.   var marker = new google.maps.Marker({
  843.     position: location,
  844.     map: shippingMap,
  845.   });
  846.   shippingMap.panTo(location);
  847. }
  848. function getShippingAddress(latLng) {
  849.     shippingGeocoder = new google.maps.Geocoder();
  850.   shippingGeocoder.geocode({ location: latLng }, function (results, status) {
  851.     console.log(results);
  852.     if (status === "OK") {
  853.       if (results[0]) {
  854.         console.log(results[0].formatted_address);
  855.       } else {
  856.         console.log("No results found");
  857.       }
  858.     } else {
  859.       console.log("Geocoder failed due to: " + status);
  860.     }
  861.   });
  862. }
  863. initShippingMap();
  864. $("#modalShippingMap").click(function(){
  865.     $("#shippingMap").removeClass("d-none");
  866.     $("#collectMap").addClass("d-none");
  867. });
  868. $("#modalCollectMap").click(function(){
  869.     $("#shippingMap").addClass("d-none");
  870.     $("#collectMap").removeClass("d-none");
  871. });
  872. });
  873. </script>
  874. <!-- Modal -->
  875. <div class="modal fade" id="collectMapModal" tabindex="-1" aria-labelledby="collectMapModalLabel" aria-hidden="true">
  876.   <div class="modal-dialog modal-xl" style="width:800px;">
  877.     <div class="modal-content">
  878.       <div class="modal-header">
  879.         <h5 class="modal-title" id="collectMapModalLabel">Cordonnées de collect</h5>
  880.         <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  881.       </div>
  882.       <div class="modal-body">
  883.         <div id="collectMap"></div>
  884.         <div id="shippingMap"  class="d-none"></div>
  885.       </div>
  886.       <div class="modal-footer">
  887.         <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button>
  888.         <button type="button" class="btn btn-primary">Séléctionner</button>
  889.       </div
  890.     </div>
  891.   </div>
  892. </div>
  893. {% endblock %}