diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-11-16 11:23:43 +0700 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-11-16 11:23:43 +0700 |
commit | 87bf926c60712be2d6076c96bc9da659023f37bf (patch) | |
tree | 485b959cfd89d34f744402dcb5e05ff74489cfc0 /basket.cxx | |
parent | 992b2cc2fb3637a3df45b67ad282aab1d1905320 (diff) |
If item is already in basket, then add the quantity instead
Diffstat (limited to 'basket.cxx')
-rw-r--r-- | basket.cxx | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -1,3 +1,4 @@ +#include <algorithm> #include "qicclient/basket.hxx" namespace ICClient { @@ -41,10 +42,18 @@ namespace ICClient { void Basket::addItem(Item const& item) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - items << item; - endInsertRows(); - emit rowCountChanged(); + 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()) { + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + items << item; + endInsertRows(); + emit rowCountChanged(); + } else + iterator->quantity++; } void Basket::update(icclient_ord_order* order) @@ -54,7 +63,6 @@ namespace ICClient { addItem(Item{order->items[i]}); m_subtotal = order->subtotal; m_totalCost = order->total_cost; - emit updated(); emit subtotalChanged(); emit totalCostChanged(); } |