From b8ef74e598edca39ab68c5319308a881c526e8f1 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: Fri, 31 Mar 2023 17:19:51 +0800 Subject: Method for removing an item from the cart --- interchange/ord.hxx | 5 ++++- ord.cxx | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/interchange/ord.hxx b/interchange/ord.hxx index 7405c55..a0cb885 100644 --- a/interchange/ord.hxx +++ b/interchange/ord.hxx @@ -47,17 +47,20 @@ namespace QInterchange { double totalCost() const { return m_totalCost; } void setProfile(QString const& profile); public slots: -// void remove(unsigned int const& indices); + void remove(const QString &name, + const QString &nextPage); void checkout(const Member& member); signals: void rowCountChanged(); void subtotalChanged(); void shippingChanged(); void totalCostChanged(); + void removed(const QString &response); void gotTransaction(QString const& response); protected: QHash roleNames() const Q_DECL_OVERRIDE; + void emitRemoval(const QString &response); void emitTransaction(QString const& response); private: diff --git a/ord.cxx b/ord.cxx index 2a696c8..e5463ee 100644 --- a/ord.cxx +++ b/ord.cxx @@ -6,6 +6,7 @@ namespace QInterchange { static Ord* ord; + static char *item_name, *next_page; static char* order_profile; static char *fname, *lname, *address1, *address2, *city, *state, *zip, *phone_day, *email; @@ -88,6 +89,25 @@ namespace QInterchange { if (this->profile != profile) this->profile = profile; } + void Ord::remove(const QString &name, const QString &nextPage) + { + item_name = (char *)malloc(name.size() + 1); + strcpy(item_name, name.toLatin1().constData()); + if (nextPage.isEmpty()) + next_page = nullptr; + else { + next_page = (char *)malloc(nextPage.size() + 1); + strcpy(next_page, nextPage.toLatin1().constData()); + } + interchange_ord_remove(item_name, next_page, + [](interchange_response *response) { + free(item_name); + if (next_page) free(next_page); + ord->emitRemoval(QString{response->data}); + interchange_free_response(response); + }); + } + void Ord::checkout(const Member& member) { order_profile = (char*)malloc(profile.size() + 1); @@ -140,6 +160,11 @@ namespace QInterchange { }); } + void Ord::emitRemoval(const QString &response) + { + emit removed(response); + } + void Ord::emitTransaction(QString const& response) { emit gotTransaction(response); -- cgit v1.2.3