Delet subcategory function in handleCategorySelection
This commit is contained in:
parent
95d5fe644d
commit
a400d12d16
@ -177,45 +177,45 @@ export default class UserProductHandler {
|
||||
const chatId = callbackQuery.message.chat.id;
|
||||
const messageId = callbackQuery.message.message_id;
|
||||
const [locationId, categoryId] = callbackQuery.data.replace('shop_category_', '').split('_');
|
||||
|
||||
|
||||
try {
|
||||
const subcategories = await CategoryService.getSubcategoriesByCategoryId(categoryId);
|
||||
const location = await LocationService.getLocationById(locationId);
|
||||
|
||||
if (subcategories.length === 0) {
|
||||
// Получаем товары для выбранной категории
|
||||
const products = await ProductService.getProductsByCategoryId(categoryId);
|
||||
|
||||
if (products.length === 0) {
|
||||
await bot.editMessageText(
|
||||
'No products available in this category yet.',
|
||||
'No products available in this category.',
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
reply_markup: {
|
||||
inline_keyboard: [[
|
||||
{
|
||||
text: '« Back to Categories',
|
||||
callback_data: `shop_district_${location.country}_${location.city}_${location.district}`
|
||||
}
|
||||
{ text: '« Back', callback_data: `shop_district_${locationId}` }
|
||||
]]
|
||||
}
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Создаем клавиатуру с товарами
|
||||
const keyboard = {
|
||||
inline_keyboard: [
|
||||
...subcategories.map(sub => [{
|
||||
text: sub.name,
|
||||
callback_data: `shop_subcategory_${locationId}_${categoryId}_${sub.id}`
|
||||
}]),
|
||||
[{
|
||||
text: '« Back to Categories',
|
||||
callback_data: `shop_district_${location.country}_${location.city}_${location.district}`
|
||||
}]
|
||||
]
|
||||
inline_keyboard: products.map(product => [
|
||||
{
|
||||
text: `${product.name} - $${product.price}`,
|
||||
callback_data: `shop_product_${product.id}`
|
||||
}
|
||||
])
|
||||
};
|
||||
|
||||
|
||||
// Добавляем кнопку "Назад"
|
||||
keyboard.inline_keyboard.push([
|
||||
{ text: '« Back', callback_data: `shop_district_${locationId}` }
|
||||
]);
|
||||
|
||||
// Отправляем сообщение с товарами
|
||||
await bot.editMessageText(
|
||||
'📦 Select subcategory:',
|
||||
'Select a product:',
|
||||
{
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
@ -224,7 +224,7 @@ export default class UserProductHandler {
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error in handleCategorySelection:', error);
|
||||
await bot.sendMessage(chatId, 'Error loading subcategories. Please try again.');
|
||||
await bot.sendMessage(chatId, 'Error loading products. Please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user