Answer the question
In order to leave comments, you need to log in
How to add User_Cart to the table by clicking on the button (product)??
Hello. I tried with the choice of quantity., in the end, at least 1 product how to add? A user-SELECTED item... I don't understand.
I send an SQL
query that
displays
the products that are in stock. Product_code ''')
re_Pizs = cur.fetchall() #record with code 2, 4, 7, 8
Display results in inline buttons. What condition to write in order to select a specific one! goods add a record to the table. I explicitly specify which element to display when clicked, but this is not correct ((
File Main:
#Соединяемся с БД
con = funcs_DB.sqlite3.connect(funcs_DB.name_DB)
cur = con.cursor()
#Имя и фамилия пользователя
user_name = message.chat.first_name #Получим имя юзера
last_name = message.chat.last_name
insert_query_Korzina = '''INSERT OR IGNORE INTO Корзина_юзера(Товар,
Цена_руб, Количество, Юзер) VALUES (?, ?, ?, ?)'''
lt_one = (funcs_DB.re_Naps[0])
lt_two = (1, f'{user_name} {last_name}')
list_Korzina= [lt_one + lt_two]
#Добавление товаров в корзину_Юзера
if text == 'НапиткиAdd':
count = cur.executemany(insert_query_Korzina, list_Korzina)
con.commit()
bot.send_message(message.chat.id, f'Товар: {list_Korzina[0]} добавлен в корзину.')
print("Запись успешно вставлена в таблицу: Корзина_юзера\n", "Кол-во записей:" , cur.rowcount)
for row in funcs_DB.re_Naps:
#Создаём инлайн меню_1
keyboard_inline_menu_Naps.add(
telebot.types.InlineKeyboardButton(f'{row[0]} Цена: {row[1]}', callback_data='НапиткиAdd'))
Answer the question
In order to leave comments, you need to log in
Chet is difficult to understand all this, looking only at some strange snatches. Anyway. As I understand it re_Naps
, you have a list of goods for output, if so, then here lt_one = (funcs_DB.re_Naps[0])
you yourself indicate that you need to write down exactly the first element from the list of these goods.
Further: you really cannot pass to the callback
text of the button, only what is in callback_data
, but you can do something like this:
Create buttons:
keyboard_inline_menu_Naps.add(
telebot.types.InlineKeyboardButton(
f'{row[0]} Цена: {row[1]}', callback_data=f'НапиткиAdd_{row[0]}_{row[1]}'
)
)
text
you save yours callback
from the button, if so, then here:if 'НапиткиAdd' in text:
callback_data = text.split('НапиткиAdd_')[-1].split('_')
list_Korzina = [*callback_data, 1, f'{user_name} {last_name}']
count = cur.execute(insert_query_Korzina, list_Korzina)
con.commit()
bot.send_message(message.chat.id, f'Товар: {list_Korzina[0]} добавлен в корзину.')
not to the point of the question, but why not start using sqlalchemy?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question