In my tutorial, I realised that I am able to get the number/id of the order during every event except orders/delete
. In my controller below, I try to retrieve the order number just as I do for every topic ('orders/create', 'orders/paid')etc
, but then I get an error saying:
Undefined index: number in Controller
Controller
public function registerOrderDeleteWebhook()
{
$shop = Auth::user()->site;
$token = Auth::user()->access_token;
$shopify = Shopify::setShopUrl($shop)->setAccessToken($token);
Shopify::setShopUrl($shop)->setAccessToken($token)->post("admin/webhooks.json", ['webhook' =>
['topic' => 'orders/delete',
'address' => 'https://example.domain.com/order-delete-webhook',
'format' => 'json'
]
]);
}
public function orderDeleteWebhook(Request $request)
{
$order = $request->getContent();
$order = json_decode($order, true);
$order_id = $order['number'];
//send notification to Admin with order number deleted below
}
Why could this be happening for only orders/delete
?
$request
and$order
variables? Can you put the portion of code whereorderDeleteWebhook
function is called? – gomdhttps://example.domain.com/order-delete-webhook
which triggersorderDeleteWebhook
– Michael Anaman$request
and$order
variables withvar_dump
function? In order to see if the problem is in how you make the request or how you interpret the request. – gomd