如何获取从Shopify Webhook删除的订单ID-Laravel和Shopify

时间:2018-11-07 12:04:16

标签: php laravel shopify webhooks

在我的教程中,我意识到我可以获取除final = [] for i in range(0, len(eg)): for j in range(0, len(gt)): gtf_row = gt[j] esse_gene_row = eg[i] gtf_column = gtf_row.split() esse_gene_column = esse_gene_row.split() gtf_symbol = gtf_columns[17] esse_gene_symbol = esse_gene_columns[0] if gtf_symbol == esse_gene_symbol: final.append(gt(j)) 以外的每个事件期间的订单编号/ id。在下面的控制器中,我尝试像对每个主题getDownloadUrl()一样检索订单号,但是随后出现错误消息:

  

未定义索引:控制器中的数字

控制器

public void createOrUpdatePostWithImage(Uri imageUri, final OnPostCreatedListener onPostCreatedListener, final Post post) {

    // Register observers to listen for when the download is done or if it fails
    DatabaseHelper databaseHelper = ApplicationHelper.getDatabaseHelper();
    if (post.getId() == null) {
        post.setId(generatePostId());
    }

    final String imageTitle = ImageUtil.generateImageTitle(UploadImagePrefix.POST, post.getId());
    UploadTask uploadTask = databaseHelper.uploadImage(imageUri, imageTitle);

    if (uploadTask != null) {
        uploadTask.addOnFailureListener(exception -> {
            // Handle unsuccessful uploads
            onPostCreatedListener.onPostSaved(false);

        }).addOnSuccessListener(taskSnapshot -> {
            // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
            Uri downloadUrl = taskSnapshot.getDownloadUrl();
            LogUtil.logDebug(TAG, "successful upload image, image url: " + String.valueOf(downloadUrl));

            post.setImagePath(String.valueOf(downloadUrl));
            post.setImageTitle(imageTitle);
            createOrUpdatePost(post);

            onPostCreatedListener.onPostSaved(true);
        });
    }
}

为什么仅Job会发生这种情况?

1 个答案:

答案 0 :(得分:3)

  

未定义索引错误

发生是因为Shopify Order Delete webhook响应中没有数字字段。此外,检查字段是否首先存在总是一个好主意。

如果您查看Shopify发送的Delete Order response,则其中仅包含

{
  "id": 777859760246
}

其中id是订单ID。但是,由于删除了订单,因此以后甚至无法通过API获取更多详细信息。根据{{​​3}},必须先取消订单,然后才能删除订单。因此,一种解决方法是也监听“订单取消”钩子,然后将此信息保存在您的Laravel应用程序(数据库等)中,然后在收到“订单删除” webhook以后使用。