From f56b0fb7e7b2688aa1207f511119d1efb9582553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Salo=C5=88?= Date: Mon, 22 Nov 2021 19:13:05 +0100 Subject: [PATCH] Added missing Article documentation + small fixes --- CHANGELOG.md | 16 + README.md | 10 +- doc/Article.md | 565 +++++++++++++++++++++++++++-- example/Article.php | 55 +-- src/Article/DTO/ProductRequest.php | 2 +- src/Article/DTO/VariantRequest.php | 2 +- src/Article/Entity/Product.php | 14 +- src/Order/OrderClient.php | 2 +- 8 files changed, 591 insertions(+), 75 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7c8fe0..39da918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 4.0.0-beta.2 - 2021-11-22 + +### Added + +- rest of missing `Article` documentation +- requirements to Readme + +### Changed + +- fixed small issues with documentation +- used array concat instead of `array_merge` + +### Fixed + +- `Product` entity would not return all fields in `jsonEncode` result + ## 4.0.0-beta.1 - 2021-08-25 ### Added diff --git a/README.md b/README.md index 5d42d47..bf0de1d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ MPAPI client is a tool created to help Internet Mall, a. s. partners easily manage article catalogue, deliveries, orders etc. using Mall Marketplace API. +## Requirements +- `64bit` version of `PHP 7.4` or `PHP 8` +- Guzzle 7 + ## Installation To install the client using [Composer](https://getcomposer.org/doc/00-intro.md) run following command in your repository @@ -127,9 +131,9 @@ List of custom Exceptions thrown in this client can be found [here](doc/Exceptio ## ⚠ Warning -- client does not include support for deprecated endpoints (i.e., deliveries or gifts), that will be changed, replaced or removed in the future +- client does not include support for deprecated endpoints (i.e., `/v1/deliveries` or `/v1/gifts`), that will be changed, replaced or removed in the future -### This is still a Beta release, and some documentation and examples are missing or incomplete +### This is still a Beta release, and some features are missing or incomplete -- [ ] Article client documentation - [ ] Order client documentation and examples +- [ ] Transports v2 support diff --git a/doc/Article.md b/doc/Article.md index c0d1c2f..34d71a6 100644 --- a/doc/Article.md +++ b/doc/Article.md @@ -4,12 +4,488 @@ To see example of initialization, please look at [Implementation](../README.md#implementation) part of our [README](../README.md) -## TODO: add missing product documentation +## Get list of products +Method expects [?Filter](../src/Filter/Filter.php) and returns [BasicProductList](../src/Article/Entity/BasicProductList.php) containing [BasicProduct](../src/Article/Entity/BasicProduct.php) entity. +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$productList = $articleClient->listProducts(null); +echo json_encode($productList, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +``` + +Example above prints out + +```json +{ + "paging": { + "total": 13, + "pages": 1, + "size": 13, + "page": 1 + }, + "data": [ + { + "id": "my-product-id", + "productId": 100001234567, + "title": "Product title", + "status": "A", + "stage": "live", + "inStock": 45, + "categoryId": "EG115", + "price": 34, + "purchasePrice": 0, + "rrp": 34, + "variantsCount": 3, + "hasVariants": true + }, + { + "id": "my-product-id-2", + "productId": 100001930989, + "title": "Product title 2", + "status": "A", + "stage": "live", + "inStock": 45, + "categoryId": "EG115", + "price": 34, + "purchasePrice": 0, + "rrp": 34, + "variantsCount": 3, + "hasVariants": true + }, + { + "id": "my-product-id-3", + "productId": 100001930961, + "title": "Product title 3", + "status": "A", + "stage": "live", + "inStock": 45, + "categoryId": "EG115", + "price": 34, + "purchasePrice": 0, + "rrp": 34, + "variantsCount": 0, + "hasVariants": false + }, + ... + ] +} +``` + +## Create product + +Method expects [ProductRequest](../src/Article/DTO/ProductRequest.php) and returns [Product](../src/Article/Entity/Product.php) entity. + +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$productRequest = new ProductRequest( + 'my-product-id', + 'Product title', + 'Short product description', + 'Long product description with tags', + 'EG115', + 20, + 1, +); + +// Add data required for product creation +$productRequest->setAvailability(new Availability(StatusEnum::ACTIVE(), 1)); +$productRequest->setMedia( + new MediaIterator( + new Media('https://cdn.my-domain.com/my-product-id-1.jpg', true), + new Media('https://cdn.my-domain.com/my-product-id-energy-label.jpg', false, null, true, false), + ), +); +$productRequest->setPrice(69); + +// Add optional data +$productRequest->setDimensions(new Dimensions(2, 20, 5, 20)); +$productRequest->setBrandId('BRAND_ID'); +$productRequest->setBarcode('0000123456789'); + +// Create product +// - request returns full product detail, same as calling `getProduct` method +$createdProduct = $articleClient->createProduct($productRequest); +echo json_encode($createdProduct, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +``` + +Example above prints out + +```json +{ + "stage": "live", + "categoryId": "EG115", + "vat": 20, + "variants": [], + "variableParameters": [], + "partnerTitle": null, + "brandId": "BRAND_ID", + "id": "my-product-id", + "articleId": 100001234567, + "title": "Product title", + "url": "https:\/\/www.mall.cz\/id\/100001234567", + "shortDesc": "Short product description", + "longDesc": "Long product description with tags<\/strong>", + "priority": 1, + "barcode": "0000123456789", + "price": 69, + "purchasePrice": 0, + "rrp": 69, + "media": [ + { + "url": "https:\/\/cdn.my-domain.com\/my-product-id-1.jpg", + "main": true, + "switch": null, + "energyLabel": false, + "informationList": false + }, + { + "url": "https:\/\/cdn.my-domain.com\/my-product-id-energy-label.jpg", + "main": false, + "switch": null, + "energyLabel": true, + "informationList": false + } + ], + "promotions": [], + "parameters": [], + "dimensions": { + "weight": 2, + "width": 20, + "height": 5, + "length": 20 + }, + "availability": { + "status": "A", + "inStock": 1 + }, + "labels": [], + "overrides": [], + "recommended": [], + "deliveryDelay": 3, + "freeDelivery": false, + "packageSize": "smallbox", + "mallboxAllowed": false +} +``` + +## Update product + +Method expects [ProductRequest](../src/Article/DTO/ProductRequest.php) and does not return anything. + +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$productRequest = new ProductRequest( + 'my-product-id', + 'Product title', + 'Short product description', + 'Long product description with tags', + 'EG115', + 20, + 1, +); + +// Add optional data +$productRequest->setBrandId('BRAND_ID'); +$productRequest->setBarcode('0000123456789'); + +// Update product +// - API returns same data that were sent in, which is not the same as data returned by `getProduct` method +// - that's why client does not return anything (you already have data you sent in `$productRequest` variable) +$articleClient->updateProduct($productRequest); +``` + +## Get product detail + +Method expects `product` ID and returns [Product](../src/Article/Entity/Product.php) entity. + +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$productDetail = $articleClient->getProduct('my-product-id'); +echo json_encode($productDetail, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +``` + +Example above prints out + +```json +{ + "stage": "live", + "categoryId": "EG115", + "vat": 20, + "variants": [], + "variableParameters": [], + "partnerTitle": null, + "brandId": "BRAND_ID", + "id": "my-product-id", + "articleId": 100001234567, + "title": "Product title", + "url": "https:\/\/www.mall.cz\/id\/100001234567", + "shortDesc": "Short product description", + "longDesc": "Long product description with tags<\/strong>", + "priority": 1, + "barcode": "0000123456789", + "price": 69, + "purchasePrice": 0, + "rrp": 69, + "media": [ + { + "url": "https:\/\/cdn.my-domain.com\/my-product-id-1.jpg", + "main": true, + "switch": null, + "energyLabel": false, + "informationList": false + }, + { + "url": "https:\/\/cdn.my-domain.com\/my-product-id-energy-label.jpg", + "main": false, + "switch": null, + "energyLabel": true, + "informationList": false + } + ], + "promotions": [], + "parameters": [], + "dimensions": { + "weight": 2, + "width": 20, + "height": 5, + "length": 20 + }, + "availability": { + "status": "A", + "inStock": 1 + }, + "labels": [], + "overrides": [], + "recommended": [], + "deliveryDelay": 3, + "freeDelivery": false, + "packageSize": "smallbox", + "mallboxAllowed": false +} +``` + +## Delete product + +Method expects `product` ID and does not return anything. + +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$articleClient->deleteProduct('my-product-id'); +``` + +## Get product availability + +Method expects `product` ID and returns [Availability](../src/Article/Entity/Common/Availability.php) entity. + +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$productAvailability = $articleClient->getProductAvailability('my-product-id'); +echo json_encode($productAvailability, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +``` + +Example above prints out + +```json +{ + "status": "A", + "inStock": 1 +} +``` + +## Get product pricing + +Method expects `product` ID and returns [Pricing](../src/Article/Entity/Common/Pricing.php) entity. + +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$productPricing = $articleClient->getProductPricing('my-product-id'); +echo json_encode($productPricing, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +``` + +Example above prints out + +```json +{ + "price": 99.9, + "rrp": 112, + "purchasePrice": 80.5 +} +``` + +## Update product pricing + +Method expects `product` ID and [Pricing](../src/Article/Entity/Common/Pricing.php) entity and does not return anything. + +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$articleClient->updateProductPricing( + 'my-product-id', + new Pricing(99.9, 112.0, 80.5) +); +``` + +--- + +## Get list of all variants for product + +Method expects `product` id and [?Filter](../src/Filter/Filter.php) and returns [BasicVariantList](../src/Article/Entity/BasicVariantList.php) containing [BasicVariant](../src/Article/Entity/BasicVariant.php) entity. + +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$variantList = $articleClient->listProductVariants('my-product-id', null); +echo json_encode($variantList, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +``` + +Example above prints out + +```json +{ + "paging": { + "total": 3, + "pages": 1, + "size": 3, + "page": 1 + }, + "data": [ + { + "id": "my-variant-id", + "productId": 100001234567, + "variantId": 100001992001, + "title": "P2, adventury", + "status": "A", + "inStock": 6, + "price": 34, + "purchasePrice": 0, + "rrp": 34 + }, + { + "id": "my-variant-id-2", + "productId": 100001234567, + "variantId": 100001992002, + "title": "P2, akčné - 1st person", + "status": "A", + "inStock": 6, + "price": 34, + "purchasePrice": 0, + "rrp": 34 + }, + { + "id": "my-variant-id-3", + "productId": 100001234567, + "variantId": 100001992003, + "title": "P2, akčné - ostatné", + "status": "A", + "inStock": 7, + "price": 34, + "purchasePrice": 0, + "rrp": 34 + } + ] +} +``` + +## Create variant + +Method expects `product` id and [VariantRequest](../src/Article/DTO/VariantRequest.php) and returns [Variant](../src/Article/Entity/Variant.php) entity. + +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$variantRequest = new VariantRequest( + 'my-variant-id', + 'Variant title', + 'Short variant description', + 'Long variant description with tags', + 1, + 20, + new MediaIterator( + new Media('https://cdn.my-domain.com/my-variant-id-1.jpg', true), + new Media('https://cdn.my-domain.com/my-variant-id-energy-label.jpg', false, null, true, false), + ), + new ParameterIterator( + Parameter::create('MP_PARAMETER', 'a', 'b', 'c'), + ), +); + +// Add data required for variant creation +$variantRequest->setAvailability(new Availability(StatusEnum::ACTIVE(), 1)); + +// Add optional data +$variantRequest->setDimensions(new Dimensions(2, 20, 5, 20)); +$variantRequest->setBarcode('0000123456789'); + +// Create variant +// - request returns full variant detail, same as calling `getVariant` method +$createdVariant = $articleClient->createVariant('my-product-id', $variantRequest); +echo json_encode($createdVariant, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +``` + +Example above prints out + +```json +{ + "id": "my-variant-id", + "articleId": 100001234567, + "title": "Variant title", + "url": "https:\/\/www.mall.cz\/id\/100001234567", + "shortDesc": "Short variant description", + "longDesc": "Long variant description with tags<\/strong>", + "priority": 1, + "barcode": "0000123456789", + "price": 20, + "purchasePrice": 0, + "rrp": 20, + "media": [ + { + "url": "https:\/\/cdn.my-domain.com\/my-variant-id-1.jpg", + "main": true, + "switch": null, + "energyLabel": false, + "informationList": false + }, + { + "url": "https:\/\/cdn.my-domain.com\/my-variant-id-energy-label.jpg", + "main": false, + "switch": null, + "energyLabel": true, + "informationList": false + } + ], + "promotions": [], + "parameters": [ + { + "id": "MP_PARAMETER", + "values": [ + "a", + "b", + "c" + ] + } + ], + "dimensions": { + "weight": 2, + "width": 20, + "height": 5, + "length": 20 + }, + "availability": { + "status": "A", + "inStock": 1 + }, + "labels": [], + "overrides": [], + "recommended": [], + "deliveryDelay": 3, + "freeDelivery": false, + "packageSize": "smallbox", + "mallboxAllowed": false +} +``` ## Update variant +Method expects `product` id and [VariantRequest](../src/Article/DTO/VariantRequest.php) and does not return anything. + ```php /** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ $variantRequest = new VariantRequest( @@ -20,8 +496,8 @@ $variantRequest = new VariantRequest( 1, 20, new MediaIterator( - new Media('https://cdn.my-domain.com/my-variant-id-1.jpeg', true), - new Media('https://cdn.my-domain.com/my-variant-id-energy-label.jpeg', false, null, true, false), + new Media('https://cdn.my-domain.com/my-variant-id-1.jpg', true), + new Media('https://cdn.my-domain.com/my-variant-id-energy-label.jpg', false, null, true, false), ), new ParameterIterator( Parameter::create('MP_PARAMETER', 'a', 'b', 'c'), @@ -35,18 +511,16 @@ $variantRequest->setBarcode('0000123456789'); // Update variant // - API returns same data that were sent in, which is not the same as data returned by `getVariant` method // - that's why client does not return anything (you already have data you sent in `$variantRequest` variable) -$client->article()->updateVariant('my-product-id', $variantRequest); +$articleClient->updateVariant('my-product-id', $variantRequest); ``` - - ## Get variant detail -Method expects `product` and `variant` id's and returns [Variant](../src/Article/Entity/Variant.php) entity. +Method expects `product` and `variant` IDs and returns [Variant](../src/Article/Entity/Variant.php) entity. ```php /** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ -$variantDetail = $client->article()->getVariant('my-product-id', 'my-variant-id'); +$variantDetail = $articleClient->getVariant('my-product-id', 'my-variant-id'); echo json_encode($variantDetail, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); ``` @@ -54,57 +528,53 @@ Example above prints out ```json { - "id": "TR", + "id": "my-variant-id", "articleId": 100001234567, - "title": "My product - variant", + "title": "Variant title", "url": "https:\/\/www.mall.cz\/id\/100001234567", - "shortDesc": "short desc", - "longDesc": "

