Qt Woocommerce API返回以前的订单数据

时间:2018-12-22 07:05:30

标签: qt rest api woocommerce

我正在编写一个Qt桌面应用程序,以支持通过woocommerce REST API存储和检索Woocommerce商店的订单元数据。更新元数据值后,Qt继续报告以前的值。

一个表小部件将填充原始数据(请参阅获取代码)。用户编辑数据,放置代码用于更新woocommerce中的订单。如果用户使用其他顺序,然后又返回到先前编辑的顺序,则获取代码将带回先前的数据。

例如,使用下面的放置代码,我正在更新特定订单的元数据。在该示例中,“ _ shipment”的原始值为“ 38:1”。我想将其更改为“ 38:2”。

输入代码:

void MainWindow::ULShippmentItemMeta()
{
    //Put order item metadata back to woo

    //{"meta_data":[{"key":"_shipment","value":"38:2"}]}
    QByteArray qba = "{\"meta_data\":[{\"key\":\"_shipment\",\"value\":\"38:2\"}]}";

    QNetworkAccessManager *m_nam_putordermeta = new QNetworkAccessManager(this);

    connect(m_nam_putordermeta, SIGNAL(finished(QNetworkReply*)), this, SLOT(PostOrderItemMetaFinished(QNetworkReply*)));

    QUrl url(urlpath + "/wp-json/wc/v3/orders/853";

    QByteArray postDataSize = QByteArray::number(qba.size());
    QNetworkRequest request(url);

    request.setRawHeader("Content-Type", "application/json");
    request.setRawHeader("Content-Length", postDataSize);

    QString concatenated = api_key + ":" + api_secret;
    QByteArray data = concatenated.toLocal8Bit().toBase64();
    QString headerData = "Basic " + data;
    request.setRawHeader("Authorization", headerData.toLocal8Bit());

    m_nam_putordermeta->put(request, qba);
}

void MainWindow::PostOrderItemMetaFinished(QNetworkReply *reply)
{
    qWarning() << ("Server Replied With Code " + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString() +
                       reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString());

    reply->deleteLater();

}

Qt调试器说:

  

“服务器收到的代码为200OK”

我可以验证看跌期权是否成功,就像Postman所看到的那样:

"meta_data": [
        {
            "id": 10362,
            "key": "_shipment",
            "value": "38:2"
        }
    ]

但是,在更新后使用get代码提取值时,它将继续显示前一个值。

获取代码:

    void MainWindow::on_twOrders_cellDoubleClicked()
    {
        //The order was double clicked, so lets pull it!
        QNetworkAccessManager *m_nam_singleorder = new QNetworkAccessManager(this);

        connect(m_nam_singleorder, SIGNAL(finished(QNetworkReply*)), this, SLOT(dlSingleOrderFinished(QNetworkReply*)));

        QUrl url(urlpath + "/wp-json/wc/v3/orders/853");
        QUrlQuery query;

        url.setQuery(query.query());

        QNetworkRequest request(url);

        QString concatenated = api_key + ":" + api_secret;
        QByteArray data = concatenated.toLocal8Bit().toBase64();
        QString headerData = "Basic " + data;
        request.setRawHeader("Authorization", headerData.toLocal8Bit());

        m_nam_singleorder->get(request);
    }

void MainWindow::dlSingleOrderFinished(QNetworkReply *reply)
{            
        //Gather the order data from woo, returned in JSON
        QJsonDocument d = QJsonDocument::fromJson(reply->readAll());
        qWarning() << d;
}

Qt调试器GET输出:

"meta_data": [
            {
                "id": 10362,
                "key": "_shipment",
                "value": "38:1"
            }
        ]

尽管邮递员显示更新成功(38:2),但我不明白为什么Qt继续显示“ 38:1”。感谢对此的任何想法。

1 个答案:

答案 0 :(得分:0)

事实证明,此问题与托管站点拥有的缓存插件有关。我关闭了他们的缓存插件,现在我的数据立即按预期返回。

我仍然对为什么邮递员似乎不受影响感到好奇。那是另一天。