-
Notifications
You must be signed in to change notification settings - Fork 44
/
StateMachineService.php
39 lines (30 loc) · 1.42 KB
/
StateMachineService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php declare(strict_types=1);
namespace Vin\ShopwareSdk\Service;
/**
*
* Class StateMachineService
* @package Vin\ShopwareSdk\Service
*/
class StateMachineService extends ApiService
{
public function getState(string $entity, string $entityId, array $data = [], array $headers = []): ApiResponse
{
$data['stateFieldName'] = array_key_exists('stateFieldName', $data) ? $data['stateFieldName'] : 'stateId';
$path = sprintf('/api/_action/state-machine/%s/%s/state', $entity, $entityId);
$response = $this->httpClient->get($this->getFullUrl($path), [
'body' => json_encode($data),
'headers' => $this->getBasicHeaders($headers)
]);
$contents = self::handleResponse($response->getBody()->getContents(), $response->getHeaders());
return new ApiResponse($contents, $response->getHeaders(), $response->getStatusCode());
}
public function transitionState(string $entity, string $entityId, string $actionName, array $data = [], array $headers = []): void
{
$data['stateFieldName'] = array_key_exists('stateFieldName', $data) ? $data['stateFieldName'] : 'stateId';
$path = sprintf('/api/_action/state-machine/%s/%s/state/%s', $entity, $entityId, $actionName);
$this->httpClient->post($this->getFullUrl($path), [
'body' => json_encode($data),
'headers' => $this->getBasicHeaders($headers)
]);
}
}