diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2020-03-28 15:19:02 +0800 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2020-03-28 15:19:02 +0800 |
commit | 4681103c794fef10a0448d4378ca68ac77b6ee29 (patch) | |
tree | a7b411f744e730ded6877ec1b275a75f017b14e5 /basket.cxx | |
parent | a68fc492cf86a14cf9cf95d9f9a764cdf5b01007 (diff) | |
parent | 0728570b5a424abaad7fe49f63caa1977e016782 (diff) |
Merge branch 'master' into cmake
Diffstat (limited to 'basket.cxx')
-rw-r--r-- | basket.cxx | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -1,3 +1,4 @@ +#include <algorithm> #include "qicclient/basket.hxx" namespace ICClient { @@ -5,7 +6,7 @@ namespace ICClient { int Basket::rowCount(QModelIndex const& parent) const { Q_UNUSED(parent) - return items.count(); + return items.count(); } QVariant Basket::data(QModelIndex const& index, int role) const @@ -41,6 +42,18 @@ namespace ICClient { void Basket::addItem(Item const& item) { + auto product = item.product; + auto iterator = std::find_if(items.begin(), items.end() + , [&product](Item const& item) { + return product.sku == item.product.sku; + }); + if (iterator != items.end()) { + auto index = items.indexOf(*iterator); + beginRemoveRows(QModelIndex(), index, index); + items.removeAt(index); + endRemoveRows(); + } + beginInsertRows(QModelIndex(), rowCount(), rowCount()); items << item; endInsertRows(); @@ -52,8 +65,10 @@ namespace ICClient { if (order) { for (size_t i = 0; i < order->nitems; i++) addItem(Item{order->items[i]}); - icclient_ord_free(order); - emit updated(); + m_subtotal = order->subtotal; + m_totalCost = order->total_cost; + emit subtotalChanged(); + emit totalCostChanged(); } } |