Skip to content

Commit 881d27f

Browse files
mdevaudmdevaud
and
mdevaud
authored
fix: add new route to CustomerFamilyProductPrice.php (#25)
create CustomerFamilyProductPrice by ref PSE Co-authored-by: mdevaud <mdevaud@openstudio.fr>
1 parent 38ae801 commit 881d27f

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace CustomerFamily\Api\Controller;
4+
5+
use CustomerFamily\Api\Resource\CustomerFamilyProductPrice;
6+
use Symfony\Component\HttpFoundation\Request;
7+
use Symfony\Component\HttpKernel\Attribute\AsController;
8+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9+
use Thelia\Model\ProductSaleElementsQuery;
10+
11+
#[AsController]
12+
class CustomerFamilyProductPriceCreateByRef
13+
{
14+
public function __construct(
15+
)
16+
{
17+
}
18+
19+
public function __invoke(Request $request)
20+
{
21+
$jsonData = json_decode($request->getContent(), true);
22+
23+
$productSaleElements = ProductSaleElementsQuery::create()
24+
->findOneByRef($jsonData['productSaleElementsRef']);
25+
26+
if(!$productSaleElements){
27+
throw new NotFoundHttpException('NotFound');
28+
}
29+
/** @var CustomerFamilyProductPrice $customerFamilyProductPriceResource */
30+
$customerFamilyProductPriceResource = $request->get('data');
31+
32+
$customerFamilyProductPriceResource->setCustomerFamilyCode($jsonData['customerFamilyCode'])
33+
->setProductSaleElementsId($productSaleElements->getId())
34+
->setPrice($jsonData['price'])
35+
->setPromoPrice($jsonData['promoPrice'])
36+
->setPromo($jsonData['promo']);
37+
38+
return $customerFamilyProductPriceResource;
39+
40+
}
41+
}

Api/Resource/CustomerFamilyProductPrice.php

+42
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use ApiPlatform\Metadata\Get;
88
use ApiPlatform\Metadata\Post;
99
use ApiPlatform\Metadata\Put;
10+
use ApiPlatform\OpenApi\Model\Operation;
11+
use ApiPlatform\OpenApi\Model\RequestBody;
12+
use CustomerFamily\Api\Controller\CustomerFamilyProductPriceCreateByRef;
1013
use CustomerFamily\Api\Controller\CustomerFamilyProductPriceUpdateByRef;
1114
use CustomerFamily\Api\State\CustomerFamilyPricePersistProcessor;
1215
use CustomerFamily\Model\Map\CustomerFamilyProductPriceTableMap;
@@ -22,6 +25,45 @@
2225
uriTemplate: '/admin/customer_family_product_prices',
2326
denormalizationContext: ['groups' => [self::GROUP_ADMIN_CREATE, self::GROUP_ADMIN_WRITE]]
2427
),
28+
new Post(
29+
uriTemplate: '/admin/customer_family_product_prices_by_ref',
30+
controller: CustomerFamilyProductPriceCreateByRef::class,
31+
openapi: new Operation(
32+
requestBody: new RequestBody(
33+
content: new \ArrayObject([
34+
'application/json' => [
35+
'schema' => [
36+
'type' => 'object',
37+
'properties' => [
38+
'customerFamilyCode' => [
39+
'type' => 'string',
40+
'example' =>'string'
41+
],
42+
'productSaleElementsRef' => [
43+
'type' => 'string',
44+
'example' => 'string'
45+
],
46+
'price' => [
47+
'type' => 'number',
48+
'format' => 'float',
49+
'example' => 0.0
50+
],
51+
'promoPrice' => [
52+
'type' => 'number',
53+
'format' => 'float',
54+
'example' => 0.0
55+
],
56+
'promo' => [
57+
'type' => 'boolean',
58+
'example' => true
59+
]
60+
]
61+
]
62+
]
63+
])
64+
)
65+
),
66+
),
2567
new Get(
2668
uriTemplate: '/admin/customer_family_product_prices/{productSaleElementsId}/family/{customerFamilyCode}',
2769
),

Config/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<descriptive locale="fr_FR">
88
<title>Famille de clients et prix d'achat</title>
99
</descriptive>
10-
<version>3.1.4</version>
10+
<version>3.1.5</version>
1111
<author>
1212
<name>Guillaume Barral / Etienne Perriere</name>
1313
<email>gbarral@openstudio.fr / eperriere@openstudio.fr</email>

0 commit comments

Comments
 (0)