From b8680f8eecc7c7d4d3c09b6880904f3f732ea4d8 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: Wed, 17 May 2023 14:09:33 +0800 Subject: order takes custom options paramters --- interchange.cxx | 17 ++++++++++++++--- interchange.hxx | 4 +++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/interchange.cxx b/interchange.cxx index 21a1fb5..c8c6a6e 100644 --- a/interchange.cxx +++ b/interchange.cxx @@ -4,8 +4,8 @@ namespace QInterchange { static Interchange* interchange; - static char *mv_sku = nullptr, *mv_order_item = nullptr; static int sampleUrlLength = 0; + static char *mv_sku = nullptr, *mv_order_item = nullptr; Interchange::Interchange(const char* sampleURL, const char* image_Dir, const QString& cookie, const QString& certificate) @@ -72,7 +72,7 @@ namespace QInterchange { } void Interchange::order(const QString &sku, const QString &item, - const int quantity) + const int quantity, const QVariant &options) { mv_sku = (char *)malloc(sku.size() + 1); strcpy(mv_sku, sku.toLatin1().constData()); @@ -83,8 +83,19 @@ namespace QInterchange { mv_order_item = (char *)malloc(item.size() + 1); strcpy(mv_order_item, item.toLatin1().constData()); } + auto opts = options.toList(); + auto size = opts.size(); + const char *mv_order_s[size + 1][2]; + for (int i = 0; i < size; i++) { + auto pair = opts.at(i).toList(); + mv_order_s[i][0] = pair.at(0) + .toByteArray().constData(); + mv_order_s[i][1] = pair.at(1) + .toByteArray().constData(); + } + mv_order_s[size][0] = nullptr; interchange_ord_order(mv_sku, mv_order_item, quantity, - [](interchange_response *response) { + mv_order_s, [](interchange_response *response) { free(mv_sku); mv_sku = nullptr; free(mv_order_item); diff --git a/interchange.hxx b/interchange.hxx index 582a007..cdd3e9a 100644 --- a/interchange.hxx +++ b/interchange.hxx @@ -64,10 +64,12 @@ namespace QInterchange { * \param sku The product or variant SKU of the item. * \param item The product SKU of the item to order. * \param quantity The quantity of the item to order. + * \param opts Any additional pairs of custom options. */ void order(const QString &sku, const QString &item = "", - const int quantity = 1); + const int quantity = 1, + const QVariant &options = {}); signals: void gotPage(QString const& path, -- cgit v1.2.3