summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-06-16 15:40:24 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-06-16 15:40:24 +0800
commit4c43c27774cfc3652ff3269519ee248e71b58185 (patch)
treebe2c03a23347033a16926e236d0af93d8ca27d7f
parentd0a8570fd5c46ad2cab21af0b8f5a299bcbc1792 (diff)
Item is now a subclass of Product
-rw-r--r--interchange/ord.hxx15
-rw-r--r--interchange/product.hxx11
-rw-r--r--ord.cxx21
3 files changed, 27 insertions, 20 deletions
diff --git a/interchange/ord.hxx b/interchange/ord.hxx
index 34ff202..a7e41a7 100644
--- a/interchange/ord.hxx
+++ b/interchange/ord.hxx
@@ -8,22 +8,23 @@
namespace QInterchange {
- struct Item
+ struct Item : public Product
{
enum ItemRoles {
QuantityRole = Product::PriceRole + 1,
NameRole
};
- Item(interchange_ord_item item) :
- product{&item.product},
- quantity{item.quantity},
- name{item.name} {}
- Product product;
+ Item(interchange_ord_item *item) :
+ quantity{item->quantity},
+ name{item->name}
+ {
+ init((struct interchange_product *)item);
+ }
unsigned int quantity;
QString name;
bool operator==(Item const& item)
{
- return product.sku == item.product.sku;
+ return sku == item.sku;
}
};
diff --git a/interchange/product.hxx b/interchange/product.hxx
index d3246ed..9fd7a89 100644
--- a/interchange/product.hxx
+++ b/interchange/product.hxx
@@ -25,9 +25,12 @@ namespace QInterchange {
};
Product() {}
- Product(struct interchange_product *product) :
- price{product->price},
- weight{product->weight}
+ Product(struct interchange_product *product)
+ {
+ init(product);
+ }
+
+ void init(struct interchange_product *product)
{
if (product->sku)
sku = QString{product->sku};
@@ -41,10 +44,12 @@ namespace QInterchange {
thumb = QString{product->thumb};
if (product->image)
image = QString{product->image};
+ price = product->price;
if (product->prod_group)
prodGroup = QString{product->prod_group};
if (product->category)
category = QString{product->category};
+ weight = product->weight;
if (product->option_type)
optionType = QString{product->option_type};
if (product->author)
diff --git a/ord.cxx b/ord.cxx
index 12d2cdb..06f9132 100644
--- a/ord.cxx
+++ b/ord.cxx
@@ -16,7 +16,7 @@ namespace QInterchange {
{
ord = this;
for (size_t i = 0; i < order->nitems; i++)
- addItem(Item{order->items[i]});
+ addItem(Item{&order->items[i]});
m_subtotal = order->subtotal;
m_shipping = order->shipping;
m_totalCost = order->total_cost;
@@ -35,17 +35,17 @@ namespace QInterchange {
auto item = items[row];
switch (role) {
case Product::SkuRole:
- return item.product.sku;
+ return item.sku;
case Product::TitleRole:
- return item.product.title;
+ return item.title;
case Product::DescriptionRole:
- return item.product.description;
+ return item.description;
case Product::ImageRole:
- return item.product.image;
+ return item.image;
case Product::PriceRole:
- return item.product.price;
+ return item.price;
case Product::OptionTypeRole:
- return item.product.optionType;
+ return item.optionType;
case Item::QuantityRole:
return item.quantity;
case Item::NameRole:
@@ -71,9 +71,10 @@ namespace QInterchange {
void Ord::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;
+ auto sku = item.sku;
+ auto iterator = std::find_if(items.begin(), items.end(),
+ [&sku](Item const& item) {
+ return sku == item.sku;
});
if (iterator != items.end()) {
auto index = items.indexOf(*iterator);