mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[API] Improve productAttribute routing
This commit is contained in:
parent
26ddbe0905
commit
305ef73062
10 changed files with 198 additions and 54 deletions
|
|
@ -84,6 +84,9 @@ You can bring back previous configuration by overriding current routing with you
|
|||
* Routing definition for ProductVariants has been changed and productVariants are now resolved by code instead of id.
|
||||
You can bring back previous configuration by overriding current routing with your definition.
|
||||
|
||||
* Routing definition for ProductAttributes has been changed and productAttributes are now resolved by code instead of id.
|
||||
You can bring back previous configuration by overriding current routing with your definition.
|
||||
|
||||
### Attribute / AttributeBundle
|
||||
|
||||
* `AttributeValue::$localeCode` property was added to make it translatable. Now, every attribute value has a locale code to be displayed properly in different locales. All attribute values are migrated to the new concept with migration `Version20170109143010`. Look at [this PR](https://github.com/Sylius/Sylius/pull/7219) if you have any problems with upgrade.
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ sylius_api_locale:
|
|||
sylius_api_product:
|
||||
resource: "@SyliusApiBundle/Resources/config/routing/product.yml"
|
||||
|
||||
sylius_api_product_attribute:
|
||||
resource: "@SyliusApiBundle/Resources/config/routing/product_attribute.yml"
|
||||
|
||||
sylius_api_product_variant:
|
||||
resource: "@SyliusApiBundle/Resources/config/routing/product_variant.yml"
|
||||
prefix: /products/{productCode}/variants
|
||||
|
|
@ -24,13 +27,6 @@ sylius_api_product_option:
|
|||
resource: "@SyliusApiBundle/Resources/config/routing/product_option.yml"
|
||||
prefix: /product-options
|
||||
|
||||
sylius_api_product_taxon:
|
||||
resource: "@SyliusApiBundle/Resources/config/routing/productTaxon.yml"
|
||||
|
||||
sylius_api_product_attribute:
|
||||
resource: "@SyliusApiBundle/Resources/config/routing/product_attribute.yml"
|
||||
prefix: /product-attributes
|
||||
|
||||
sylius_api_taxon:
|
||||
resource: "@SyliusApiBundle/Resources/config/routing/taxon.yml"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,49 +1,13 @@
|
|||
# This file is part of the Sylius package.
|
||||
# (c) Paweł Jędrzejewski
|
||||
|
||||
sylius_api_product_attribute_index:
|
||||
path: /
|
||||
methods: [GET]
|
||||
defaults:
|
||||
_controller: sylius.controller.product_attribute:indexAction
|
||||
_sylius:
|
||||
serialization_version: $version
|
||||
paginate: $limit
|
||||
sortable: true
|
||||
sorting:
|
||||
id: desc
|
||||
|
||||
sylius_api_product_attribute_create:
|
||||
path: /
|
||||
methods: [POST]
|
||||
defaults:
|
||||
_controller: sylius.controller.product_attribute:createAction
|
||||
_sylius:
|
||||
serialization_version: $version
|
||||
factory:
|
||||
method: createTyped
|
||||
arguments:
|
||||
type: $type
|
||||
|
||||
sylius_api_product_attribute_update:
|
||||
path: /{id}
|
||||
methods: [PUT, PATCH]
|
||||
defaults:
|
||||
_controller: sylius.controller.product_attribute:updateAction
|
||||
_sylius:
|
||||
serialization_version: $version
|
||||
|
||||
sylius_api_product_attribute_delete:
|
||||
path: /{id}
|
||||
methods: [DELETE]
|
||||
defaults:
|
||||
_controller: sylius.controller.product_attribute:deleteAction
|
||||
_sylius:
|
||||
serialization_version: $version
|
||||
csrf_protection: false
|
||||
|
||||
sylius_api_product_attribute_show:
|
||||
path: /{id}
|
||||
methods: [GET]
|
||||
defaults:
|
||||
_controller: sylius.controller.product_attribute:showAction
|
||||
sylius_api_product_attribute:
|
||||
resource: |
|
||||
identifier: code
|
||||
alias: sylius.product_attribute
|
||||
section: api
|
||||
only: ['index', 'show']
|
||||
serialization_version: $version
|
||||
criteria:
|
||||
code: $code
|
||||
type: sylius.resource_api
|
||||
|
|
|
|||
|
|
@ -6,19 +6,33 @@ Sylius\Component\Product\Model\ProductAttribute:
|
|||
expose: true
|
||||
type: integer
|
||||
xml_attribute: true
|
||||
gorups: [Default, Detailed]
|
||||
position:
|
||||
expose: true
|
||||
type: integer
|
||||
gorups: [Default, Detailed]
|
||||
name:
|
||||
expose: true
|
||||
type: string
|
||||
gorups: [Default, Detailed]
|
||||
presentation:
|
||||
expose: true
|
||||
type: string
|
||||
gorups: [Detailed]
|
||||
createdAt:
|
||||
expose: true
|
||||
type: DateTime
|
||||
gorups: [Detailed]
|
||||
updatedAt:
|
||||
expose: true
|
||||
type: DateTime
|
||||
|
||||
gorups: [Detailed]
|
||||
relations:
|
||||
- rel: self
|
||||
href:
|
||||
route: sylius_api_product_attribute_show
|
||||
parameters:
|
||||
code: expr(object.getCode())
|
||||
version: 1
|
||||
exclusion:
|
||||
groups: [Detailed]
|
||||
|
|
|
|||
95
tests/Controller/ProductAttributeApiTest.php
Normal file
95
tests/Controller/ProductAttributeApiTest.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Tests\Controller;
|
||||
use Lakion\ApiTestCase\JsonApiTestCase;
|
||||
use Sylius\Component\Product\Model\ProductAttributeInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* @author Anna Walasek <anna.walasek@lakion.com>
|
||||
*/
|
||||
class ProductAttributeApiTest extends JsonApiTestCase
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $authorizedHeaderWithAccept = [
|
||||
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
|
||||
'ACCEPT' => 'application/json',
|
||||
];
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_does_not_allow_to_show_product_attributes_list_when_access_is_denied()
|
||||
{
|
||||
$this->loadFixturesFromFile('resources/product_attributes.yml');
|
||||
|
||||
$this->client->request('GET', '/api/v1/product-attributes/');
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_allows_indexing_product_attributes()
|
||||
{
|
||||
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
||||
$this->loadFixturesFromFile('resources/product_attributes.yml');
|
||||
|
||||
|
||||
$this->client->request('GET', '/api/v1/product-attributes/', [], [], static::$authorizedHeaderWithAccept);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertResponse($response, 'product_attribute/index_response', Response::HTTP_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_does_not_allow_to_show_product_attribute_when_it_does_not_exist()
|
||||
{
|
||||
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
||||
|
||||
$this->client->request('GET', '/api/v1/product-attributes/-1', [], [], static::$authorizedHeaderWithAccept);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_allows_showing_product_attribute()
|
||||
{
|
||||
$this->loadFixturesFromFile('authentication/api_administrator.yml');
|
||||
$productAttributes = $this->loadFixturesFromFile('resources/product_attributes.yml');
|
||||
$productAttribute = $productAttributes['productAttribute1'];
|
||||
|
||||
$this->client->request('GET', $this->getProductAttributeUrl($productAttribute), [], [], static::$authorizedHeaderWithAccept);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertResponse($response, 'product_attribute/show_response', Response::HTTP_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProductAttributeInterface $productAttribute
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getProductAttributeUrl(ProductAttributeInterface $productAttribute)
|
||||
{
|
||||
return '/api/v1/product-attributes/' . $productAttribute->getCode();
|
||||
}
|
||||
}
|
||||
20
tests/Controller/ProductOptionApiTest.php
Normal file
20
tests/Controller/ProductOptionApiTest.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Tests\Controller;
|
||||
|
||||
/**
|
||||
* @author Anna Walasek <anna.walasek@lakion.com>
|
||||
*/
|
||||
class ProductOptionApiTest
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"page": 1,
|
||||
"limit": 10,
|
||||
"pages": 1,
|
||||
"total": 2,
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/product-attributes\/?page=1&limit=10"
|
||||
},
|
||||
"first": {
|
||||
"href": "\/api\/v1\/product-attributes\/?page=1&limit=10"
|
||||
},
|
||||
"last": {
|
||||
"href": "\/api\/v1\/product-attributes\/?page=1&limit=10"
|
||||
}
|
||||
},
|
||||
"_embedded": {
|
||||
"items": [
|
||||
{
|
||||
"id": @integer@,
|
||||
"created_at": "@string@.isDateTime()",
|
||||
"updated_at": "@string@.isDateTime()",
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/product-attributes\/mug_material"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": @integer@,
|
||||
"created_at": "@string@.isDateTime()",
|
||||
"updated_at": "@string@.isDateTime()",
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/product-attributes\/mug_collection"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"id": @integer@,
|
||||
"created_at": "@string@.isDateTime()",
|
||||
"updated_at": "@string@.isDateTime()",
|
||||
"_links": {
|
||||
"self": {
|
||||
"href": "\/api\/v1\/product-attributes\/mug_material"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue