diff options
-rw-r--r-- | interchange.cxx | 35 | ||||
-rw-r--r-- | interchange.hxx | 12 |
2 files changed, 33 insertions, 14 deletions
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); - }); - } } diff --git a/interchange.hxx b/interchange.hxx index f412377..582a007 100644 --- a/interchange.hxx +++ b/interchange.hxx @@ -61,23 +61,27 @@ namespace QInterchange { void defaultAllProducts(); /*! * \brief For putting an item to a cart. - * \param sku The SKU of the item to order. + * \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. */ - void order(QString const& sku); + void order(const QString &sku, + const QString &item = "", + const int quantity = 1); signals: void gotPage(QString const& path, QString const& response); void gotCatalog(QString const& response); void gotProduct(QString const& response); - void gotOrder(QString const& response); + void gotOrder(const QString &response); protected: void emitPage(QString const& path, QString const& response); void emitCatalog(QString const& response); void emitProduct(QString const& response); - void emitOrder(QString const& response); + void emitOrder(const QString &response); }; } |