Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ jobs:
matrix:
os: [ubuntu-latest]
php: [8.5, 8.4, 8.3, 8.2]
laravel: [11.*, 10.*]
laravel: [12.*, 11.*, 10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 12.*
testbench: 10.*
- laravel: 11.*
testbench: ^9.9
- laravel: 10.*
Expand All @@ -41,7 +43,7 @@ jobs:
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:^2.64" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
64 changes: 61 additions & 3 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
# From 1.x to 2.x
> [!IMPORTANT]
> It is recommended not to migrate to v2 of this package yet. While it was initially based on v2 of Plytix's API, their API was later reclassified as beta after some changes were reverted. This package now reflects those reversions and is tagged as an alpha release, as further breaking changes may occur.
# From 1.x to 3.x
This package now supports Plytix's v2 API.
This document outlines the changes made to the package to support the new API.

## Rate limiting changes
Configuring rate limiting through a `Esign\Plytix\Enums\RateLimitingPlan` has been removed.
Furthermore this package does not provide any predefined rate limiting out of the box anymore.
If you wish to keep predefined rate limits, you may do so by using the `Esign\Plytix\Facades\RateLimiter` facade.
Please refer to the [rate limiting](/README.md#rate-limiting) section in the README on how to set things up.
To figure out your current rate limits you can refer to the [Plytix API docs](https://apidocs.plytix.com/#api-limits).

Additionally, you should remove the `plan` key from the `rate_limiting` configuration in your `config/plytix.php` file.
```diff
- use Esign\Plytix\Enums\RateLimitingPlan;

return [
'rate_limiting' => [
- /**
- * The rate limits to be used for the Plytix API.
- */
- 'plan' => RateLimitingPlan::FREE,

/**
* The cache store to be used for the Plytix rate limits.
* Use null to utilize the default cache store from the cache.php config file.
* To disable caching, you can use the 'array' store.
*/
'cache_store' => null,
],
];
```

## Request changes
- Requests targetting Plytix's v1 API have been moved from `Esign\Plytix\Requests` into the `Esign\Plytix\Requests\V1` namespace.
- New requests have been added to target Plytix's v2 API. These requests are located in the `Esign\Plytix\Requests\V2` namespace.
- Deprecated Plytix v1 requests have been removed. You may now use the new v2 requests instead.
- `Esign\Plytix\Requests\AssignProductsToRelationshipRequest`
- `Esign\Plytix\Requests\CreateProductRequest`
- `Esign\Plytix\Requests\LinkAssetToProductRequest`
- `Esign\Plytix\Requests\ModifySelectedProductAttributesRequest`
- `Esign\Plytix\Requests\ProductRequest`
- `Esign\Plytix\Requests\ProductSearchRequest`
- `Esign\Plytix\Requests\UpdateProductRequest`
- The `Esign\Plytix\Requests\ProductVariantRequest` has been removed.
If you wish to retrieve a list of variants related to a parent, you can do so by using the request to search for all products related to a parent.
- The `Esign\Plytix\Requests\ModifySelectedProductAttributesRequest` has been removed. Use the `Esign\Plytix\Requests\V2\UpdateProductRequest` request instead.

## Response changes
<!-- TODO: these may change, check official upgrade guide on Plytix and change accordingly -->
- The `Esign\Plytix\Requests\V2\ProductRequest` now returns product information in a different format.
See [Plytix API docs](https://apidocs.plytix.com/#781906e5-f698-4d79-bb16-3994a7056a35).
- The `Esign\Plytix\Requests\V2\AssignProductsToRelationshipRequest` now returns no content instead of the relationship information.
See [Plytix API docs](https://apidocs.plytix.com/#2f76584a-bd65-438e-a353-302129d0ba25).
- The `Esign\Plytix\Requests\V2\CreateProductRequest` now returns less product information than it used to.
Additionally, it now returns an instance of `Esign\Plytix\DataTransferObjects\V2\Product` instead of an array.
See [Plytix API docs](https://apidocs.plytix.com/#85e380af-7f3b-46bb-8203-3283aef081c2).
- The `Esign\Plytix\Requests\V2\UpdateProductRequest` now returns less product information than it used to.
Additionally, it now returns an instance of `Esign\Plytix\DataTransferObjects\V2\Product` instead of an array.
See [Plytix API docs](https://apidocs.plytix.com/#6317fd74-f753-4a2a-9b28-8752cde0f3d7).
- The `Esign\Plytix\Requests\V2\ProductSearchRequest` now returns product information in a different format.
See [Plytix API docs](https://apidocs.plytix.com/#0e0ad194-7132-49bf-aa8f-951ea1ed266c).
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
],
"require": {
"php": "^8.2",
"illuminate/support": "^10.0|^11.0",
"illuminate/support": "^10.0|^11.0|^12.0",
"saloonphp/pagination-plugin": "^2.2",
"saloonphp/rate-limit-plugin": "^2.0",
"saloonphp/saloon": "^3.8",
"spatie/laravel-data": "^4.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.5",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^10.1"
"orchestra/testbench": "^8.0|^9.0|^10.0",
"phpunit/phpunit": "^10.1|^11.0|^12.0"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 4 additions & 3 deletions src/DataTransferObjects/V2/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
class Product extends Data
{
public function __construct(
#[MapInputName(('_id'))]
public readonly string $id,
public readonly ?string $sku,
public readonly ?string $label,
Expand All @@ -27,8 +26,10 @@ public function __construct(
public readonly ?array $attributes,
#[DataCollectionOf(RelationshipInformation::class)]
public readonly ?array $relationships,
public readonly ?array $categoryIds,
public readonly ?array $assetIds,
#[DataCollectionOf(ProductCategory::class)]
public readonly ?array $categories,
#[DataCollectionOf(Asset::class)]
public readonly ?array $assets,
) {
}
}
12 changes: 12 additions & 0 deletions src/DataTransferObjects/V2/ProductCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Esign\Plytix\DataTransferObjects\V2;

use Spatie\LaravelData\Data;

class ProductCategory extends Data
{
public function __construct(
public readonly string $id,
) {}
}
2 changes: 1 addition & 1 deletion src/DataTransferObjects/V2/RelationshipInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
public readonly string $relationshipId,
public readonly string $relationshipLabel,
#[DataCollectionOf(RelatedProduct::class)]
public readonly array $linksTo,
public readonly array $relatedProducts,
) {
}
}
23 changes: 15 additions & 8 deletions tests/Feature/Requests/V2/ProductRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Esign\Plytix\Tests\Feature\Request\V2;

use Esign\Plytix\DataTransferObjects\V2\Asset;
use PHPUnit\Framework\Attributes\Test;
use Esign\Plytix\DataTransferObjects\V2\Product;
use Esign\Plytix\DataTransferObjects\V2\ProductCategory;
use Esign\Plytix\DataTransferObjects\V2\RelatedProduct;
use Esign\Plytix\DataTransferObjects\V2\RelationshipInformation;
use Esign\Plytix\Plytix;
Expand All @@ -26,7 +28,7 @@ public function it_can_send_a_product_request(): void
$response = $plytix->send(new ProductRequest('67348b7e2bbf7d289efd7984'));

$mockClient->assertSent(ProductRequest::class);
$this->assertEquals('67348b7e2bbf7d289efd7984', $response->json('data.0._id'));
$this->assertEquals('67348b7e2bbf7d289efd7984', $response->json('data.0.id'));
$this->assertEquals('red adventure mug S02223', $response->json('data.0.sku'));
}

Expand All @@ -42,22 +44,27 @@ public function it_can_create_a_dto_from_a_response(): void
$response = $plytix->send(new ProductRequest('67348b7e2bbf7d289efd7984'));
$product = $response->dto();

// Product
$this->assertInstanceOf(Product::class, $product);
$this->assertEquals('67348b7e2bbf7d289efd7984', $product->id);
$this->assertEquals('red adventure mug S02223', $product->sku);
$this->assertEquals('Adventure mug', $product->label);
$this->assertEquals(0, $product->numVariations);
$this->assertEquals('2024-11-13 12:12:20', $product->modified->format('Y-m-d H:i:s'));
$this->assertEquals('2024-11-13 11:20:30', $product->created->format('Y-m-d H:i:s'));
$this->assertEquals(['67191873b301fed08f12f7fb'], $product->categoryIds);
$this->assertEquals(
['671b5ffcc0c8f0e5fd21b9b9', '671918ceb301fed08f12f804', '671918c4b301fed08f12f803'],
$product->assetIds
);
// Product Categories
$this->assertIsArray($product->categories);
$this->assertInstanceOf(ProductCategory::class, $product->categories[0]);
$this->assertEquals('67191873b301fed08f12f7fb', $product->categories[0]->id);
// Product Assets
$this->assertIsArray($product->assets);
$this->assertInstanceOf(Asset::class, $product->assets[0]);
$this->assertEquals('671b5ffcc0c8f0e5fd21b9b9', $product->assets[0]->id);
// Product Relationships
$this->assertInstanceOf(RelationshipInformation::class, $product->relationships[0]);
$this->assertEquals('64ad0d69573a2e83cd38b146', $product->relationships[0]->relationshipId);
$this->assertEquals('related_products', $product->relationships[0]->relationshipLabel);
$this->assertInstanceOf(RelatedProduct::class, $product->relationships[0]->linksTo[0]);
$this->assertEquals('5ec383c6421a5e26d9ac71b1', $product->relationships[0]->linksTo[0]->productId);
$this->assertInstanceOf(RelatedProduct::class, $product->relationships[0]->relatedProducts[0]);
$this->assertEquals('5ec383c6421a5e26d9ac71b1', $product->relationships[0]->relatedProducts[0]->productId);
}
}
20 changes: 11 additions & 9 deletions tests/Feature/Requests/V2/ProductSearchRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function it_can_send_a_product_search_request(): void
$response = $plytix->send(new ProductSearchRequest());

$mockClient->assertSent(ProductSearchRequest::class);
$this->assertEquals('6797dafb0f261cea58ec4e7f', $response->json('data.0._id'));
$this->assertEquals('6797dafb0f261cea58ec4e7f', $response->json('data.0.id'));
$this->assertEquals('NSP-10003', $response->json('data.0.sku'));
}

Expand Down Expand Up @@ -58,20 +58,22 @@ public function it_can_create_a_dto_from_a_response_with_all_attributes(): void
$this->assertIsArray($products[0]->attributes);
$this->assertEquals(true, $products[0]->attributes['published']);
// Product categories
$this->assertIsArray($products[0]->categoryIds);
$this->assertEquals('6797dae60f261cea58ec4db5', $products[0]->categoryIds[0]);
$this->assertIsArray($products[0]->categories);
$this->assertInstanceOf(ProductCategory::class, $products[0]->categories[0]);
$this->assertEquals('6797dae60f261cea58ec4db5', $products[0]->categories[0]->id);
// Assets
$this->assertIsArray($products[0]->assetIds);
$this->assertEquals('6797daeb0f261cea58ec4dd4', $products[0]->assetIds[0]);
$this->assertIsArray($products[0]->assets);
$this->assertInstanceOf(Asset::class, $products[0]->assets[0]);
$this->assertEquals('6797daeb0f261cea58ec4dd4', $products[0]->assets[0]->id);
// Relationships
$this->assertIsArray($products[0]->relationships);
$this->assertIsArray($products[1]->relationships);
$this->assertInstanceOf(RelationshipInformation::class, $products[0]->relationships[0]);
$this->assertEquals('6797dae60f261cea58ec4db7', $products[0]->relationships[0]->relationshipId);
$this->assertEquals('related_items', $products[0]->relationships[0]->relationshipLabel);
$this->assertIsArray($products[0]->relationships[0]->linksTo);
$this->assertInstanceOf(RelatedProduct::class, $products[0]->relationships[0]->linksTo[0]);
$this->assertEquals('6797dafb0f261cea58ec4e83', $products[0]->relationships[0]->linksTo[0]->productId);
$this->assertEquals(1, $products[0]->relationships[0]->linksTo[0]->quantity);
$this->assertIsArray($products[0]->relationships[0]->relatedProducts);
$this->assertInstanceOf(RelatedProduct::class, $products[0]->relationships[0]->relatedProducts[0]);
$this->assertEquals('6797dafb0f261cea58ec4e83', $products[0]->relationships[0]->relatedProducts[0]->productId);
$this->assertEquals(1, $products[0]->relationships[0]->relatedProducts[0]->quantity);
}
}
Loading
Loading