long desc<\/p>", + "shortDesc": "Short variant description", + "longDesc": "Long variant description with tags<\/strong>", "priority": 1, - "barcode": null, - "price": 34, + "barcode": "0000123456789", + "price": 20, "purchasePrice": 0, - "rrp": 34, + "rrp": 20, "media": [ { - "url": "http:\/\/cdn.my-domain.com\/products\/100001234567\/media\/detail-001.jpg", + "url": "https:\/\/cdn.my-domain.com\/my-variant-id-1.jpg", "main": true, "switch": null, "energyLabel": false, "informationList": false }, { - "url": "http:\/\/cdn.my-domain.com\/products\/100001234567\/media\/detail-001.jpg", - "main": true, + "url": "https:\/\/cdn.my-domain.com\/my-variant-id-energy-label.jpg", + "main": false, "switch": null, - "energyLabel": false, + "energyLabel": true, "informationList": false } ], "promotions": [], "parameters": [ { - "id": "GENRE_OF_GAME", - "values": [ - "adventury" - ] - }, - { - "id": "TYPE_CONSOLE", + "id": "MP_PARAMETER", "values": [ - "Nintendo 3DS" + "a", + "b", + "c" ] } ], "dimensions": { - "weight": 6, - "width": 6, - "height": 6, - "length": 6 + "weight": 2, + "width": 20, + "height": 5, + "length": 20 }, "availability": { "status": "A", - "inStock": 6 + "inStock": 1 }, "labels": [], "overrides": [], @@ -118,16 +588,35 @@ Example above prints out ## Delete variant -Method expects `product` and `variant` id's and does not return anything. +Method expects `product` and `variant` IDs and does not return anything. + +```php +/** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ +$articleClient->deleteVariant('my-product-id', 'my-variant-id'); +``` + +## Get variant availability + +Method expects `product` and `variant` IDs and returns [Availability](../src/Article/Entity/Common/Availability.php) entity. ```php /** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ -$articleClient->article()->deleteVariant('my-product-id', 'my-variant-id'); +$variantAvailability = $articleClient->getVariantAvailability('my-product-id', 'my-variant-id'); +echo json_encode($variantAvailability, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); +``` + +Example above prints out + +```json +{ + "status": "A", + "inStock": 1 +} ``` ## Get variant pricing -Method expects `product` and `variant` id's and returns [Pricing](../src/Article/Entity/Common/Pricing.php) entity. +Method expects `product` and `variant` IDs and returns [Pricing](../src/Article/Entity/Common/Pricing.php) entity. ```php /** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ @@ -147,7 +636,7 @@ Example above prints out ## Update variant pricing -Method expects `product` and `variant` id's and [Pricing](../src/Article/Entity/Common/Pricing.php) entity and does not return anything. +Method expects `product` and `variant` IDs and [Pricing](../src/Article/Entity/Common/Pricing.php) entity and does not return anything. ```php /** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ @@ -158,6 +647,8 @@ $articleClient->updateVariantPricing( ); ``` +--- + ## Update availability Method expects [BatchAvailabilityIterator](../src/Article/DTO/BatchAvailabilityIterator.php) DTO and does not return anything. @@ -181,7 +672,7 @@ $articleClient->activateAllProducts(); ## Activate selected products -Method expects dynamic amount of `product` id's and does not return anything. +Method expects variable amount of `product` IDs and does not return anything. ```php /** @var MpApiClient\Common\Interfaces\ArticleClientInterface $articleClient */ diff --git a/example/Article.php b/example/Article.php index b2cd051..d7a19b1 100644 --- a/example/Article.php +++ b/example/Article.php @@ -65,7 +65,7 @@ echo PHP_EOL; } } catch (MpApiException $e) { - echo 'Unexpected error occurred, while loading product list: ' . $e->getMessage(); + echo 'Unexpected error occurred while loading product list: ' . $e->getMessage(); } // @@ -88,13 +88,14 @@ $productRequest->setAvailability(new Availability(StatusEnum::ACTIVE(), 1)); $productRequest->setMedia( new MediaIterator( - new Media('https://cdn.my-domain.com/my-product-id-1.jpeg', true), - new Media('https://cdn.my-domain.com/my-product-id-energy-label.jpeg', false, null, true, false), + new Media('https://cdn.my-domain.com/my-product-id-1.jpg', true), + new Media('https://cdn.my-domain.com/my-product-id-energy-label.jpg', false, null, true, false), ), ); $productRequest->setPrice(69); // Add optional data + $productRequest->setDimensions(new Dimensions(2, 20, 5, 20)); $productRequest->setBrandId('BRAND_ID'); $productRequest->setBarcode('0000123456789'); @@ -111,7 +112,7 @@ // Get product as array var_dump($createdProduct->jsonSerialize()); } catch (MpApiException | Exception $e) { - echo 'Unexpected error occurred, during product creation: ' . $e->getMessage(); + echo 'Unexpected error occurred during product creation: ' . $e->getMessage(); } // @@ -130,6 +131,8 @@ 1, ); + // There is an option to create request from existing Product entity -> ProductRequest::createFromProduct($product) + // Add optional data $productRequest->setBrandId('BRAND_ID'); $productRequest->setBarcode('0000123456789'); @@ -139,7 +142,7 @@ // - that's why client does not return anything (you already have data you sent in `$productRequest` variable) $client->article()->updateProduct($productRequest); } catch (MpApiException $e) { - echo 'Unexpected error occurred, during product update: ' . $e->getMessage(); + echo 'Unexpected error occurred during product update: ' . $e->getMessage(); } // @@ -163,7 +166,7 @@ echo 'Status: ' . $productDetail->getAvailability()->getStatus() . PHP_EOL; echo PHP_EOL; } catch (MpApiException | Exception $e) { - echo 'Unexpected error occurred, while loading product detail: ' . $e->getMessage(); + echo 'Unexpected error occurred while loading product detail: ' . $e->getMessage(); } // @@ -173,7 +176,7 @@ try { $client->article()->deleteProduct('my-product-id'); } catch (MpApiException $e) { - echo 'Unexpected error occurred, during product deletion: ' . $e->getMessage(); + echo 'Unexpected error occurred during product deletion: ' . $e->getMessage(); } // @@ -194,7 +197,7 @@ echo 'In stock: ' . $productAvailability->getInStock() . PHP_EOL; echo PHP_EOL; } catch (MpApiException $e) { - echo 'Unexpected error occurred, while loading product availability: ' . $e->getMessage(); + echo 'Unexpected error occurred while loading product availability: ' . $e->getMessage(); } // @@ -216,7 +219,7 @@ echo 'Purchase price: ' . $productPricing->getPurchasePrice() . PHP_EOL; echo PHP_EOL; } catch (MpApiException $e) { - echo 'Unexpected error occurred, while loading product pricing: ' . $e->getMessage(); + echo 'Unexpected error occurred while loading product pricing: ' . $e->getMessage(); } // @@ -229,7 +232,7 @@ new Pricing(99.9, 112.0, 80.5) ); } catch (MpApiException $e) { - echo 'Unexpected error occurred, during product pricing update: ' . $e->getMessage(); + echo 'Unexpected error occurred during product pricing update: ' . $e->getMessage(); } // @@ -259,7 +262,7 @@ echo PHP_EOL; } } catch (MpApiException $e) { - echo 'Unexpected error occurred, while loading variant list: ' . $e->getMessage(); + echo 'Unexpected error occurred while loading variant list: ' . $e->getMessage(); } // @@ -276,8 +279,8 @@ 1, 20, new MediaIterator( - new Media('https://cdn.my-domain.com/my-variant-id-1.jpeg', true), - new Media('https://cdn.my-domain.com/my-variant-id-energy-label.jpeg', false, null, true, false), + new Media('https://cdn.my-domain.com/my-variant-id-1.jpg', true), + new Media('https://cdn.my-domain.com/my-variant-id-energy-label.jpg', false, null, true, false), ), new ParameterIterator( Parameter::create('MP_PARAMETER', 'a', 'b', 'c'), @@ -301,7 +304,7 @@ // Get variant as array var_dump($createdVariant->jsonSerialize()); } catch (MpApiException | Exception $e) { - echo 'Unexpected error occurred, during variant creation: ' . $e->getMessage(); + echo 'Unexpected error occurred during variant creation: ' . $e->getMessage(); } // @@ -318,14 +321,16 @@ 1, 20, new MediaIterator( - new Media('https://cdn.my-domain.com/my-variant-id-1.jpeg', true), - new Media('https://cdn.my-domain.com/my-variant-id-energy-label.jpeg', false, null, true, false), + new Media('https://cdn.my-domain.com/my-variant-id-1.jpg', true), + new Media('https://cdn.my-domain.com/my-variant-id-energy-label.jpg', false, null, true, false), ), new ParameterIterator( Parameter::create('MP_PARAMETER', 'a', 'b', 'c'), ), ); + // There is an option to create request from existing Variant entity -> VariantRequest::createFromVariant($variant) + // Add optional data $variantRequest->setDimensions(new Dimensions(2, 20, 5, 20)); $variantRequest->setBarcode('0000123456789'); @@ -335,7 +340,7 @@ // - that's why client does not return anything (you already have data you sent in `$variantRequest` variable) $client->article()->updateVariant('my-product-id', $variantRequest); } catch (MpApiException $e) { - echo 'Unexpected error occurred, during variant update: ' . $e->getMessage(); + echo 'Unexpected error occurred during variant update: ' . $e->getMessage(); } // @@ -358,7 +363,7 @@ echo 'Status: ' . $variantDetail->getAvailability()->getStatus() . PHP_EOL; echo PHP_EOL; } catch (MpApiException | Exception $e) { - echo 'Unexpected error occurred, while loading variant detail: ' . $e->getMessage(); + echo 'Unexpected error occurred while loading variant detail: ' . $e->getMessage(); } // @@ -368,7 +373,7 @@ try { $client->article()->deleteVariant('my-product-id', 'my-variant-id'); } catch (MpApiException $e) { - echo 'Unexpected error occurred, during variant deletion: ' . $e->getMessage(); + echo 'Unexpected error occurred during variant deletion: ' . $e->getMessage(); } // @@ -389,7 +394,7 @@ echo 'In stock: ' . $variantAvailability->getInStock() . PHP_EOL; echo PHP_EOL; } catch (MpApiException $e) { - echo 'Unexpected error occurred, while loading variant availability: ' . $e->getMessage(); + echo 'Unexpected error occurred while loading variant availability: ' . $e->getMessage(); } // @@ -411,7 +416,7 @@ echo 'Purchase price: ' . $variantPricing->getPurchasePrice() . PHP_EOL; echo PHP_EOL; } catch (MpApiException $e) { - echo 'Unexpected error occurred, while loading variant pricing: ' . $e->getMessage(); + echo 'Unexpected error occurred while loading variant pricing: ' . $e->getMessage(); } // @@ -425,7 +430,7 @@ new Pricing(99.9, 112.0, 80.5) ); } catch (MpApiException $e) { - echo 'Unexpected error occurred, during variant pricing update: ' . $e->getMessage(); + echo 'Unexpected error occurred during variant pricing update: ' . $e->getMessage(); } // @@ -440,7 +445,7 @@ ) ); } catch (MpApiException $e) { - echo 'Unexpected error occurred, during batch availability update: ' . $e->getMessage(); + echo 'Unexpected error occurred during batch availability update: ' . $e->getMessage(); } // @@ -450,7 +455,7 @@ try { $client->article()->activateAllProducts(); } catch (MpApiException $e) { - echo 'Unexpected error occurred, during activation of all products: ' . $e->getMessage(); + echo 'Unexpected error occurred during activation of all products: ' . $e->getMessage(); } // @@ -460,5 +465,5 @@ try { $client->article()->activateSelectedProducts('my-product-id-1', 'my-product-id-2', 'my-product-id-3'); } catch (MpApiException $e) { - echo 'Unexpected error occurred, during activation of selected products: ' . $e->getMessage(); + echo 'Unexpected error occurred during activation of selected products: ' . $e->getMessage(); } diff --git a/src/Article/DTO/ProductRequest.php b/src/Article/DTO/ProductRequest.php index 2af7845..337d73f 100644 --- a/src/Article/DTO/ProductRequest.php +++ b/src/Article/DTO/ProductRequest.php @@ -111,7 +111,7 @@ public function getArrayForApi(): array fn($value): bool => !is_null($value) ); - return array_merge($mandatory, $optional); + return $mandatory + $optional; } public function getCategoryId(): string diff --git a/src/Article/DTO/VariantRequest.php b/src/Article/DTO/VariantRequest.php index 69dbe5b..1357409 100644 --- a/src/Article/DTO/VariantRequest.php +++ b/src/Article/DTO/VariantRequest.php @@ -90,7 +90,7 @@ public function getArrayForApi(): array fn($value): bool => !is_null($value) ); - return array_merge($mandatory, $optional); + return $mandatory + $optional; } public function getPrice(): float diff --git a/src/Article/Entity/Product.php b/src/Article/Entity/Product.php index cf1952b..e0dc538 100644 --- a/src/Article/Entity/Product.php +++ b/src/Article/Entity/Product.php @@ -17,16 +17,16 @@ final class Product extends AbstractArticle { - private ProductStageEnum $stage; - private string $categoryId; - private int $vat; - private VariantIterator $variants; + protected ProductStageEnum $stage; + protected string $categoryId; + protected int $vat; + protected VariantIterator $variants; /** * @var string[] */ - private array $variableParameters; - private ?string $partnerTitle; - private ?string $brandId; + protected array $variableParameters; + protected ?string $partnerTitle; + protected ?string $brandId; /** * @param string $id diff --git a/src/Order/OrderClient.php b/src/Order/OrderClient.php index 7f2ba7e..3dff270 100644 --- a/src/Order/OrderClient.php +++ b/src/Order/OrderClient.php @@ -31,7 +31,7 @@ final class OrderClient extends AbstractMpApiClient implements OrderClientInterf public function list(?Filter $filter): BasicOrderList { $filter ??= new Filter(); - // client supports only list of basic orders (there is no reason to list ID's only from MPAPI) + // client supports only list of basic orders (there is no reason to list IDs only from MPAPI) $filter->addFilterItem(FilterItem::create('filter', 'basic', FilterOperatorEnum::EMPTY())); return BasicOrderList::createWithCallback(