Shopify-需要创建一个webhook
问题描述:
我需要创建一个web-hook将用于将xml数据发布到存储库。Shopify-需要创建一个webhook
XML格式应该是这样的:
<Order OrderID="xxxx" AffiliateID="xxxxxx">
<ShipToName>Bob Sanders</ShipToName>
<ShipToContact>Bob Sanders</ShipToContact>
<ShipToName2></ShipToName2>
<AddressLine1>21 N. Long St.</AddressLine1>
<AddressLine2>Unit A</AddressLine2>
<AddressLine3></AddressLine3>
<City>Barrington Hills</City>
<Country>US</Country>
<State>Il</State>
<Province></Province>
<Zip>60010</Zip>
<Email>[email protected]</Email>
<Phone>7086639935</Phone>
<SpecialInstructions></SpecialInstructions>
<SpecialInstructions2></SpecialInstructions2>
目前是这样的:
<order>
<buyer-accepts-marketing type="boolean">true</buyer-accepts-marketing>
<cancel-reason nil="true"/>
<cancelled-at type="dateTime" nil="true"/>
<cart-token>6343c2a1ec2e675202ad9fdccb8fe862</cart-token>
<checkout-token>c62fcb629ce1df6a7202be1e4f34f237</checkout-token>
<closed-at type="dateTime" nil="true"/>
<confirmed type="boolean">true</confirmed>
<created-at type="dateTime">2014-11-24T23:22:22-07:00</created-at>
<currency>USD</currency>
<email>[email protected]</email>
<financial-status>pending</financial-status>
<fulfillment-status nil="true"/>
<gateway>Cash on Delivery (COD)</gateway>
<id type="integer">282488743</id>
<landing-site>/</landing-site>
<location-id type="integer" nil="true"/>
<name>#SH1001</name>
<note nil="true"/>
<number type="integer">1</number>
我需要改变的节点名称和抢只有少数所需的节点不是所有的人。 我不明白从哪里开始。
为了更好地了解这里的情况是网址:
- https://shibumi-home.myshopify.com/admin/orders.xml [XML需要修改]
- http://divinepnc.com/a/webhooks-shopify/a.xml [应该如何]
我没有问到为情况提供确切的代码,我所要求的是我应该如何进行。
非常感谢
答
您可以从shopify管理面板创建一个网络挂接,通知选项卡下,并要发布的数据(XML在我的情况下,它指向的网址,你也可以选择json)。
2.然后抓住shopify-xml,我使用了下面的代码,它以“timber.xml”的形式存储在服务器上。
下面是示例代码段:
$webhookContent = "";
$webhook = fopen('php://input' , 'rb');
while (!feof($webhook)) {
$webhookContent .= fread($webhook,18920);
}
fclose($webhook);
//error_log($webhookContent);
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "https://*.com/a/webhooks-shopify/timber.xml","wb");
fwrite($fp,$webhookContent);
fclose($fp);
3.对于抓住shopify-XML转换到所需的XML,我用PHP DOM LIBRARY。
下面是示例代码片段:
$doc = new DOMDocument;
$doc->load('timber.xml');
$thedocument = $doc->documentElement;
//this gives you a list of elements by tag name
$order_number = $thedocument->getElementsByTagName('order-number')->item(0);
$order_number_val = $order_number->textContent;
$shipping_address = $thedocument->getElementsByTagName('shipping-address')->item(0);
$shipping_address = $shipping_address->lastChild;
$shipping_address = $shipping_address->previousSibling;
$shipping_address = $shipping_address->previousSibling;
$shipping_address_val = $shipping_address->textContent;
$address1 = $thedocument->getElementsByTagName('shipping-address')->item(0);
$address1 = $address1->firstChild;
$address1_val = $address1->textContent;
只是解析从Shopify发送的XML,然后把你从这些部件需要的XML文件。 – 2014-11-25 20:33:18