diff --git a/wp-content/themes/cosmopet/modules/forms/module-ajax-controller.php b/wp-content/themes/cosmopet/modules/forms/module-ajax-controller.php index f05fbec..5c11d9e 100644 --- a/wp-content/themes/cosmopet/modules/forms/module-ajax-controller.php +++ b/wp-content/themes/cosmopet/modules/forms/module-ajax-controller.php @@ -281,16 +281,34 @@ function send_order_data($order_id) { $utm = get_utm_data()['utm_source']; $url = ''; $fName = 2; - // 2. Формируем список товаров + + // 2. Формируем список товаров с полной ценой (включая НДС) foreach ($order->get_items() as $item) { $product = $item->get_product(); + // Используем get_total_tax() + get_total() для получения полной цены с НДС + $item_total_without_tax = $item->get_total(); + $item_tax = $item->get_total_tax(); + $item_total_with_tax = round($item_total_without_tax + $item_tax); $order_comment .= sprintf( "%s x %s = %s\n", $product->get_name(), $item->get_quantity(), - wc_price($item->get_total()) + strip_tags(wc_price($item_total_with_tax)) ); } + + // 3. Добавляем информацию о промокодах, если они использовались + $coupons = $order->get_coupon_codes(); + if (!empty($coupons)) { + $order_comment .= "\n=== ПРОМОКОДЫ ===\n"; + foreach ($coupons as $coupon_code) { + $coupon = new WC_Coupon($coupon_code); + $discount_amount = round($order->get_discount_total()); + $order_comment .= "Промокод: {$coupon_code}\n"; + $order_comment .= "Скидка: " . strip_tags(wc_price($discount_amount)) . "\n"; + } + } + $order_comment .= "\n=== ДАННЫЕ ДОСТАВКИ ===\n"; $order_comment .= "Город: " . $order->get_billing_city() . "\n"; $order_comment .= "Адрес: " . $order->get_billing_address_1() . "\n"; @@ -302,11 +320,8 @@ function send_order_data($order_id) { if (is_user_logged_in()) { $user_id = get_current_user_id(); - - } - else{ + } else { $user_id = ''; - } $form_title = 'Покупка на сайте'; $formData = [ @@ -319,7 +334,7 @@ function send_order_data($order_id) { 'ORDER_ID' => $order_id, 'ORDER_TOTAL' => $order_total, 'PAYMENT_METHOD' => $order->get_payment_method_title(), - 'COMMENTS' => $order_comment, + 'COMMENTS' => $clean_order_comment, // Адрес (префикс ADDR_) 'ADDR_CITY' => $order->get_billing_city(), @@ -341,40 +356,75 @@ function send_order_data($order_id) { $product_summary = "🛒 Состав заказа:\n\n"; foreach ($order->get_items() as $item) { $product = $item->get_product(); - $formData["PRODUCT_{$product_index}_NAME"] = $product->get_name(); - $formData["PRODUCT_{$product_index}_QTY"] = $item->get_quantity(); - $formData["PRODUCT_{$product_index}_PRICE"] = $item->get_total(); - $formData["PRODUCT_{$product_index}_SKU"] = $product->get_sku(); - - // Добавляем в текстовую сводку - $product_summary .= "{$product_index}) {$name}\n"; - $product_summary .= " Кол-во: {$qty}\n"; - $product_summary .= " Сумма: {$total}\n"; - if ($sku) { - $product_summary .= " Артикул: {$sku}\n"; + $product_name = $product->get_name(); + $product_qty = $item->get_quantity(); + $product_total_without_tax = $item->get_total(); + $product_tax = $item->get_total_tax(); + $product_total_with_tax = round($product_total_without_tax + $product_tax); + $product_sku = $product->get_sku(); + + $formData["PRODUCT_{$product_index}_NAME"] = $product_name; + $formData["PRODUCT_{$product_index}_QTY"] = $product_qty; + $formData["PRODUCT_{$product_index}_PRICE"] = $product_total_with_tax; + $formData["PRODUCT_{$product_index}_SKU"] = $product_sku; + + // Добавляем в текстовую сводку с полной ценой + $product_summary .= "{$product_index}) {$product_name}\n"; + $product_summary .= " Кол-во: {$product_qty}\n"; + $product_summary .= " Сумма: " . strip_tags(wc_price($product_total_with_tax)) . "\n"; + if ($product_sku) { + $product_summary .= " Артикул: {$product_sku}\n"; } $product_summary .= "\n"; $product_index++; } + + // Добавляем информацию о промокодах в сводку товаров + $coupons = $order->get_coupon_codes(); + if (!empty($coupons)) { + $product_summary .= "=== ПРОМОКОДЫ ===\n"; + foreach ($coupons as $coupon_code) { + $coupon = new WC_Coupon($coupon_code); + $discount_amount = round($order->get_discount_total()); + $product_summary .= "Промокод: {$coupon_code}\n"; + $product_summary .= "Скидка: " . strip_tags(wc_price($discount_amount)) . "\n"; + } + $product_summary .= "\n"; + } + + // Функция для очистки текста от HTML-сущностей + function clean_text_for_telegram($text) { + // Удаляем HTML-теги + $text = strip_tags($text); + // Заменяем HTML-сущности на обычные символы + $text = html_entity_decode($text, ENT_QUOTES | ENT_HTML5, 'UTF-8'); + // Убираем лишние пробелы + $text = preg_replace('/\s+/', ' ', $text); + return trim($text); + } $message = "📋 Данные формы:\n\n"; foreach ($formData as $key => $value) { if (is_array($value)) { $value = implode(', ', $value); // на случай, если в значении массив } - $message .= sprintf("%s: %s\n", $key, $value); + $message .= sprintf("%s: %s\n", $key, clean_text_for_telegram($value)); } + // Очищаем тексты от HTML-сущностей для Telegram + $clean_product_summary = clean_text_for_telegram($product_summary); + $clean_order_comment = clean_text_for_telegram($order_comment); + $crmData = array( 'phone' => $customer_phone, 'name' => $customer_name, 'email' => $customer_email, - 'msg' => $product_summary, + 'msg' => $clean_product_summary, 'url' => null, 'stage' => 'C2:UC_ZMY1QV', 'fName' => 2, 'order_total' => $order_total, - 'user_id' => $user_data['user_id'], + 'user_id' => $user_id, 'method' => 'crm.deal.add', 'form_title' => 'Заказ на сайте', 'is_subscribe' => false,