From 501f86b2313538dec63834421806127383424771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Sat, 16 Nov 2019 18:15:10 +0700 Subject: Same item in basket, gets removed and then inserted with new quantity --- basket.cxx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'basket.cxx') diff --git a/basket.cxx b/basket.cxx index 60ea273..52dca83 100644 --- a/basket.cxx +++ b/basket.cxx @@ -47,13 +47,17 @@ namespace ICClient { , [&product](Item const& item) { return product.sku == item.product.sku; }); - if (iterator == items.end()) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - items << item; - endInsertRows(); - emit rowCountChanged(); - } else - iterator->quantity++; + if (iterator != items.end()) { + auto index = items.indexOf(*iterator); + beginRemoveRows(QModelIndex(), index, index); + items.removeAt(index); + endRemoveRows(); + } + + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + items << item; + endInsertRows(); + emit rowCountChanged(); } void Basket::update(icclient_ord_order* order) -- cgit v1.2.3