Skip to content

Commit 26e8cb6

Browse files
authored
Merge pull request #22 from Invertus/BRD-224/batch-sync-endpoint
BRD-224: batch-sync-endpoint
2 parents d1ec19d + 8c926a9 commit 26e8cb6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Client/HttpClient.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public function delete(string $endpoint): array
4747
return $this->request('DELETE', $endpoint);
4848
}
4949

50+
/**
51+
* Make a PATCH request
52+
*/
53+
public function patch(string $endpoint, array $data = []): array
54+
{
55+
return $this->request('PATCH', $endpoint, $data);
56+
}
57+
5058
/**
5159
* Make HTTP request
5260
*/

src/SynchronizationApiSdk.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,34 @@ public function validateProducts(array $productsData): void
234234
$this->validator->validateProducts($productsData);
235235
}
236236

237+
/**
238+
* Update specific fields of multiple products in bulk
239+
*
240+
* @param string $index
241+
* @param array $updates Array of updates in format: [['id' => 'product_id', 'fields' => ['field' => 'value']]]
242+
* @return array Response from the API
243+
* @throws ValidationException
244+
*/
245+
public function updateProductsBulk(string $index, array $updates): array
246+
{
247+
$this->validator->validateIndex($index);
248+
249+
if (empty($updates)) {
250+
return [
251+
'status' => 'success',
252+
'message' => 'No updates provided',
253+
'updated_count' => 0,
254+
];
255+
}
256+
257+
$data = [
258+
'index_name' => $index,
259+
'updates' => $updates,
260+
];
261+
262+
return $this->httpClient->patch('api/v1/sync/update-products', $data);
263+
}
264+
237265
/**
238266
* Build embeddable fields configuration with localized fields
239267
*/

0 commit comments

Comments
 (0)