diff --git a/src/ApiPlatform/Resources/CartRule.php b/src/ApiPlatform/Resources/CartRule.php index 06a26bf..d3fc8a1 100644 --- a/src/ApiPlatform/Resources/CartRule.php +++ b/src/ApiPlatform/Resources/CartRule.php @@ -25,6 +25,7 @@ use ApiPlatform\Metadata\ApiResource; use PrestaShop\PrestaShop\Core\Domain\CartRule\Command\EditCartRuleCommand; use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; +use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue; #[ApiResource( operations: [ @@ -52,6 +53,7 @@ class CartRule public int $customerId; + #[LocalizedValue] public array $localizedNames; public bool $highlightInCart; diff --git a/src/ApiPlatform/Resources/CustomerGroup.php b/src/ApiPlatform/Resources/CustomerGroup.php index 1e8b187..6e1aa59 100644 --- a/src/ApiPlatform/Resources/CustomerGroup.php +++ b/src/ApiPlatform/Resources/CustomerGroup.php @@ -35,6 +35,7 @@ use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete; use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; +use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue; #[ApiResource( operations: [ @@ -102,6 +103,7 @@ class CustomerGroup #[ApiProperty(identifier: true)] public int $customerGroupId; + #[LocalizedValue] public array $localizedNames; public float $reductionPercent; diff --git a/src/ApiPlatform/Resources/Product/NewProductImage.php b/src/ApiPlatform/Resources/Product/NewProductImage.php index 2ac13d0..7bfd39f 100644 --- a/src/ApiPlatform/Resources/Product/NewProductImage.php +++ b/src/ApiPlatform/Resources/Product/NewProductImage.php @@ -26,6 +26,7 @@ use PrestaShop\PrestaShop\Core\Domain\Product\Image\Command\AddProductImageCommand; use PrestaShop\PrestaShop\Core\Domain\Product\Image\Query\GetProductImage; use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate; +use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue; use Symfony\Component\HttpFoundation\File\File; #[ApiResource( @@ -49,12 +50,15 @@ )] class NewProductImage { + public int $productId; + public int $imageId; public string $imageUrl; public string $thumbnailUrl; + #[LocalizedValue] public array $legends; public bool $cover; diff --git a/src/ApiPlatform/Resources/Product/Product.php b/src/ApiPlatform/Resources/Product/Product.php index 9e1f221..7907756 100644 --- a/src/ApiPlatform/Resources/Product/Product.php +++ b/src/ApiPlatform/Resources/Product/Product.php @@ -34,6 +34,7 @@ use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete; use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate; +use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue; use Symfony\Component\HttpFoundation\Response; #[ApiResource( @@ -95,8 +96,10 @@ class Product public bool $active; + #[LocalizedValue] public array $names; + #[LocalizedValue] public array $descriptions; public const QUERY_MAPPING = [ diff --git a/src/ApiPlatform/Resources/Product/ProductImage.php b/src/ApiPlatform/Resources/Product/ProductImage.php index 58dc140..b6630d1 100644 --- a/src/ApiPlatform/Resources/Product/ProductImage.php +++ b/src/ApiPlatform/Resources/Product/ProductImage.php @@ -28,6 +28,7 @@ use PrestaShop\PrestaShop\Core\Domain\Product\Image\Query\GetProductImage; use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; +use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue; use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; @@ -73,6 +74,7 @@ class ProductImage public string $thumbnailUrl; + #[LocalizedValue] public array $legends; public bool $cover; diff --git a/src/ApiPlatform/Resources/Product/ProductImageList.php b/src/ApiPlatform/Resources/Product/ProductImageList.php index 1e11891..b2bf68b 100644 --- a/src/ApiPlatform/Resources/Product/ProductImageList.php +++ b/src/ApiPlatform/Resources/Product/ProductImageList.php @@ -25,6 +25,7 @@ use ApiPlatform\Metadata\ApiResource; use PrestaShop\PrestaShop\Core\Domain\Product\Image\Query\GetProductImages; use PrestaShopBundle\ApiPlatform\Metadata\CQRSGetCollection; +use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue; #[ApiResource( operations: [ @@ -45,12 +46,15 @@ )] class ProductImageList { + public int $productId; + public int $imageId; public string $imageUrl; public string $thumbnailUrl; + #[LocalizedValue] public array $legends; public bool $cover; diff --git a/tests/Integration/ApiPlatform/CustomerGroupApiTest.php b/tests/Integration/ApiPlatform/CustomerGroupApiTest.php index e984f49..2147616 100644 --- a/tests/Integration/ApiPlatform/CustomerGroupApiTest.php +++ b/tests/Integration/ApiPlatform/CustomerGroupApiTest.php @@ -73,7 +73,7 @@ public function testAddCustomerGroup(): int 'auth_bearer' => $bearerToken, 'json' => [ 'localizedNames' => [ - 1 => 'test1', + 'en-US' => 'test1', ], 'reductionPercent' => 10.3, 'displayPriceTaxExcluded' => true, @@ -92,7 +92,7 @@ public function testAddCustomerGroup(): int [ 'customerGroupId' => $customerGroupId, 'localizedNames' => [ - 1 => 'test1', + 'en-US' => 'test1', ], 'reductionPercent' => 10.3, 'displayPriceTaxExcluded' => true, @@ -114,7 +114,7 @@ public function testAddCustomerGroupWithoutShopIds(): int 'auth_bearer' => $bearerToken, 'json' => [ 'localizedNames' => [ - 1 => 'test1', + 'en-US' => 'test1', ], 'reductionPercent' => 10.3, 'displayPriceTaxExcluded' => true, @@ -132,7 +132,7 @@ public function testAddCustomerGroupWithoutShopIds(): int [ 'customerGroupId' => $customerGroupId, 'localizedNames' => [ - 1 => 'test1', + 'en-US' => 'test1', ], 'reductionPercent' => 10.3, 'displayPriceTaxExcluded' => true, @@ -162,7 +162,7 @@ public function testUpdateCustomerGroup(int $customerGroupId): int 'auth_bearer' => $bearerToken, 'json' => [ 'localizedNames' => [ - 1 => 'new_test1', + 'en-US' => 'new_test1', ], 'displayPriceTaxExcluded' => false, 'shopIds' => [1], @@ -179,7 +179,7 @@ public function testUpdateCustomerGroup(int $customerGroupId): int [ 'customerGroupId' => $customerGroupId, 'localizedNames' => [ - 1 => 'new_test1', + 'en-US' => 'new_test1', ], 'reductionPercent' => 10.3, 'displayPriceTaxExcluded' => false, @@ -214,7 +214,7 @@ public function testGetCustomerGroup(int $customerGroupId): int [ 'customerGroupId' => $customerGroupId, 'localizedNames' => [ - 1 => 'new_test1', + 'en-US' => 'new_test1', ], 'reductionPercent' => 10.3, 'displayPriceTaxExcluded' => false, diff --git a/tests/Integration/ApiPlatform/ProductEndpointTest.php b/tests/Integration/ApiPlatform/ProductEndpointTest.php index bb51ec7..523936e 100644 --- a/tests/Integration/ApiPlatform/ProductEndpointTest.php +++ b/tests/Integration/ApiPlatform/ProductEndpointTest.php @@ -33,16 +33,13 @@ class ProductEndpointTest extends ApiTestCase { - protected const EN_LANG_ID = 1; - protected static int $frenchLangId; - public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); (new ResourceResetter())->backupTestModules(); ProductResetter::resetProducts(); LanguageResetter::resetLanguages(); - self::$frenchLangId = self::addLanguageByLocale('fr-FR'); + self::addLanguageByLocale('fr-FR'); self::createApiClient(['product_write', 'product_read']); } @@ -110,8 +107,8 @@ public function testAddProduct(): int 'json' => [ 'type' => ProductType::TYPE_STANDARD, 'names' => [ - self::EN_LANG_ID => 'product name', - self::$frenchLangId => 'nom produit', + 'en-US' => 'product name', + 'fr-FR' => 'nom produit', ], ], ]); @@ -128,12 +125,12 @@ public function testAddProduct(): int 'type' => ProductType::TYPE_STANDARD, 'productId' => $productId, 'names' => [ - self::EN_LANG_ID => 'product name', - self::$frenchLangId => 'nom produit', + 'en-US' => 'product name', + 'fr-FR' => 'nom produit', ], 'descriptions' => [ - self::EN_LANG_ID => '', - self::$frenchLangId => '', + 'en-US' => '', + 'fr-FR' => '', ], 'active' => false, ], @@ -163,10 +160,10 @@ public function testPartialUpdateProduct(int $productId): int ], 'json' => [ 'names' => [ - self::$frenchLangId => 'nouveau nom', + 'fr-FR' => 'nouveau nom', ], 'descriptions' => [ - self::EN_LANG_ID => 'new description', + 'en-US' => 'new description', ], 'active' => true, ], @@ -183,12 +180,12 @@ public function testPartialUpdateProduct(int $productId): int 'type' => ProductType::TYPE_STANDARD, 'productId' => $productId, 'names' => [ - self::EN_LANG_ID => 'product name', - self::$frenchLangId => 'nouveau nom', + 'en-US' => 'product name', + 'fr-FR' => 'nouveau nom', ], 'descriptions' => [ - self::EN_LANG_ID => 'new description', - self::$frenchLangId => '', + 'en-US' => 'new description', + 'fr-FR' => '', ], 'active' => true, ], @@ -203,7 +200,7 @@ public function testPartialUpdateProduct(int $productId): int ], 'json' => [ 'names' => [ - self::EN_LANG_ID => 'new product name', + 'en-US' => 'new product name', ], ], ]); @@ -216,12 +213,12 @@ public function testPartialUpdateProduct(int $productId): int 'type' => ProductType::TYPE_STANDARD, 'productId' => $productId, 'names' => [ - self::EN_LANG_ID => 'new product name', - self::$frenchLangId => 'nouveau nom', + 'en-US' => 'new product name', + 'fr-FR' => 'nouveau nom', ], 'descriptions' => [ - self::EN_LANG_ID => 'new description', - self::$frenchLangId => '', + 'en-US' => 'new description', + 'fr-FR' => '', ], 'active' => true, ], @@ -252,12 +249,12 @@ public function testGetProduct(int $productId): int 'type' => ProductType::TYPE_STANDARD, 'productId' => $productId, 'names' => [ - self::EN_LANG_ID => 'new product name', - self::$frenchLangId => 'nouveau nom', + 'en-US' => 'new product name', + 'fr-FR' => 'nouveau nom', ], 'descriptions' => [ - self::EN_LANG_ID => 'new description', - self::$frenchLangId => '', + 'en-US' => 'new description', + 'fr-FR' => '', ], 'active' => true, ], @@ -302,8 +299,8 @@ public function testAddImage(int $productId): int $this->assertMatchesRegularExpression('@/img/p[/0-9]+/' . $imageId . '-small_default\.jpg@', $decodedResponse['thumbnailUrl']); $this->assertArrayHasKey('legends', $decodedResponse); $this->assertEquals([ - self::EN_LANG_ID => '', - self::$frenchLangId => '', + 'en-US' => '', + 'fr-FR' => '', ], $decodedResponse['legends']); $this->assertArrayHasKey('cover', $decodedResponse); $this->assertIsBool($decodedResponse['cover']); @@ -337,8 +334,8 @@ public function testGetImage(int $imageId): string $this->assertMatchesRegularExpression('@/img/p[/0-9]+/' . $imageId . '-small_default\.jpg@', $decodedResponse['thumbnailUrl']); $this->assertArrayHasKey('legends', $decodedResponse); $this->assertEquals([ - self::EN_LANG_ID => '', - self::$frenchLangId => '', + 'en-US' => '', + 'fr-FR' => '', ], $decodedResponse['legends']); $this->assertArrayHasKey('cover', $decodedResponse); $this->assertIsBool($decodedResponse['cover']); @@ -369,8 +366,8 @@ public function testUpdateImage(int $imageId, string $imageMD5): int 'extra' => [ 'parameters' => [ 'legends' => [ - self::EN_LANG_ID => 'legend en', - self::$frenchLangId => 'legend fr', + 'en-US' => 'legend en', + 'fr-FR' => 'legend fr', ], ], 'files' => [ @@ -392,8 +389,8 @@ public function testUpdateImage(int $imageId, string $imageMD5): int $this->assertMatchesRegularExpression('@/img/p[/0-9]+/' . $imageId . '-small_default\.jpg@', $decodedResponse['thumbnailUrl']); $this->assertArrayHasKey('legends', $decodedResponse); $this->assertEquals([ - self::EN_LANG_ID => 'legend en', - self::$frenchLangId => 'legend fr', + 'en-US' => 'legend en', + 'fr-FR' => 'legend fr', ], $decodedResponse['legends']); $this->assertArrayHasKey('cover', $decodedResponse); $this->assertIsBool($decodedResponse['cover']); @@ -443,8 +440,8 @@ public function testListImages(int $productId, int $imageId): void 'imageUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($imageId, false), 'thumbnailUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($imageId, true), 'legends' => [ - self::EN_LANG_ID => 'legend en', - self::$frenchLangId => 'legend fr', + 'en-US' => 'legend en', + 'fr-FR' => 'legend fr', ], 'cover' => true, 'position' => 1, @@ -457,8 +454,8 @@ public function testListImages(int $productId, int $imageId): void 'imageUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($newImageId, false), 'thumbnailUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($newImageId, true), 'legends' => [ - self::EN_LANG_ID => '', - self::$frenchLangId => '', + 'en-US' => '', + 'fr-FR' => '', ], 'cover' => false, 'position' => 2, @@ -496,8 +493,8 @@ public function testListImages(int $productId, int $imageId): void 'imageUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($newImageId, false), 'thumbnailUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($newImageId, true), 'legends' => [ - self::EN_LANG_ID => '', - self::$frenchLangId => '', + 'en-US' => '', + 'fr-FR' => '', ], 'cover' => true, 'position' => 1, @@ -510,8 +507,8 @@ public function testListImages(int $productId, int $imageId): void 'imageUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($imageId, false), 'thumbnailUrl' => 'http://myshop.com/img/p/' . $this->getImagePath($imageId, true), 'legends' => [ - self::EN_LANG_ID => 'legend en', - self::$frenchLangId => 'legend fr', + 'en-US' => 'legend en', + 'fr-FR' => 'legend fr', ], 'cover' => false, 'position' => 2, diff --git a/tests/Integration/ApiPlatform/ProductMultiShopEndpointTest.php b/tests/Integration/ApiPlatform/ProductMultiShopEndpointTest.php index c103bcb..bc95ac7 100644 --- a/tests/Integration/ApiPlatform/ProductMultiShopEndpointTest.php +++ b/tests/Integration/ApiPlatform/ProductMultiShopEndpointTest.php @@ -36,9 +36,6 @@ class ProductMultiShopEndpointTest extends ApiTestCase { - protected const EN_LANG_ID = 1; - protected static int $frenchLangId; - protected const DEFAULT_SHOP_GROUP_ID = 1; protected static int $secondShopGroupId; @@ -58,7 +55,7 @@ public static function setUpBeforeClass(): void ShopResetter::resetShops(); ConfigurationResetter::resetConfiguration(); - self::$frenchLangId = self::addLanguageByLocale('fr-FR'); + self::addLanguageByLocale('fr-FR'); self::updateConfiguration(MultistoreConfig::FEATURE_STATUS, 1); // Disable secure protection for the tests (the configuration reset forced the default config back) @@ -72,12 +69,12 @@ public static function setUpBeforeClass(): void self::$defaultProductData = [ 'type' => ProductType::TYPE_STANDARD, 'names' => [ - self::EN_LANG_ID => 'product name', - self::$frenchLangId => 'nom produit', + 'en-US' => 'product name', + 'fr-FR' => 'nom produit', ], 'descriptions' => [ - self::EN_LANG_ID => '', - self::$frenchLangId => '', + 'en-US' => '', + 'fr-FR' => '', ], 'active' => false, ]; @@ -114,8 +111,8 @@ public function testShopContextIsRequired(): void 'json' => [ 'type' => ProductType::TYPE_STANDARD, 'names' => [ - self::EN_LANG_ID => 'product name', - self::$frenchLangId => 'nom produit', + 'en-US' => 'product name', + 'fr-FR' => 'nom produit', ], ], ]); @@ -132,8 +129,8 @@ public function testCreateProductForFirstShop(): int 'json' => [ 'type' => ProductType::TYPE_STANDARD, 'names' => [ - self::EN_LANG_ID => 'product name', - self::$frenchLangId => 'nom produit', + 'en-US' => 'product name', + 'fr-FR' => 'nom produit', ], ], 'extra' => [