summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-05-13 18:06:01 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-05-13 18:06:01 +0800
commit8899052cef9b4e8d2682279ab9bc2d3ae09cb0ce (patch)
tree05375fb9931fb03235cbe13044101ad177307afd
parent77ded2a3b9142073f1ea74b948ad3219c6b245df (diff)
Function for updating quantity
-rw-r--r--interchange/ord.h15
-rw-r--r--ord.c15
2 files changed, 25 insertions, 5 deletions
diff --git a/interchange/ord.h b/interchange/ord.h
index 16c4e64..fa55da1 100644
--- a/interchange/ord.h
+++ b/interchange/ord.h
@@ -38,14 +38,25 @@ void interchange_ord_order(const char *sku,
void (*handler)(interchange_response *));
/*!
+ * \brief For updating the quantity of an item in a cart.
+ * \param name The name given, in the cart, to the item.
+ * \param quantity The desired quantity.
+ * \param orderpage The order page, by default it's ord/basket.
+ * \param nextpage The page to expect response from, whatever the result is.
+ * \param parser Function for parsing the formatted response.
+ */
+void interchange_ord_update(const char *name, const unsigned int quantity,
+ const char *orderpage, const char *nextpage,
+ void (*parser)(interchange_response *));
+
+/*!
* \brief For removing an item from a cart.
* \param name The name given, in the cart, to the item.
* \param orderpage The order page, by default it's ord/basket.
* \param nextpage The page to expect response from, whatever the result is.
* \param parser Function for parsing the formatted response.
*/
-void interchange_ord_remove(const char *name, const char *orderpage,
- const char *nextpage, void (*parser)(interchange_response *));
+#define interchange_ord_remove(a, b, c, d) interchange_ord_update(a, 0, b, c, d)
/*!
* \brief For checking out items in the cart.
diff --git a/ord.c b/ord.c
index a3019e7..8ffe17c 100644
--- a/ord.c
+++ b/ord.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "request.h"
@@ -11,13 +12,21 @@ void interchange_ord_order(const char *sku,
request(handler, NULL, NULL, "%s%s", "order?mv_arg=", sku);
}
-void interchange_ord_remove(const char *name, const char *orderpage,
- const char *nextpage, void (*parser)(interchange_response *))
+void interchange_ord_update(const char *name, const unsigned int quantity,
+ const char *orderpage, const char *nextpage,
+ void (*parser)(interchange_response *))
{
+ 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 + (nextpage ? 1 : 0), {
{ "mv_quantity_update", "1" },
{ "mv_doit", "refresh" },
- { name, "0" },
+ { name, qty_str },
{ "mv_orderpage", orderpage ? orderpage : "ord/basket" },
{ "mv_nextpage", nextpage }
}}, "%s", "process");