|
7 | 7 | class MediaFileApi extends AbstractApi |
8 | 8 | { |
9 | 9 | /** |
10 | | - * Upload a product media file and return the server response. |
| 10 | + * Upload a product media file alongside the required UnoPim form fields. |
11 | 11 | * |
| 12 | + * @param string $filePath |
| 13 | + * @param string $sku |
| 14 | + * @param string $attribute |
12 | 15 | * @return array<string, mixed> |
13 | 16 | */ |
14 | | - public function uploadProductMedia(string $filePath): array |
| 17 | + public function uploadProductMedia(string $filePath, string $sku = '', string $attribute = ''): array |
15 | 18 | { |
16 | | - return $this->client->uploadFile('/api/v1/rest/media-files/product', $filePath); |
| 19 | + $fields = array_filter([ |
| 20 | + 'sku' => $sku, |
| 21 | + 'attribute' => $attribute, |
| 22 | + ], static fn ($v) => $v !== ''); |
| 23 | + |
| 24 | + return $this->client->uploadFile('/api/v1/rest/media-files/product', $filePath, $fields); |
17 | 25 | } |
18 | 26 |
|
19 | 27 | /** |
20 | | - * Upload a category media file and return the server response. |
| 28 | + * Upload a category media file alongside the required UnoPim form fields. |
21 | 29 | * |
| 30 | + * @param string $filePath |
| 31 | + * @param string $code |
| 32 | + * @param string $attribute |
22 | 33 | * @return array<string, mixed> |
23 | 34 | */ |
24 | | - public function uploadCategoryMedia(string $filePath): array |
| 35 | + public function uploadCategoryMedia(string $filePath, string $code = '', string $attribute = ''): array |
25 | 36 | { |
26 | | - return $this->client->uploadFile('/api/v1/rest/media-files/category', $filePath); |
| 37 | + $fields = array_filter([ |
| 38 | + 'code' => $code, |
| 39 | + 'attribute' => $attribute, |
| 40 | + ], static fn ($v) => $v !== ''); |
| 41 | + |
| 42 | + return $this->client->uploadFile('/api/v1/rest/media-files/category', $filePath, $fields); |
27 | 43 | } |
28 | 44 | } |
0 commit comments