summaryrefslogtreecommitdiff
path: root/basket.cxx
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2020-03-28 15:19:02 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2020-03-28 15:19:02 +0800
commit4681103c794fef10a0448d4378ca68ac77b6ee29 (patch)
treea7b411f744e730ded6877ec1b275a75f017b14e5 /basket.cxx
parenta68fc492cf86a14cf9cf95d9f9a764cdf5b01007 (diff)
parent0728570b5a424abaad7fe49f63caa1977e016782 (diff)
Merge branch 'master' into cmake
Diffstat (limited to 'basket.cxx')
-rw-r--r--basket.cxx21
1 files changed, 18 insertions, 3 deletions
diff --git a/basket.cxx b/basket.cxx
index c4905e0..52dca83 100644
--- a/basket.cxx
+++ b/basket.cxx
@@ -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();
}
}