Shopify Webhook to Mysql PHP multiple line items and properties

chrisfewster
New Member
1 0 0

Hi so i am trying to transfer orders made to an SQL database so far set up an easy table with order info going to it all works fine shown below 

    try { 
          $link = new PDO($sql, $username, $password);
          //echo "<p> DB Connect = Success.</p>";
        } catch (PDOException $error) {
          echo 'Connection error: ' . $error->getMessage();
        }

//Assign to variable 
			$order_no = $data['order_number'];
			$fullname = $data['billing_address']['name'];
			$email = $data['email'];
			$order_item = $data['line_items']['0']['title'];
			$fullname 	= $data['billing_address']['name'];
			$address = $data['billing_address']['address1'];
			$city = $data['billing_address']['city'];
			$postcode = $data ['billing_address']['zip'];




			
$stmt = $link->query("INSERT INTO orders(order_number, name, email, address, city, postcode)
								VALUES ('$order_no', '$fullname','$email', '$address', '$city', '$postcode')");

 

Now I want to somehow add line items to the table so each item ordered and the properties it holds example of a line item is below 

  "line_items": [
    {
      "id": 9012009762986,
      "variant_id": 37627266498730,
      "title": "Letter From Santa",
      "quantity": 1,
      "sku": "",
      "variant_title": "",
      "vendor": "tools for santa",
      "fulfillment_service": "manual",
      "product_id": 6090658054314,
      "requires_shipping": true,
      "taxable": true,
      "gift_card": false,
      "name": "Letter From Santa",
      "variant_inventory_management": null,
      "properties": [
        {
          "name": "_Paper Type",
          "value": "plain"
        },
        {
          "name": "_Child's Name",
          "value": "Steve"
        },
        {
          "name": "_Child's Age",
          "value": "22"
        },
        {
          "name": "_Town Child Is From",
          "value": "burnley"
        },
        {
          "name": "_Toy they have asked for or want",
          "value": "Xbox"
        },
        {
          "name": "_An achievement / something they are proud of themselves for",
          "value": "adsfdd"
        },
        {
          "name": "upsellcheckquantity",
          "value": ""
        }
      ],
      "product_exists": true,
      "fulfillable_quantity": 1,
      "grams": 0,
      "price": "0.00",
      "total_discount": "0.00",
      "fulfillment_status": null,
      "price_set": {
        "shop_money": {
          "amount": "0.00",
          "currency_code": "GBP"
        },
        "presentment_money": {
          "amount": "0.00",
          "currency_code": "GBP"
        }
      },
      "total_discount_set": {
        "shop_money": {
          "amount": "0.00",
          "currency_code": "GBP"
        },
        "presentment_money": {
          "amount": "0.00",
          "currency_code": "GBP"
        }
      },
      "discount_allocations": [],
      "duties": [],
      "admin_graphql_api_id": "gid://shopify/LineItem/9012009762986",
      "tax_lines": [],
      "origin_location": {
        "id": 2581140373674,
        "country_code": "GB",
        "province_code": "",
        "name": "tools for santa",
        "address1": "32 Dovedale Drive",
        "address2": "",
        "city": "Burnley",
        "zip": "BB12 8XD"
      }
    },

so i want to add this into a table so how can i do this ? Any help much appreciated !!

 

0 Likes