Christopher Fewster
Christopher Fewster

Reputation: 31

Shopify Webhook JSON to PHP use and post variables

Hey thanks for the help,

I have got the Webhooks pointed at my domain I have managed to get some fields to write to my database but I am having an issue posting line_items and the contents of its array into mysql .

so for example I want to pull the title for line_items which is "Aviator sunglasses"

so far I have only managed to pull the word Array into the table.

I have used this code

//Assign to variable 
            $email = $data['line_items???'];
            
$stmt = $link->query("INSERT INTO orders (test)
                                VALUES ('$email')");

this is the line items section of the array

[line_items] => Array
        (
            [0] => Array
                (
                    [id] => 487817672276298554
                    [variant_id] => 
                    [title] => Aviator sunglasses
                    [quantity] => 1
                    [sku] => SKU2006-001
                    [variant_title] => 
                    [vendor] => 
                    [fulfillment_service] => manual
                    [product_id] => 788032119674292922
                    [requires_shipping] => 1
                    [taxable] => 1
                    [gift_card] => 
                    [name] => Aviator sunglasses
                    [variant_inventory_management] => 
                    [properties] => Array
                        (
                        )

                    [product_exists] => 1
                    [fulfillable_quantity] => 1
                    [grams] => 100
                    [price] => 89.99
                    [total_discount] => 0.00
                    [fulfillment_status] => 

Upvotes: 0

Views: 254

Answers (1)

David Lazar
David Lazar

Reputation: 11427

Your variable $email is an array. An Order has many Line Items. So instead of assigning email to a table column, you have to iterate the array and grab what you want. Besides that point, a line item never has an email, so your example would be clearer if you used title when you meant title.

Upvotes: 1

Related Questions