I am tring to create a table dinamically with the products of a Magento order using API result.
I have the following PHP code to dinamically generate a table with Json content
$data = json_decode($resp, true);
/*Initializing temp variable to design table dynamically*/
$temp = "<table>";
/*Defining table Column headers depending upon JSON records*/
$temp .= "<tr><th>Order ID</th>";
$temp .= "<th>Sku</th>";
$temp .= "<th>Nome</th>";
$temp .= "<th>Quantità</th></tr>";
/*Dynamically generating rows & columns*/
for($i = 0; $i < sizeof($data["items"]); $i++)
{
$temp .= "<tr>";
$temp .= "<td>" . $data["items"][$i]["items"] . "</td>";
$temp .= "<td>" . $data["items"][$i]["sku"] . "</td>";
$temp .= "<td>" . $data["items"][$i]["name"] . "</td>";
$temp .= "<td>" . $data["items"][$i]["qty_ordered"] . "</td>";
$temp .= "</tr>";
}
/*End tag of table*/
$temp .= "</table>";
/*Printing temp variable which holds table*/
echo $temp;
In this way is not working because the products are in the second deep "items" node (json)
{
"items": [{
"items": [{
"name": "Product 1",
"order_id": 54228,
"qty_ordered": 2,
"sku": "190289855757"
}, {
"name": "Product 2",
"order_id": 54228,
"qty_ordered": 1,
"sku": "4062051502434"
}]
}]
}
Decoded version
Array ( [items] => Array ( [0] => Array ( [items] => Array ( [0] => Array ( [name] => Product 1 [order_id] => 54228 [qty_ordered] => 2 [sku] => 190289855757 ) [1] => Array ( [name] => Product 2 [order_id] => 54228 [qty_ordered] => 1 [sku] => 4062051502434 ) ) ) ) )
I used the following API call
https://mywebsite.com/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=entity_id&searchCriteria[filter_groups][0][filters][0][value]=1&searchCriteria[filter_groups][0][filters][0][condition_type]=eq&fields=items[entity_id]&fields=items[items[order_id,sku,name,qty_ordered]]&searchCriteria[pageSize]=1
Is there a way to get just the second node items result or a way to set the for so that it counts just the second deep node containing "item"