function updateProductPrices($apiUrl, $productId, $dataArray) {
$productData = [
'price-updates' => [
'action' => 'upsert',
'entity' => 'product',
'payload' => [
[
'id' => $productId,
'price' => [
'currencyID' => $dataArray['currencyId'],
'gross' => $dataArray['gross'],
'net' => $dataArray['net'],
'linked' => true
]
]
]
]
];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $apiUrl . "/_action/sync",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Accept: application/vnd.api+json, application/json",
"Content-Type: application/json",
"Authorization: " . getToken($apiUrl)
],
CURLOPT_POSTFIELDS => json_encode($productData)
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return "cURL Error #:" . $err;
} else {
return $response;
}
}
Ausgabe von print_r($productData) :
Array
(
[price-updates] => Array
(
[action] => upsert
[entity] => product
[payload] => Array
(
[0] => Array
(
[id] => 924909bd56684a0bae8e35153a01df97
[price] => Array
(
[currencyID] => b7d2554b0ce847cd82f3ac9bd1c0dfca
[gross] => 15.95
[net] => 14.906542056075
[linked] => 1
)
)
)
)
)
Ich erhalte diese Ausgabe von $response:
{"extensions":[],"success":false,"data":{"price-updates":{"extensions":[],"result":[{"entities":[],"errors":[{"code":"0","status":"500","title":"Internal Server Error","detail":"Cannot unset string offsets"}]}]}},"deleted":[],"notFound":[]}
Kann mir da jemand weiter helfen?