Add variant selection with price and integrate into order

This commit is contained in:
RomanDoroshenko 2026-10-06 12:21:14 +00:00
parent b7c0542f17
commit e5bf8ffbe0
7 changed files with 53 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

38
bot.js
View File

@ -59,6 +59,7 @@ function formatOrder(order) {
return `📦 Номер заказа: ${order.id}\n`
+ `🧁 Вид: ${order.type}\n`
+ `🔢 Кол‑во: ${order.quantity}\n`
+ `🧩 Вариант: ${order.variant + 1}\n`
+ `📅 Дата доставки: ${order.date}\n`
+ `🕒 Время: ${order.time}\n`
+ `👤 Имя: ${order.name}\n`
@ -77,14 +78,20 @@ bot.command('start', async (ctx) => {
await ctx.replyWithPhoto(new InputFile(filePath), { caption: `Вариант ${i + 1}` }).catch(() => {});
}
// Кнопки выбора типа продукта
await ctx.reply('Какой вариант вас интересует?', {
// Предлагаем выбрать вариант товара с ценой
const variantButtons = images.map((_, i) => {
const price = i % 2 === 0 ? PRICE['букет'] : PRICE['коробка'];
return `Вариант ${i + 1} – ${price}₸`;
});
const variantKeyboard = variantButtons.map(b => [b]);
await ctx.reply('Выберите вариант товара:', {
reply_markup: {
keyboard: [['Букет', 'Коробка']],
keyboard: variantKeyboard,
one_time_keyboard: true,
resize_keyboard: true,
},
});
setStage(ctx.chat.id, { stage: 'choose_type' });
setStage(ctx.chat.id, { stage: 'choose_variant' });
});
bot.on('message:text', async (ctx) => {
@ -99,7 +106,28 @@ bot.on('message:text', async (ctx) => {
}
switch (session.stage) {
case 'choose_type': {
case 'choose_variant': {
const match = text.match(/Вариант\s(\d+)/);
if (!match) {
await ctx.reply('Пожалуйста, выберите вариант из списка.');
return;
}
const idx = parseInt(match[1], 10) - 1;
if (idx < 0 || idx >= images.length) {
await ctx.reply('Неправильный вариант.');
return;
}
setStage(chatId, { variant: idx, stage: 'choose_type' });
await ctx.reply('Какой вариант вас интересует? Выберите: Букет или Коробка.', {
reply_markup: {
keyboard: [['Букет', 'Коробка']],
one_time_keyboard: true,
resize_keyboard: true,
},
});
break;
}
case 'choose_type': {
if (text !== 'букет' && text !== 'коробка') {
await ctx.reply('Пожалуйста, укажите "букет" или "коробка".');
return;
@ -253,7 +281,7 @@ case 'await_time': {
const { type, quantity, date, time, name } = session;
const total = PRICE[type] * quantity;
const orderId = Date.now();
const order = { id: orderId, type, quantity, date, time, name, phone, total };
const order = { id: orderId, type, quantity, date, time, name, phone, total, variant: session.variant };
saveOrder(order);
// Формируем итоговое сообщение
await ctx.reply(formatOrder(order));

View File

@ -28,5 +28,25 @@
"name": "Роман",
"phone": "+77059631941",
"total": 9000
},
{
"id": 1791288625288,
"type": "букет",
"quantity": 3,
"date": "2026-10-07",
"time": "12:00",
"name": "Роман",
"phone": "+77059631941",
"total": 15000
},
{
"id": 1791288816480,
"type": "коробка",
"quantity": 4,
"date": "2026-10-06",
"time": "12:00",
"name": "Ро",
"phone": "97483828727181",
"total": 12000
}
]