Skip to content

Commit

Permalink
fix: use ArbitraryPrice as input
Browse files Browse the repository at this point in the history
  • Loading branch information
Atala committed Feb 7, 2025
1 parent 0a73058 commit 26a78f8
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 93 deletions.
4 changes: 2 additions & 2 deletions assets/react/controllers/Delivery/DeliveryForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ export default function ({ storeId, deliveryId, order }) {
if (values.variantIncVATPrice && values.variantName) {
data = {
...data,
deliveryPriceInput: {
priceIncVATcents: values.variantIncVATPrice,
arbitraryPrice: {
variantPrice: values.variantIncVATPrice,
variantName: values.variantName
}
}
Expand Down
208 changes: 200 additions & 8 deletions features/deliveries.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,7 @@ Feature: Deliveries
}
"""

Scenario: Create delivery with given price and variant as an admin
Scenario: Create delivery with given price and variant as an admin then edit it with a new price
Given the fixtures files are loaded:
| sylius_channels.yml |
| sylius_products.yml |
Expand All @@ -2473,8 +2473,8 @@ Feature: Deliveries
"address": "48, Rue de Rivoli",
"doneBefore": "tomorrow 13:30"
},
"deliveryPriceInput": {
"priceIncVATcents": 1200,
"arbitraryPrice": {
"variantPrice": 1200,
"variantName": "my custom variant"
}
}
Expand All @@ -2483,16 +2483,208 @@ Feature: Deliveries
When I add "Content-Type" header equal to "application/ld+json"
And I add "Accept" header equal to "application/ld+json"
And the user "bob" sends a "GET" request to "/api/orders/1"
Then the response status code should be 200
Then the response status code should be 200
And the response should be in JSON
And the JSON should match:
"""
{
"deliveryPrice": {
"variantName": "my custom variant",
"value": 1200,
"@*@": "@*@"
"@context": "/api/contexts/Order",
"@id": "/api/orders/1",
"@type": "http://schema.org/Order",
"customer": null,
"shippingAddress": {
"@id": "/api/addresses/4",
"@type": "http://schema.org/Place",
"description": null,
"geo": {
"@type": "GeoCoordinates",
"latitude": 50.636137,
"longitude": 3.092335
},
"streetAddress": "48 Rue de Rivoli, 59800 Lille",
"telephone": null,
"name": null
},
"events": [
{
"@type": "OrderEvent",
"@id": "@string@",
"type": "order:created",
"data": [],
"createdAt": "@[email protected]()"
},
{
"@type": "OrderEvent",
"@id": "@string@",
"type": "order:state_changed",
"data": {
"newState": "new",
"triggeredByEvent": {
"name": "order:created",
"data": []
}
},
"createdAt": "@[email protected]()"
}
],
"id": 1,
"items": [
{
"@id": "/api/orders/1/items/1",
"@type": "OrderItem",
"id": 1,
"quantity": 1,
"unitPrice": 1200,
"total": 1200,
"adjustments": {
"tax": [
{
"id": "@string@",
"label": "TVA 0%",
"amount": 0
}
]
},
"name": "On demand delivery",
"variantName": "my custom variant",
"vendor": null,
"player": {
"@id": "/api/customers/1",
"@type": "Customer",
"email": "[email protected]",
"phoneNumber": null,
"tags": [],
"telephone": null,
"username": "bob",
"fullName": ""
}
}
],
"itemsTotal": 1200,
"total": 1200,
"state": "new",
"paymentMethod": "CARD",
"assignedTo": null,
"adjustments": {
"delivery": [],
"delivery_promotion": [],
"order_promotion": [],
"reusable_packaging": [],
"tax": [],
"tip": [],
"incident": []
},
"paymentGateway": "stripe",
"@*@": "@*@"
}
"""
When I add "Content-Type" header equal to "application/ld+json"
And I add "Accept" header equal to "application/ld+json"
And the user "bob" sends a "PUT" request to "/api/deliveries/1" with body:
"""
{
"arbitraryPrice": {
"variantPrice": 2000,
"variantName": "my new product name"
}
}
"""
Then the response status code should be 200
When I add "Content-Type" header equal to "application/ld+json"
And I add "Accept" header equal to "application/ld+json"
And the user "bob" sends a "GET" request to "/api/orders/1"
Then the response status code should be 200
And the response should be in JSON
And the JSON should match:
"""
{
"@context": "/api/contexts/Order",
"@id": "/api/orders/1",
"@type": "http://schema.org/Order",
"customer": null,
"shippingAddress": {
"@id": "/api/addresses/4",
"@type": "http://schema.org/Place",
"description": null,
"geo": {
"@type": "GeoCoordinates",
"latitude": 50.636137,
"longitude": 3.092335
},
"streetAddress": "48 Rue de Rivoli, 59800 Lille",
"telephone": null,
"name": null
},
"events": [
{
"@type": "OrderEvent",
"@id": "@string@",
"type": "order:created",
"data": [],
"createdAt": "@[email protected]()"
},
{
"@type": "OrderEvent",
"@id": "@string@",
"type": "order:state_changed",
"data": {
"newState": "new",
"triggeredByEvent": {
"name": "order:created",
"data": []
}
},
"createdAt": "@[email protected]()"
}
],
"id": 1,
"items": [
{
"@id": "/api/orders/1/items/2",
"@type": "OrderItem",
"id": 2,
"quantity": 1,
"unitPrice": 2000,
"total": 2000,
"adjustments": {
"tax": [
{
"id": "@string@",
"label": "TVA 0%",
"amount": 0
}
]
},
"name": "On demand delivery",
"variantName": "my new product name",
"vendor": null,
"player": {
"@id": "/api/customers/1",
"@type": "Customer",
"email": "[email protected]",
"phoneNumber": null,
"tags": [],
"telephone": null,
"username": "bob",
"fullName": ""
}
}
],
"itemsTotal": 2000,
"total": 2000,
"state": "new",
"paymentMethod": "CARD",
"assignedTo": null,
"adjustments": {
"delivery": [],
"delivery_promotion": [],
"order_promotion": [],
"reusable_packaging": [],
"tax": [],
"tip": [],
"incident": []
},
"paymentGateway": "stripe",
"@*@": "@*@"
}
"""
6 changes: 3 additions & 3 deletions src/Action/Delivery/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function __invoke(Delivery $data)
throw new ValidationException($errors);
}

$useArbitraryPrice = $this->authorizationCheckerInterface->isGranted('ROLE_ADMIN') && !is_null($data->getDeliveryPriceInput());
$useArbitraryPrice = $this->authorizationCheckerInterface->isGranted('ROLE_ADMIN') && $data->hasArbitraryPrice();

if ($useArbitraryPrice) {
$arbitraryPrice = new ArbitraryPrice(
$data->getDeliveryPriceInput()->getVariantName(),
$data->getDeliveryPriceInput()->getPriceIncVATcents()
$data->getArbitraryPrice()->getVariantName(),
$data->getArbitraryPrice()->getValue()
);
$this->pricingManager->createOrder(
$data,
Expand Down
6 changes: 3 additions & 3 deletions src/Action/Delivery/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function __invoke(Delivery $data): mixed
}

$order = $data->getOrder();
$useArbitraryPrice = $this->authorizationCheckerInterface->isGranted('ROLE_ADMIN') && !is_null($data->getDeliveryPriceInput());
$useArbitraryPrice = $this->authorizationCheckerInterface->isGranted('ROLE_ADMIN') && $data->hasArbitraryPrice();

if ($useArbitraryPrice) {
$arbitraryPrice = new ArbitraryPrice(
$data->getDeliveryPriceInput()->getVariantName(),
$data->getDeliveryPriceInput()->getPriceIncVATcents()
$data->getArbitraryPrice()->getVariantName(),
$data->getArbitraryPrice()->getValue()
);

if (null === $order) {
Expand Down
56 changes: 0 additions & 56 deletions src/Api/Dto/DeliveryPriceInput.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Api/Resource/TaxRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ final class TaxRate

public function __construct(BaseTaxRate $taxRate, string $name, array $alternatives = [])
{
var_dump($taxRate->getCode());
$this->id = $taxRate->getCode();
$this->code = $taxRate->getCode();
$this->amount = $taxRate->getAmount();
Expand Down
Loading

0 comments on commit 26a78f8

Please sign in to comment.