[Api] Add subresource operation for orderItemUnit adjustments

This commit is contained in:
Wojdylak 2024-02-20 13:26:45 +01:00
parent e6b3789477
commit 9bea130b91
No known key found for this signature in database
GPG key ID: 7509E560A6821ABE
6 changed files with 108 additions and 0 deletions

View file

@ -83,6 +83,15 @@
</attribute>
</attribute>
</subresourceOperation>
<subresourceOperation name="api_order_item_units_adjustments_get_subresource">
<attribute name="normalization_context">
<attribute name="groups">
<attribute>admin:order_item_unit:index</attribute>
<attribute>sylius:admin:order_item_unit:index</attribute>
</attribute>
</attribute>
</subresourceOperation>
</subresourceOperations>
<property name="id" identifier="true" writable="false" />

View file

@ -42,6 +42,16 @@
</itemOperation>
</itemOperations>
<subresourceOperations>
<subresourceOperation name="adjustments_get_subresource">
<attribute name="method">GET</attribute>
<attribute name="path">/admin/order-item-units/{id}/adjustments</attribute>
</subresourceOperation>
</subresourceOperations>
<property name="id" identifier="true" writable="false" />
<property name="adjustments" readable="true">
<subresource resourceClass="%sylius.model.adjustment.class%" />
</property>
</resource>
</resources>

View file

@ -41,6 +41,8 @@
<group>shop:cart:show</group>
<group>sylius:shop:cart:show</group>
<group>sylius:admin:order_item:index</group>
<group>admin:order_item_unit:index</group>
<group>sylius:admin:order_item_unit:index</group>
</attribute>
<attribute name="label">
@ -68,6 +70,8 @@
<group>shop:cart:show</group>
<group>sylius:shop:cart:show</group>
<group>sylius:admin:order_item:index</group>
<group>admin:order_item_unit:index</group>
<group>sylius:admin:order_item_unit:index</group>
</attribute>
<attribute name="order">
@ -115,6 +119,8 @@
<group>shop:cart:show</group>
<group>sylius:shop:cart:show</group>
<group>sylius:admin:order_item:index</group>
<group>admin:order_item_unit:index</group>
<group>sylius:admin:order_item_unit:index</group>
</attribute>
<attribute name="locked">
@ -127,6 +133,8 @@
<group>shop:adjustment:show</group>
<group>sylius:shop:adjustment:show</group>
<group>sylius:admin:order_item:index</group>
<group>admin:order_item_unit:index</group>
<group>sylius:admin:order_item_unit:index</group>
</attribute>
</class>
</serializer>

View file

@ -45,4 +45,31 @@ final class OrderItemUnitsTest extends JsonApiTestCase
$this->assertResponse($response, 'admin/order_item_units/get_order_item_unit_response', Response::HTTP_OK);
}
/** @test */
public function it_gets_adjustments_for_an_order_item_unit(): void
{
$this->loadFixturesFromFiles([
'authentication/api_administrator.yaml',
'channel.yaml',
'cart.yaml',
'country.yaml',
'shipping_method.yaml',
'payment_method.yaml',
'cart/promotion.yaml',
]);
$order = $this->placeOrder('token');
$orderItemUnit = $order->getItems()->first()->getUnits()->first();
$this->client->request(
method: 'GET',
uri: '/api/v2/admin/order-item-units/' . $orderItemUnit->getId() . '/adjustments',
server: $this->headerBuilder()->withJsonLdAccept()->withAdminUserAuthorization('api@example.com')->build(),
);
$response = $this->client->getResponse();
$this->assertResponse($response, 'admin/order_item_units/get_order_item_unit_adjustments', Response::HTTP_OK);
}
}

View file

@ -0,0 +1,38 @@
Sylius\Component\Core\Model\Promotion:
promotion_50_off:
code: '50_off'
name: '50% Off on your first order'
description: 'Get 50% off of your first purchase'
channels: ['@channel_web']
priority: 1
exclusive: false
appliesToDiscounted: false
usageLimit: 1
used: 0
couponBased: false
translations:
- '@promotion_50_off_en'
actions:
- '@action_percentage_discount_50'
rules:
- '@rule_cart_quantity'
Sylius\Component\Promotion\Model\PromotionTranslation:
promotion_50_off_en:
locale: 'en_US'
label: '-50% on first order!'
translatable: '@promotion_50_off'
Sylius\Component\Promotion\Model\PromotionAction:
action_percentage_discount_50:
type: order_percentage_discount
configuration:
percentage: 0.5
promotion: '@promotion_50_off'
Sylius\Component\Promotion\Model\PromotionRule:
rule_cart_quantity:
type: cart_quantity
configuration:
count: 1
promotion: '@promotion_50_off'

View file

@ -0,0 +1,16 @@
{
"@context": "\/api\/v2\/contexts\/Adjustment",
"@id": "\/api\/v2\/admin\/order-item-units\/@integer@\/adjustments",
"@type": "hydra:Collection",
"hydra:member": [
{
"@id": "\/api\/v2\/admin\/adjustments\/@integer@",
"@type": "Adjustment",
"type": "order_promotion",
"amount": -1000,
"neutral": false,
"locked": false
}
],
"hydra:totalItems": 1
}