title: Shopify line items using webhook when order updated
body: <p>I am using shopify webhook to update my sql server's 'qty' field  when order updated, 
  below is my php code </p>
  
  <pre><code>?php
  $xmlData = fopen('php://input' , 'rb'); 
  while (!feof($xmlData)) { $xmlString .= fread($xmlData, 4096); }
  fclose($xmlData);
  $xml = new SimplexmlElement($xmlString);
  
  
  file_put_contents('orders/order' . '.xml', $xmlString);
  
  
  
  $dom = new DomDocument();
  
  $dom-&gt;load('orders/order.xml');
  
  $itemList = $dom-&gt;getElementsByTagName('line-item');
  foreach($itemList as $item) {
    $sku='';
    $qty='';
    foreach($item-&gt;childNodes as $child) {
      if ($child-&gt;localName == 'sku') {
        $sku = $child-&gt;textContent;
      }
      if ($child-&gt;localName == 'quantity') {
        $qty = $child-&gt;textContent;
      }
    }
    mysql_connect ("?????????????????????????");
  mysql_select_db("??????????");
  
  $query = "UPDATE xcart_categories SET product_count = product_count - $qty WHERE description='$sku';";
  
  mysql_query($query);
  }
  </code></pre>
  
  <p>and below is xml file i am getting from shopify webhook</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;order&gt;
    &lt;buyer-accepts-marketing type="boolean"&gt;true&lt;/buyer-accepts-marketing&gt;
    &lt;closed-at type="datetime" nil="true"&gt;&lt;/closed-at&gt;
    &lt;currency&gt;USD&lt;/currency&gt;
    &lt;email&gt;yeongju_l@yahoo.com&lt;/email&gt;
    &lt;financial-status&gt;pending&lt;/financial-status&gt;
    &lt;fulfillment-status&gt;fulfilled&lt;/fulfillment-status&gt;
    &lt;gateway&gt;Local Pick-Up&lt;/gateway&gt;
    &lt;id type="integer"&gt;140303247&lt;/id&gt;
    &lt;name&gt;#1012&lt;/name&gt;
    &lt;note&gt;&lt;/note&gt;
    &lt;number type="integer"&gt;12&lt;/number&gt;
    &lt;subtotal-price type="decimal"&gt;0.2&lt;/subtotal-price&gt;
    &lt;taxes-included type="boolean"&gt;false&lt;/taxes-included&gt;
    &lt;total-discounts type="decimal"&gt;0.0&lt;/total-discounts&gt;
    &lt;total-line-items-price type="decimal"&gt;0.2&lt;/total-line-items-price&gt;
    &lt;total-price type="decimal"&gt;0.2&lt;/total-price&gt;
    &lt;total-price-usd type="decimal"&gt;0.2&lt;/total-price-usd&gt;
    &lt;total-tax type="decimal"&gt;0.0&lt;/total-tax&gt;
    &lt;total-weight type="integer"&gt;0&lt;/total-weight&gt;
    &lt;updated-at type="datetime"&gt;2012-09-16T21:20:07-04:00&lt;/updated-at&gt;
    &lt;created-at type="datetime"&gt;2012-09-16T21:08:30-04:00&lt;/created-at&gt;
    &lt;token&gt;dcf523d93c68159c15a7c8d1fabbee07&lt;/token&gt;
    &lt;landing-site&gt;/products/test&lt;/landing-site&gt;
    &lt;referring-site&gt;&lt;/referring-site&gt;
    &lt;cancelled-at type="datetime" nil="true"&gt;&lt;/cancelled-at&gt;
    &lt;cancel-reason nil="true"&gt;&lt;/cancel-reason&gt;
    &lt;cart-token&gt;a9a7bc5d8103f6a3bb45e827f0cb8928&lt;/cart-token&gt;
    &lt;browser-ip nil="true"&gt;&lt;/browser-ip&gt;
    &lt;landing-site-ref nil="true"&gt;&lt;/landing-site-ref&gt;
    &lt;order-number type="integer"&gt;1012&lt;/order-number&gt;
    &lt;discount-codes type="array"/&gt;
    &lt;note-attributes type="array"&gt;
    &lt;/note-attributes&gt;
    &lt;processing-method&gt;manual&lt;/processing-method&gt;
    &lt;line-items type="array"&gt;
      &lt;line-item&gt;
        &lt;id type="integer"&gt;228531213&lt;/id&gt;
        &lt;requires-shipping type="boolean"&gt;false&lt;/requires-shipping&gt;
        &lt;fulfillment-service&gt;manual&lt;/fulfillment-service&gt;
        &lt;grams type="integer"&gt;0&lt;/grams&gt;
        &lt;price type="decimal"&gt;0.2&lt;/price&gt;
        &lt;quantity type="integer"&gt;1&lt;/quantity&gt;
        &lt;sku&gt;1234567&lt;/sku&gt;
        &lt;title&gt;test&lt;/title&gt;
        &lt;product-id type="integer"&gt;104663831&lt;/product-id&gt;
        &lt;variant-id type="integer"&gt;240660979&lt;/variant-id&gt;
        &lt;vendor&gt;5 Second&lt;/vendor&gt;
        &lt;variant-title nil="true"&gt;&lt;/variant-title&gt;
        &lt;fulfillment-status&gt;fulfilled&lt;/fulfillment-status&gt;
        &lt;name&gt;test&lt;/name&gt;
        &lt;variant-inventory-management&gt;&lt;/variant-inventory-management&gt;
        &lt;properties type="array"&gt;
        &lt;/properties&gt;
      &lt;/line-item&gt;
    &lt;/line-items&gt;
    &lt;shipping-lines type="array"/&gt;
    &lt;tax-lines type="array"&gt;
      &lt;tax-line&gt;
        &lt;title&gt;NY State Tax&lt;/title&gt;
        &lt;price type="decimal"&gt;0.0&lt;/price&gt;
        &lt;rate type="float"&gt;0.04&lt;/rate&gt;
      &lt;/tax-line&gt;
      &lt;tax-line&gt;
        &lt;title&gt;Queens County Tax&lt;/title&gt;
        &lt;price type="decimal"&gt;0.0&lt;/price&gt;
        &lt;rate type="float"&gt;0.04875&lt;/rate&gt;
      &lt;/tax-line&gt;
    &lt;/tax-lines&gt;
    &lt;billing-address&gt;
      &lt;first-name&gt;Yeongju&lt;/first-name&gt;
      &lt;last-name&gt;Lee&lt;/last-name&gt;
      &lt;address1&gt;14809 northern blvd&lt;/address1&gt;
      &lt;address2&gt;&lt;/address2&gt;
      &lt;city&gt;Flushing&lt;/city&gt;
      &lt;company&gt;&lt;/company&gt;
      &lt;country&gt;United States&lt;/country&gt;
      &lt;phone&gt;&lt;/phone&gt;
      &lt;province&gt;New York&lt;/province&gt;
      &lt;zip&gt;11354&lt;/zip&gt;
      &lt;latitude type="decimal"&gt;40.76529&lt;/latitude&gt;
      &lt;longitude type="decimal"&gt;-73.81831&lt;/longitude&gt;
      &lt;name&gt;Yeongju Lee&lt;/name&gt;
      &lt;country-code&gt;US&lt;/country-code&gt;
      &lt;province-code&gt;NY&lt;/province-code&gt;
    &lt;/billing-address&gt;
    &lt;fulfillments type="array"&gt;
      &lt;fulfillment&gt;
        &lt;id type="integer"&gt;67712419&lt;/id&gt;
        &lt;order-id type="integer"&gt;140303247&lt;/order-id&gt;
        &lt;created-at type="datetime"&gt;2012-09-16T21:20:07-04:00&lt;/created-at&gt;
        &lt;updated-at type="datetime"&gt;2012-09-16T21:20:07-04:00&lt;/updated-at&gt;
        &lt;tracking-number nil="true"&gt;&lt;/tracking-number&gt;
        &lt;tracking-company nil="true"&gt;&lt;/tracking-company&gt;
        &lt;status&gt;success&lt;/status&gt;
        &lt;service&gt;manual&lt;/service&gt;
        &lt;tracking-url&gt;http://www.google.com/search?q=&lt;/tracking-url&gt;
        &lt;receipt&gt;
        &lt;/receipt&gt;
        &lt;line-items type="array"&gt;
          &lt;line-item&gt;
            &lt;id type="integer"&gt;228531213&lt;/id&gt;
            &lt;requires-shipping type="boolean"&gt;false&lt;/requires-shipping&gt;
            &lt;fulfillment-service&gt;manual&lt;/fulfillment-service&gt;
            &lt;grams type="integer"&gt;0&lt;/grams&gt;
            &lt;price type="decimal"&gt;0.2&lt;/price&gt;
            &lt;quantity type="integer"&gt;1&lt;/quantity&gt;
            &lt;sku&gt;1234567&lt;/sku&gt;
            &lt;title&gt;test&lt;/title&gt;
            &lt;product-id type="integer"&gt;104663831&lt;/product-id&gt;
            &lt;variant-id type="integer"&gt;240660979&lt;/variant-id&gt;
            &lt;vendor&gt;5 Second&lt;/vendor&gt;
            &lt;variant-title nil="true"&gt;&lt;/variant-title&gt;
            &lt;fulfillment-status&gt;fulfilled&lt;/fulfillment-status&gt;
            &lt;name&gt;test&lt;/name&gt;
            &lt;variant-inventory-management&gt;&lt;/variant-inventory-management&gt;
            &lt;properties type="array"&gt;
            &lt;/properties&gt;
          &lt;/line-item&gt;
        &lt;/line-items&gt;
      &lt;/fulfillment&gt;
    &lt;/fulfillments&gt;
    &lt;customer&gt;
      &lt;id type="integer"&gt;96489088&lt;/id&gt;
      &lt;email&gt;yeongju_l@yahoo.com&lt;/email&gt;
      &lt;accepts-marketing type="boolean"&gt;true&lt;/accepts-marketing&gt;
      &lt;first-name&gt;Yeongju&lt;/first-name&gt;
      &lt;last-name&gt;Lee&lt;/last-name&gt;
      &lt;orders-count type="integer"&gt;12&lt;/orders-count&gt;
      &lt;total-spent type="decimal"&gt;16.26&lt;/total-spent&gt;
      &lt;note nil="true"&gt;&lt;/note&gt;
      &lt;created-at type="datetime"&gt;2012-08-17T11:31:50-04:00&lt;/created-at&gt;
      &lt;updated-at type="datetime"&gt;2012-09-16T21:20:07-04:00&lt;/updated-at&gt;
      &lt;state&gt;enabled&lt;/state&gt;
      &lt;last-order-id type="integer"&gt;140303509&lt;/last-order-id&gt;
      &lt;tags&gt;C&lt;/tags&gt;
      &lt;last-order-name&gt;#1013&lt;/last-order-name&gt;
    &lt;/customer&gt;
  &lt;/order&gt;
  </code></pre>
  
  <p>like you see i got two sku and qty because of duplicated line-item so for example when customer order one "product name - test in this case i got "-2" quantity update in my sql server sku test field , but  when i am  using webhook event when order creation it worked i mean i see only one line item but all the other cases(when order updated, when order payment, when order fullfillment..) show me duplicated line item even there is only one item ordered </p>
  
  <p>anyone who got idea to fix this thing?
  Thank you so much in advance guys......</p>