From baef8cc91f5fd86cde021acc6a9630cca009669f 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, 14 May 2023 16:26:04 +0800 Subject: Improve the order implementation --- interchange.cxx | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'interchange.cxx') diff --git a/interchange.cxx b/interchange.cxx index 6108547..21a1fb5 100644 --- a/interchange.cxx +++ b/interchange.cxx @@ -4,6 +4,7 @@ namespace QInterchange { static Interchange* interchange; + static char *mv_sku = nullptr, *mv_order_item = nullptr; static int sampleUrlLength = 0; Interchange::Interchange(const char* sampleURL, const char* image_Dir, @@ -70,6 +71,29 @@ namespace QInterchange { defaultCatalog("All-Products"); } + void Interchange::order(const QString &sku, const QString &item, + const int quantity) + { + mv_sku = (char *)malloc(sku.size() + 1); + strcpy(mv_sku, sku.toLatin1().constData()); + if (item.isEmpty()) { + mv_order_item = (char *)malloc(sku.size() + 1); + strcpy(mv_order_item, sku.toLatin1().constData()); + } else { + mv_order_item = (char *)malloc(item.size() + 1); + strcpy(mv_order_item, item.toLatin1().constData()); + } + interchange_ord_order(mv_sku, mv_order_item, quantity, + [](interchange_response *response) { + free(mv_sku); + mv_sku = nullptr; + free(mv_order_item); + mv_order_item = nullptr; + interchange->emitOrder(QString{response->data}); + interchange_free_response(response); + }); + } + void Interchange::emitPage(QString const& path, QString const& response) { emit gotPage(path, response); @@ -85,17 +109,8 @@ namespace QInterchange { emit gotProduct(response); } - void Interchange::emitOrder(QString const& response) + void Interchange::emitOrder(const QString &response) { emit gotOrder(response); } - - void Interchange::order(QString const& sku) - { - interchange_ord_order(sku.toLatin1().constData(), - [](interchange_response* response) { - interchange->emitOrder(QString{response->data}); - interchange_free_response(response); - }); - } } -- cgit v1.2.3