From f70a1a57d83e4f50a7221d13b173a156ef0eb6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Sun, 12 Mar 2023 17:46:34 +0800 Subject: Checkout needs only profile from order --- interchange/ord.hxx | 1 + ord.cxx | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/interchange/ord.hxx b/interchange/ord.hxx index 2d18891..56bb7d3 100644 --- a/interchange/ord.hxx +++ b/interchange/ord.hxx @@ -62,6 +62,7 @@ namespace QInterchange { void addItem(Item const& item); QList items; struct interchange_ord_order* m_data; + QString profile; double m_subtotal; double m_shipping; double m_totalCost; diff --git a/ord.cxx b/ord.cxx index 9d27432..f7e2161 100644 --- a/ord.cxx +++ b/ord.cxx @@ -6,6 +6,7 @@ namespace QInterchange { static Ord* ord; + static char* order_profile; Ord::Ord(struct interchange_ord_order *order, QObject* parent) : QAbstractListModel{parent}, @@ -89,16 +90,16 @@ namespace QInterchange { void Ord::setProfile(QString const& profile) { - auto orderProfile = profile.toLatin1().data(); - if (m_data->profile) free(m_data->profile); - m_data->profile = (char*)malloc(strlen(orderProfile) + 1); - strcpy(m_data->profile, orderProfile); + if (this->profile != profile) this->profile = profile; } void Ord::checkout(Member& member) { - interchange_ord_checkout(m_data, member.data(), + order_profile = (char*)malloc(profile.size() + 1); + strcpy(order_profile, profile.toLatin1().constData()); + interchange_ord_checkout(order_profile, member.data(), [](interchange_response* response) { + free(order_profile); ord->emitTransaction(QString{response->data}); interchange_free_response(response); }); -- cgit v1.2.3