diff --git a/src/Client.php b/src/Client.php index 3344115..c7afb62 100644 --- a/src/Client.php +++ b/src/Client.php @@ -48,13 +48,23 @@ class Client return json_decode($data->getBody()->getContents(), true); } - public function put(string $url, array $data) + public function put(string $url, array $data): void { $this->client->put($url, [ RequestOptions::JSON => $data, ]); } + public function putFile(string $url, string $image): void + { + $this->client->put($url, [ + RequestOptions::BODY => $image, + RequestOptions::HEADERS => [ + 'Content-Type' => 'application/octet-stream' + ], + ]); + } + public function get(string $url, array $parameters = []): array { $data = $this->client->get($url, [ diff --git a/src/GrocyClient.php b/src/GrocyClient.php index d191265..79d7f95 100644 --- a/src/GrocyClient.php +++ b/src/GrocyClient.php @@ -87,6 +87,11 @@ class GrocyClient ]); } + public function uploadPicture(string $fileName, string $image, string $group = 'productpictures') + { + $this->client->putFile(sprintf('files/%s/%s', $group, base64_encode($fileName)), $image); + } + public function getStockClient(): StockClient { return new StockClient($this->client); diff --git a/src/Objects/ProductsObject.php b/src/Objects/ProductsObject.php index 63b9616..e1217ab 100644 --- a/src/Objects/ProductsObject.php +++ b/src/Objects/ProductsObject.php @@ -8,7 +8,7 @@ class ProductsObject extends AbstractApiObject { private string $name; - private string $description; + private ?string $description; private int $min_stock_amount = 0; @@ -20,8 +20,10 @@ class ProductsObject extends AbstractApiObject private int $qu_factor_purchase_to_stock; + private ?string $picture_file_name; + #[Ignore] - private array $userfields; + private array $userfields = []; public static function getEntity(): string { @@ -48,19 +50,19 @@ class ProductsObject extends AbstractApiObject } /** - * @return string + * @return string|null */ - public function getDescription(): string + public function getDescription(): ?string { return $this->description; } /** - * @param string $description + * @param string|null $description * * @return ProductsObject */ - public function setDescription(string $description): ProductsObject + public function setDescription(?string $description): ProductsObject { $this->description = $description; return $this; @@ -93,6 +95,7 @@ class ProductsObject extends AbstractApiObject return $this->userfields; } + #[Ignore] public function getPicnicId(): ?int { return $this->getUserfields()['picnic'] ?? null; @@ -184,4 +187,23 @@ class ProductsObject extends AbstractApiObject $this->qu_factor_purchase_to_stock = $qu_factor_purchase_to_stock; return $this; } + + /** + * @return string|null + */ + public function getPictureFileName(): ?string + { + return $this->picture_file_name; + } + + /** + * @param string|null $picture_file_name + * + * @return ProductsObject + */ + public function setPictureFileName(?string $picture_file_name): ProductsObject + { + $this->picture_file_name = $picture_file_name; + return $this; + } } \ No newline at end of file