index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?
  2. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
  3. $APPLICATION->SetTitle("Оформление заказа");
  4. CModule::IncludeModule('iblock');
  5. \Bitrix\Main\UI\Extension::load("ui.alerts");
  6. $IBLOCK_ID = 4;
  7. define("NOT_CHECK_PERMISSIONS", true);
  8. $arBask = json_decode($_COOKIE['basket']);
  9. $arBasket = array();
  10. foreach ($arBask as $object) {
  11. array_push($arBasket, $object->id);
  12. }
  13. $arBasketFilter = ["ID" => $arBasket];
  14. $arFilter = Array("IBLOCK_ID"=>4, "ID"=>$arBasket);?>
  15. <?$arSelect = Array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM","PROPERTY_*");//IBLOCK_ID и ID обязательно должны быть указаны, см. описание arSelectFields выше
  16. $res = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>50), $arSelect);
  17. $wth_discount = 0;
  18. $sum = 0;
  19. $cart_goods = array();
  20. while($ob = $res->GetNextElement()){
  21. $arFields = $ob->GetFields();
  22. array_push($cart_goods, $arFields["ID"]);
  23. $arProps = $ob->GetProperties();
  24. if ($arProps["DISCOUNT"]["VALUE"]){
  25. $new_price = $arProps["PRICE"]["VALUE"] - ($arProps["PRICE"]["VALUE"] * $arProps["DISCOUNT"]["VALUE"] / 100);
  26. $wth_discount+=$new_price;
  27. }
  28. else{
  29. $wth_discount+=$arProps["PRICE"]["VALUE"];
  30. }
  31. $sum+=$arProps["PRICE"]["VALUE"];
  32. }
  33. if (isset($_POST["submitorder"])){
  34. //Погнали
  35. $el = new CIBlockElement;
  36. $iblock_id = 6;
  37. $section_id = false;
  38. //Свойства
  39. $PROP = array();
  40. $PROP['ADDRESS'] = $_POST['address'];
  41. $PROP['POST_INDEX'] = $_POST['zip'];
  42. $PROP['PHONE_NUMBER'] = $_POST['phone'];
  43. $PROP['EMAIL'] = $_POST['email'];
  44. $PROP['DISCOUNT_PRICE'] = $_POST['discount'];
  45. $PROP['PRICE'] = $_POST['price'];
  46. $PROP['GOODS'] = $cart_goods;
  47. //Основные поля элемента
  48. $fields = array(
  49. "DATE_CREATE" => date("d.m.Y H:i:s"), //Передаем дата создания
  50. "IBLOCK_SECTION" => $section_id,
  51. "IBLOCK_ID" => $iblock_id,
  52. "PROPERTY_VALUES" => $PROP,
  53. "NAME" => $_POST["fio"],
  54. "ACTIVE" => "Y",
  55. "PREVIEW_TEXT" => $POST["dop_info"], //Анонс
  56. "PREVIEW_PICTURE" => "", //изображение для анонса
  57. "DETAIL_TEXT" => strip_tags($_REQUEST['description_detail']),
  58. "DETAIL_PICTURE" => "", //изображение для детальной страницы
  59. );
  60. //Результат в конце отработки
  61. if ($ID = $el ->Add($fields)) {?>
  62. <div class="ui-alert ui-alert-success">
  63. <span class="ui-alert-message"><strong>Успешно!</strong> Заказ был оформлен. Информация направлена на указанный Email</span>
  64. </div><?
  65. if (isset($_COOKIE['basket'])){
  66. setcookie("basket","",time()-3600,"/");
  67. }
  68. } else {?>
  69. <div class="ui-alert ui-alert-danger">
  70. <span class="ui-alert-message"><strong>Неудача!</strong> Проверьте правильность заполнения формы.</span>
  71. </div>
  72. <?}
  73. header("Location: /order"); exit();
  74. }
  75. ?>
  76. <?$APPLICATION->IncludeComponent(
  77. "bitrix:breadcrumb",
  78. "top_navigate",
  79. array(
  80. "COMPONENT_TEMPLATE" => "top_navigate",
  81. "START_FROM" => "0",
  82. "PATH" => "",
  83. "SITE_ID" => "s1"
  84. ),
  85. false
  86. );?>
  87. <section class="checkout-wrap padding-large">
  88. <div class="container">
  89. <form name="add_my_ankete" method="POST" enctype="multipart/form-data" class="form-group" action="<?php htmlspecialchars($_SERVER["PHP_SELF"]) ?>">
  90. <div class="row d-flex flex-wrap">
  91. <div class="col-lg-6">
  92. <h3 class="mb-3">Детали заказа</h3>
  93. <div class="billing-details">
  94. <label for="fname">ФИО*</label>
  95. <input type="text" id="fio" name="fio" placeholder="Иванов Иван Иванович" class="form-control mt-2 mb-4 ps-3">
  96. <label for="address">Адрес*</label>
  97. <input type="text" id="adr" name="address" placeholder="Введите адрес доставки"
  98. class="form-control mt-3 ps-3 mb-3">
  99. <label for="zip">Почтовый индекс *</label>
  100. <input type="text" id="zip" name="zip" class="form-control mt-2 mb-4 ps-3" placeholder="603053">
  101. <label for="phone">Номер телефона *</label>
  102. <input type="text" id="phone" name="phone" class="form-control mt-2 mb-4 ps-3" placeholder="79009009090">
  103. <label for="email">Email адрес *</label>
  104. <input type="email" id="email" name="email" class="form-control mt-2 mb-4 ps-3" placeholder="email@email.ru">
  105. </div>
  106. </div>
  107. <div class="col-lg-6">
  108. <div>
  109. <h3 class="mb-3">Дополнительная информация</h3>
  110. <div class="billing-details">
  111. <label for="fname">Сообщение к заказу (необязательно)</label>
  112. <textarea class="form-control pt-3 pb-3 ps-3 mt-2" name="dop_info"
  113. placeholder="Примечания к заказу"></textarea>
  114. </div>
  115. </div>
  116. <div class="cart-totals padding-medium pb-0">
  117. <h3 class="mb-3">Сумма заказа</h3>
  118. <div class="total-price pb-3">
  119. <table cellspacing="0" class="table text-capitalize">
  120. <tbody>
  121. <tr class="subtotal pt-2 pb-2 border-top border-bottom">
  122. <th>Без скидки</th>
  123. <td data-title="Subtotal">
  124. <span class="price-amount amount text-primary ps-5 fw-light">
  125. <bdi>
  126. <?=$sum;?> <span class="price-currency-symbol">₽</span>
  127. </bdi>
  128. </span>
  129. </td>
  130. <input type="hidden" name="discount" value="<?=$sum;?>">
  131. </tr>
  132. <tr class="order-total pt-2 pb-2 border-bottom">
  133. <th>Итог</th>
  134. <td data-title="Total">
  135. <span class="price-amount amount text-primary ps-5 fw-light">
  136. <bdi>
  137. <?=$wth_discount;?> <span class="price-currency-symbol">₽</span></bdi>
  138. </span>
  139. </td>
  140. <input type="hidden" name="price" value="<?=$wth_discount;?>">
  141. </tr>
  142. </tbody>
  143. </table>
  144. </div>
  145. <div class="button-wrap mt-3">
  146. <button type="submit" name="submitorder" class="btn">Оформить заказ</button>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. </form>
  152. </div>
  153. </section>
  154. <?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>