view.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (C) 2021 Echedey López Romero <elr@disroot.org>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. -->
  15. <html lang='en'>
  16. <head>
  17. <meta charset="UTF-8" />
  18. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  19. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
  20. <meta name="author" content="Echedey López Romero" />
  21. <title>Crowdsourcing Store</title>
  22. <link rel="stylesheet" href="./frameworks/bootstrap/css/bootstrap.min.css" />
  23. <script src="./frameworks/jquery/jquery-3.5.1.min.js"></script>
  24. <script src="./frameworks/bootstrap/js/bootstrap.bundle.min.js"></script>
  25. <link rel="stylesheet" href="./frameworks/fontawesome/css/all.min.css" />
  26. <script src="./frameworks/fontawesome/attribution.js"></script>
  27. <link rel="stylesheet" href="./css/common.css" />
  28. <script src="./js/common.js"></script>
  29. </head>
  30. <body class="container-fluid">
  31. <div class="row my-2">
  32. <div class="col-sm-10 col-12 mx-auto">
  33. <div class="container-fluid">
  34. <div class="row mb-2">
  35. <div class="col text-center"></div>
  36. <h1 class="col-lg-6 col-12 mb-0 p-5 text-center">Crowdsourcing Store</h1>
  37. <?php echo $TopButtons ?>
  38. </div>
  39. <div class="row mb-2">
  40. <?php echo $Page ?>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <script type="text/javascript">
  46. function RoundUp(Num, Precision) {
  47. Precision = Math.pow(10, Precision);
  48. return Math.ceil(Num * Precision) / Precision;
  49. }
  50. $('.favourite').click(function () {
  51. $(this).toggleClass('fas far');
  52. let URL = '.?favourite=' + $(this).attr('data-id');
  53. $.get(URL);
  54. });
  55. $('.addcart').click(function () {
  56. $('#quantitycart').text(parseInt($('#quantitycart').text()) + 1);
  57. let URL = '.?cart=' + $(this).attr('data-id');
  58. $.get(URL);
  59. });
  60. $('.quantityproduct').change(function () {
  61. let QuantityProduct = parseInt($(this).val()) === NaN || parseInt($(this).val()) === 0 ? 1 : parseInt($(this).val());
  62. let URLRemove = '.?nocart=' + $(this).attr('data-id');
  63. let URLAdd = '.?cart=' + $(this).attr('data-id');
  64. $.get(URLRemove);
  65. for (let Position = 0; Position < QuantityProduct; Position++) {
  66. $.get(URLAdd);
  67. }
  68. $('#subtotal').text(0);
  69. $('#shipping').text(0);
  70. $('#total').text(0);
  71. $('[id^=quantityproduct-]').each(function () {
  72. let ProductPrice = Number(Number($(this).val() * $(this).attr('data-price')));
  73. $('#subtotal').text(RoundUp(Number($('#subtotal').text()) + ProductPrice, 2));
  74. })
  75. if (Number($('#subtotal').text()) >= 500) {
  76. $('#shipping').text(0);
  77. } else {
  78. $('#shipping').text(RoundUp(Number($('#subtotal').text()) * 10 / 100, 2));
  79. }
  80. $('#total').text(RoundUp(Number($('#subtotal').text()) + Number($('#shipping').text()), 2));
  81. });
  82. $(document).ready((async () => {
  83. if ($('#country').val() !== undefined && $('#province').val() !== undefined
  84. && $('#municipality').val() !== undefined && $('#zipcode').val() !== undefined ) {
  85. await LoadData();
  86. ShowZIPCode();
  87. ShowMunicipality();
  88. ShowProvince();
  89. $('#country').attr('onchange', 'RestartProvince(); ShowProvince();');
  90. $('#province').attr('onchange', 'RestartMunicipality(); ShowMunicipality();');
  91. $('#municipality').attr('onchange', 'RestartZIPCode(); ShowZIPCode();');
  92. }
  93. })());
  94. </script>
  95. </body>
  96. </html>