V
V
violpeople2021-06-20 14:49:53
Python
violpeople, 2021-06-20 14:49:53

How to add an item to the cart?

Hello everyone, I would like to know how you can add an item to the cart. The bot has a carousel of products and an "Add to Cart" button. Here is the question - how to make it clear to the bot on which product the user is in this carousel, so that by clicking on this button, the product data goes to the database? Aiogram library.

async def ecuador(call:types.CallbackQuery):

    kb = InlineKeyboardMarkup(row_width=2)
    
    next = InlineKeyboardButton(text= 'Следующий',callback_data= 'next_1')
    previous = InlineKeyboardButton(text= 'Предыдущий',callback_data= 'previous_1')
    add = InlineKeyboardButton(text= 'Добавить в корзину',callback_data= 'add')

    kb.add(previous,next,add)

    back = InlineKeyboardButton(text= 'Назад',callback_data= 'back')
    kb.add(back)

    await bot.send_photo(
    chatId,
    photo = current_photo,
    caption='Название: '+ current_item +'\n\nЦена: '+ current_price,
    reply_markup=kb)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-06-20
@violpeople

Add some product ID to callback_data. Let's say your products have an ID

# допустим, текущий товар имеет id 1058
add = InlineKeyboardButton(text= 'Добавить в корзину',callback_data= 'add_1058')

Further, already in the function with the processing of clicks on the callback button, parse this id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question