【问题标题】:Shopify store - Upload order details to remote server on success pageShopify 商店 - 在成功页面上将订单详细信息上传到远程服务器
【发布时间】:2019-10-08 14:31:51
【问题描述】:

这是我第一次在 Shopify 商店工作。我已经能够通过自定义模板文件来更改 UI。我需要自定义订单成功页面。为此,我使用 admin/settings/checkout->Order Processing->Additional scripts 来注入液体代码。成功创建订单后,我想以 CSV/XML 格式获取订单/客户详细信息并将其上传到远程 FTP。有可能吗?

非常感谢任何帮助。

谢谢。

【问题讨论】:

    标签: xml csv ftp shopify shopify-template


    【解决方案1】:

    是的,这是可能的。但建议不要从订单状态页面发出任何 AJAX 调用,而是使用Shopify Webhooks。对于您的特定场景,您需要收听 Order Create webhook。每当创建新订单时,您都会在您的 webhook 处理程序上收到一个有效负载,其中包含订单和客户信息。

    订单创建 webhook 的示例数据

    {
      "id": 820982911946154508,
      "email": "jon@doe.ca",
      "closed_at": null,
      "created_at": "2019-10-03T16:11:21-04:00",
      "updated_at": "2019-10-03T16:11:21-04:00",
      "number": 234,
      "note": null,
      "token": "123456abcd",
      "gateway": null,
      "test": true,
      "total_price": "403.00",
      "subtotal_price": "393.00",
      "total_weight": 0,
      "total_tax": "0.00",
      "taxes_included": false,
      "currency": "USD",
      "financial_status": "voided",
      "confirmed": false,
      "total_discounts": "5.00",
      "total_line_items_price": "398.00",
      "cart_token": null,
      "buyer_accepts_marketing": true,
      "name": "#9999",
      "referring_site": null,
      "landing_site": null,
      "cancelled_at": "2019-10-03T16:11:21-04:00",
      "cancel_reason": "customer",
      "total_price_usd": null,
      "checkout_token": null,
      "reference": null,
      "user_id": null,
      "location_id": null,
      "source_identifier": null,
      "source_url": null,
      "processed_at": null,
      "device_id": null,
      "phone": null,
      "customer_locale": "en",
      "app_id": null,
      "browser_ip": null,
      "landing_site_ref": null,
      "order_number": 1234,
      "discount_applications": [
        {
          "type": "manual",
          "value": "5.0",
          "value_type": "fixed_amount",
          "allocation_method": "one",
          "target_selection": "explicit",
          "target_type": "line_item",
          "description": "Discount",
          "title": "Discount"
        }
      ],
      "discount_codes": [
      ],
      "note_attributes": [
      ],
      "payment_gateway_names": [
        "visa",
        "bogus"
      ],
      "processing_method": "",
      "checkout_id": null,
      "source_name": "web",
      "fulfillment_status": "pending",
      "tax_lines": [
      ],
      "tags": "",
      "contact_email": "jon@doe.ca",
      "order_status_url": "https:\/\/apple.myshopify.com\/690933842\/orders\/123456abcd\/authenticate?key=abcdefg",
      "presentment_currency": "USD",
      "total_line_items_price_set": {
        "shop_money": {
          "amount": "398.00",
          "currency_code": "USD"
        },
        "presentment_money": {
          "amount": "398.00",
          "currency_code": "USD"
        }
      },
      "total_discounts_set": {
        "shop_money": {
          "amount": "5.00",
          "currency_code": "USD"
        },
        "presentment_money": {
          "amount": "5.00",
          "currency_code": "USD"
        }
      },
      "total_shipping_price_set": {
        "shop_money": {
          "amount": "10.00",
          "currency_code": "USD"
        },
        "presentment_money": {
          "amount": "10.00",
          "currency_code": "USD"
        }
      },
      "subtotal_price_set": {
        "shop_money": {
          "amount": "393.00",
          "currency_code": "USD"
        },
        "presentment_money": {
          "amount": "393.00",
          "currency_code": "USD"
        }
      },
      "total_price_set": {
        "shop_money": {
          "amount": "403.00",
          "currency_code": "USD"
        },
        "presentment_money": {
          "amount": "403.00",
          "currency_code": "USD"
        }
      },
      "total_tax_set": {
        "shop_money": {
          "amount": "0.00",
          "currency_code": "USD"
        },
        "presentment_money": {
          "amount": "0.00",
          "currency_code": "USD"
        }
      },
      "line_items": [
        {
          "id": 866550311766439020,
          "variant_id": 808950810,
          "title": "IPod Nano - 8GB",
          "quantity": 1,
          "sku": "IPOD2008PINK",
          "variant_title": null,
          "vendor": null,
          "fulfillment_service": "manual",
          "product_id": 632910392,
          "requires_shipping": true,
          "taxable": true,
          "gift_card": false,
          "name": "IPod Nano - 8GB",
          "variant_inventory_management": "shopify",
          "properties": [
          ],
          "product_exists": true,
          "fulfillable_quantity": 1,
          "grams": 567,
          "price": "199.00",
          "total_discount": "0.00",
          "fulfillment_status": null,
          "price_set": {
            "shop_money": {
              "amount": "199.00",
              "currency_code": "USD"
            },
            "presentment_money": {
              "amount": "199.00",
              "currency_code": "USD"
            }
          },
          "total_discount_set": {
            "shop_money": {
              "amount": "0.00",
              "currency_code": "USD"
            },
            "presentment_money": {
              "amount": "0.00",
              "currency_code": "USD"
            }
          },
          "discount_allocations": [
          ],
          "tax_lines": [
          ]
        },
        {
          "id": 141249953214522974,
          "variant_id": 808950810,
          "title": "IPod Nano - 8GB",
          "quantity": 1,
          "sku": "IPOD2008PINK",
          "variant_title": null,
          "vendor": null,
          "fulfillment_service": "manual",
          "product_id": 632910392,
          "requires_shipping": true,
          "taxable": true,
          "gift_card": false,
          "name": "IPod Nano - 8GB",
          "variant_inventory_management": "shopify",
          "properties": [
          ],
          "product_exists": true,
          "fulfillable_quantity": 1,
          "grams": 567,
          "price": "199.00",
          "total_discount": "5.00",
          "fulfillment_status": null,
          "price_set": {
            "shop_money": {
              "amount": "199.00",
              "currency_code": "USD"
            },
            "presentment_money": {
              "amount": "199.00",
              "currency_code": "USD"
            }
          },
          "total_discount_set": {
            "shop_money": {
              "amount": "5.00",
              "currency_code": "USD"
            },
            "presentment_money": {
              "amount": "5.00",
              "currency_code": "USD"
            }
          },
          "discount_allocations": [
            {
              "amount": "5.00",
              "discount_application_index": 0,
              "amount_set": {
                "shop_money": {
                  "amount": "5.00",
                  "currency_code": "USD"
                },
                "presentment_money": {
                  "amount": "5.00",
                  "currency_code": "USD"
                }
              }
            }
          ],
          "tax_lines": [
          ]
        }
      ],
      "shipping_lines": [
        {
          "id": 271878346596884015,
          "title": "Generic Shipping",
          "price": "10.00",
          "code": null,
          "source": "shopify",
          "phone": null,
          "requested_fulfillment_service_id": null,
          "delivery_category": null,
          "carrier_identifier": null,
          "discounted_price": "10.00",
          "price_set": {
            "shop_money": {
              "amount": "10.00",
              "currency_code": "USD"
            },
            "presentment_money": {
              "amount": "10.00",
              "currency_code": "USD"
            }
          },
          "discounted_price_set": {
            "shop_money": {
              "amount": "10.00",
              "currency_code": "USD"
            },
            "presentment_money": {
              "amount": "10.00",
              "currency_code": "USD"
            }
          },
          "discount_allocations": [
          ],
          "tax_lines": [
          ]
        }
      ],
      "billing_address": {
        "first_name": "Bob",
        "address1": "123 Billing Street",
        "phone": "555-555-BILL",
        "city": "Billtown",
        "zip": "K2P0B0",
        "province": "Kentucky",
        "country": "United States",
        "last_name": "Biller",
        "address2": null,
        "company": "My Company",
        "latitude": null,
        "longitude": null,
        "name": "Bob Biller",
        "country_code": "US",
        "province_code": "KY"
      },
      "shipping_address": {
        "first_name": "Steve",
        "address1": "123 Shipping Street",
        "phone": "555-555-SHIP",
        "city": "Shippington",
        "zip": "40003",
        "province": "Kentucky",
        "country": "United States",
        "last_name": "Shipper",
        "address2": null,
        "company": "Shipping Company",
        "latitude": null,
        "longitude": null,
        "name": "Steve Shipper",
        "country_code": "US",
        "province_code": "KY"
      },
      "fulfillments": [
      ],
      "refunds": [
      ],
      "customer": {
        "id": 115310627314723954,
        "email": "john@test.com",
        "accepts_marketing": false,
        "created_at": null,
        "updated_at": null,
        "first_name": "John",
        "last_name": "Smith",
        "orders_count": 0,
        "state": "disabled",
        "total_spent": "0.00",
        "last_order_id": null,
        "note": null,
        "verified_email": true,
        "multipass_identifier": null,
        "tax_exempt": false,
        "phone": null,
        "tags": "",
        "last_order_name": null,
        "currency": "USD",
        "accepts_marketing_updated_at": null,
        "marketing_opt_in_level": null,
        "default_address": {
          "id": 715243470612851245,
          "customer_id": 115310627314723954,
          "first_name": null,
          "last_name": null,
          "company": null,
          "address1": "123 Elm St.",
          "address2": null,
          "city": "Ottawa",
          "province": "Ontario",
          "country": "Canada",
          "zip": "K2H7A8",
          "phone": "123-123-1234",
          "name": "",
          "province_code": "ON",
          "country_code": "CA",
          "country_name": "Canada",
          "default": true
        }
      }
    }
    

    一旦你有了这些数据,你就可以将它保存在某个数据库中,创建 CSV,上传到 FTP 或任何你需要的东西。

    Get Started with Shopify Webhooks

    【讨论】:

    • Webhook 方法看起来不错,但我设法通过其他方式获取订单数据。我正在使用管理面板中的附加脚本选项添加这样的代码 {{ order_number }} {% for line in checkout.line_items %} {{ line.title }} {% endfor %} 它似乎工作正常。我似乎无法找到创建远程 FTP 连接并上传 CSV 文件的方法。
    • 这就是为什么,我已经提到了推荐的方法。您尝试做的事情非常脆弱,并且大部分时间都会失败。您无法在客户端安全地保存 FTP 凭据,而且我不知道有任何可行的方法可以从客户端 JavaScript 创建 FTP 连接。
    • 我查看了 webhook,似乎我可以使用订单创建事件 webhook 并将有效负载发布到远程 URL,在那里我可以用 PHP 编写代码来创建 FTP 并上传文件。我会尝试这种方法,看看它是否有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2011-12-11
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多