summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-05-17 14:09:33 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-05-17 14:09:33 +0800
commitb8680f8eecc7c7d4d3c09b6880904f3f732ea4d8 (patch)
treeaac2641f325fcf667ddf75858a13f984eb48c614
parent5b457c0d69377c786436476d67476eee1c922462 (diff)
order takes custom options paramters
-rw-r--r--interchange.cxx17
-rw-r--r--interchange.hxx4
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,