mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[ProductVariant][API] Add possibility to PUT variant translations
This commit is contained in:
parent
8feb851ece
commit
9bd6d0650d
8 changed files with 129 additions and 14 deletions
|
|
@ -0,0 +1,24 @@
|
|||
@managing_product_variants
|
||||
Feature: Editing a product variant
|
||||
In order to change product variant details
|
||||
As an Administrator
|
||||
I want to be able to edit a product variant
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "United States"
|
||||
And this channel allows to shop using "English (United States)" and "Polish (Poland)" locales
|
||||
And the store has a "T-Shirt" configurable product
|
||||
And this product has "Go" variant priced at "$100.00" in "United States" channel
|
||||
And this product is named "Go" in the "English (United States)" locale
|
||||
And this product is named "Idź" in the "Polish (Poland)" locale
|
||||
And I am logged in as an administrator
|
||||
|
||||
@api @ui
|
||||
Scenario: Changing product variant name
|
||||
Given I want to modify the "Go" product variant
|
||||
And I name it "Java" in "English (United States)"
|
||||
And I name it "Kawa" in "Polish (Poland)"
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And the variant with code "GO" should be named "Java" in "English (United States)" locale
|
||||
And the variant with code "GO" should be named "Kawa" in "Polish (Poland)" locale
|
||||
|
|
@ -189,6 +189,20 @@ final class ManagingProductVariantsContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that it has been successfully edited
|
||||
*/
|
||||
public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void
|
||||
{
|
||||
Assert::true(
|
||||
$this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()),
|
||||
sprintf(
|
||||
'Product Variant could not be edited: %s',
|
||||
$this->responseChecker->getError($this->client->getLastResponse()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the :productVariantCode variant of the :product product should appear in the store
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ default:
|
|||
|
||||
- sylius.behat.context.api.admin.managing_product_variants
|
||||
- Sylius\Behat\Context\Api\Admin\ChannelPricingLogEntryContext
|
||||
- sylius.behat.context.api.admin.save
|
||||
|
||||
filters:
|
||||
tags: "@managing_product_variants&&@api"
|
||||
javascript: false
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ default:
|
|||
- sylius.behat.context.api.admin.managing_product_variants
|
||||
- sylius.behat.context.api.admin.save
|
||||
- Sylius\Behat\Context\Api\Admin\ChannelPricingLogEntryContext
|
||||
|
||||
filters:
|
||||
tags: "@viewing_price_history&&@api"
|
||||
javascript: false
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
<attribute name="translations">
|
||||
<group>admin:product_variant:create</group>
|
||||
<group>admin:product_variant:read</group>
|
||||
<group>admin:product_variant:update</group>
|
||||
</attribute>
|
||||
<attribute name="optionValues">
|
||||
<group>admin:product_variant:read</group>
|
||||
|
|
|
|||
|
|
@ -292,4 +292,37 @@ final class ProductVariantsTest extends JsonApiTestCase
|
|||
|
||||
$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_does_not_allow_to_update_product_variant_with_invalid_locale_code(): void
|
||||
{
|
||||
$fixtures = $this->loadFixturesFromFiles(['channel.yaml', 'product/product_variant.yaml', 'authentication/api_administrator.yaml']);
|
||||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER);
|
||||
|
||||
/** @var ProductVariantInterface $productVariant */
|
||||
$productVariant = $fixtures['product_variant'];
|
||||
|
||||
$this->client->request(
|
||||
method: 'PUT',
|
||||
uri: sprintf('/api/v2/admin/product-variants/%s', $productVariant->getCode()),
|
||||
server: $header,
|
||||
content: json_encode([
|
||||
'code' => 'CUP',
|
||||
'channelPricings' => ['WEB' => [
|
||||
'channelCode' => 'WEB',
|
||||
'price' => 4000,
|
||||
'originalPrice' => 5000,
|
||||
'minimumPrice' => 2000,
|
||||
]],
|
||||
'translations' => [
|
||||
'NON-EXISTING-LOCALE-CODE' => [
|
||||
'locale' => 'NON-EXISTING-LOCALE-CODE',
|
||||
'name' => 'Yellow mug',
|
||||
],
|
||||
],
|
||||
], JSON_THROW_ON_ERROR),
|
||||
);
|
||||
|
||||
$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
Sylius\Component\Core\Model\Product:
|
||||
product:
|
||||
fallbackLocale: en_US
|
||||
currentLocale: en
|
||||
code: MUG_SW
|
||||
|
||||
Sylius\Component\Product\Model\ProductVariantTranslation:
|
||||
product_variant_translation_en_US:
|
||||
name: 'Mug'
|
||||
locale: en_US
|
||||
translatable: '@product_variant'
|
||||
product_variant_translation_pl_PL:
|
||||
name: 'Kubek'
|
||||
locale: pl_PL
|
||||
translatable: '@product_variant'
|
||||
|
||||
Sylius\Component\Core\Model\ProductVariant:
|
||||
product_variant:
|
||||
code: MUG
|
||||
version: 1
|
||||
product: '@product'
|
||||
fallbackLocale: en_US
|
||||
currentLocale: en
|
||||
position: 1
|
||||
channelPricings:
|
||||
channel_web: '@product_variant_channel_web_pricing'
|
||||
translations:
|
||||
- '@product_variant_translation'
|
||||
|
||||
Sylius\Component\Core\Model\ChannelPricing:
|
||||
product_variant_channel_web_pricing:
|
||||
channelCode: 'WEB'
|
||||
price: 2000
|
||||
|
|
@ -1,30 +1,37 @@
|
|||
{
|
||||
"@context":"\/api\/v2\/contexts\/ProductVariant",
|
||||
"@id":"\/api\/v2\/admin\/product-variants\/MUG",
|
||||
"@type":"ProductVariant",
|
||||
"code":"MUG",
|
||||
"product":"\/api\/v2\/admin\/products\/MUG_SW",
|
||||
"@context": "\/api\/v2\/contexts\/ProductVariant",
|
||||
"@id": "\/api\/v2\/admin\/product-variants\/MUG",
|
||||
"@type": "ProductVariant",
|
||||
"channelPricings": {
|
||||
"WEB": {
|
||||
"@id": "/api/v2/admin/channel-pricings/@integer@",
|
||||
"@id": "\/api\/v2\/admin\/channel-pricings\/@integer@",
|
||||
"@type": "ChannelPricing",
|
||||
"id": @integer@,
|
||||
"channelCode": "WEB",
|
||||
"price": 3000,
|
||||
"originalPrice": 4000,
|
||||
"lowestPriceBeforeDiscount": 2000,
|
||||
"minimumPrice": 0
|
||||
"minimumPrice": 210
|
||||
}
|
||||
},
|
||||
"optionValues":[],
|
||||
"code": "MUG",
|
||||
"product": "\/api\/v2\/admin\/products\/MUG_SW",
|
||||
"optionValues": [],
|
||||
"enabled": true,
|
||||
"translations": {
|
||||
"en_US": {
|
||||
"@id":"\/api\/v2\/admin\/product-variant-translation\/@integer@",
|
||||
"@type":"ProductVariantTranslation",
|
||||
"id":"@integer@",
|
||||
"name":"Mug",
|
||||
"locale":"en_US"
|
||||
"de_DE": {
|
||||
"@id": "\/api\/v2\/admin\/product-variant-translation\/@integer@",
|
||||
"@type": "ProductVariantTranslation",
|
||||
"id": @integer@,
|
||||
"name": "Orange Tasse",
|
||||
"locale": "de_DE"
|
||||
},
|
||||
"pl_PL": {
|
||||
"@id": "\/api\/v2\/admin\/product-variant-translation\/@integer@",
|
||||
"@type": "ProductVariantTranslation",
|
||||
"id": @integer@,
|
||||
"name": "Pomarańczowy kubek",
|
||||
"locale": "pl_PL"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue