summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-05-14 16:12:41 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-05-14 16:12:41 +0800
commit33c252c6b2f509b6420c24d610dd99a15cda5593 (patch)
tree62baab36017d868d455029181a290da07bdec88a
parent8899052cef9b4e8d2682279ab9bc2d3ae09cb0ce (diff)
Order can differentiate variant SKU from product
-rw-r--r--interchange/ord.h12
-rw-r--r--ord.c19
2 files changed, 23 insertions, 8 deletions
diff --git a/interchange/ord.h b/interchange/ord.h
index fa55da1..e31006e 100644
--- a/interchange/ord.h
+++ b/interchange/ord.h
@@ -30,12 +30,14 @@ extern "C" {
/*!
* \brief For putting an item to a cart.
- * \param sku The SKU of the item to order.
- * \param handler A pointer to the function when a custom handler is needed to
- * arrange the data into the order.
+ * \param sku The product or variant SKU of the item to order.
+ * \param item The product SKU of the item to order.
+ * \param quantity The quantity of the item to order.
+ * \param parser Function for parsing the formatted response.
*/
-void interchange_ord_order(const char *sku,
- void (*handler)(interchange_response *));
+void interchange_ord_order(const char *sku, const char *item,
+ const unsigned int quantity,
+ void (*parser)(interchange_response *));
/*!
* \brief For updating the quantity of an item in a cart.
diff --git a/ord.c b/ord.c
index 8ffe17c..06d1798 100644
--- a/ord.c
+++ b/ord.c
@@ -6,10 +6,23 @@
#include "interchange/member.h"
#include "interchange/ord.h"
-void interchange_ord_order(const char *sku,
- void (*handler)(interchange_response *))
+void interchange_ord_order(const char *sku, const char *item,
+ const unsigned int quantity,
+ void (*parser)(interchange_response *))
{
- request(handler, NULL, NULL, "%s%s", "order?mv_arg=", sku);
+ size_t length = 0;
+ unsigned int qty = quantity;
+ do {
+ length++;
+ } while ((qty /= 10));
+ char qty_str[length + 1];
+ sprintf(qty_str, "%d", quantity);
+ request(parser, NULL, &(struct body){ 4, {
+ { "mv_action", "refresh" },
+ { "mv_sku", sku },
+ { "mv_order_item", item },
+ { "mv_order_quantity", qty_str }
+ }}, "%s", "ord/basket");
}
void interchange_ord_update(const char *name, const unsigned int quantity,