Skip to content

Commit 78b3891

Browse files
authored
feat: add provider to get price from pse and family (#29)
1 parent 42b6653 commit 78b3891

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

Api/Resource/CustomerFamilyProductPrice.php

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CustomerFamily\Api\Resource;
44

5+
use ApiPlatform\Metadata\ApiProperty;
56
use ApiPlatform\Metadata\ApiResource;
67
use ApiPlatform\Metadata\Delete;
78
use ApiPlatform\Metadata\Get;
@@ -12,10 +13,12 @@
1213
use CustomerFamily\Api\Controller\CustomerFamilyProductPriceCreateByRef;
1314
use CustomerFamily\Api\Controller\CustomerFamilyProductPriceUpdateByRef;
1415
use CustomerFamily\Api\State\CustomerFamilyPricePersistProcessor;
16+
use CustomerFamily\Api\State\CustomerFamilyPriceProvider;
1517
use CustomerFamily\Model\Map\CustomerFamilyProductPriceTableMap;
1618
use Propel\Runtime\Map\TableMap;
1719
use Symfony\Component\Serializer\Attribute\Groups;
1820
use Symfony\Component\Validator\Constraints\NotBlank;
21+
use Thelia\Api\Bridge\Propel\Attribute\CompositeIdentifiers;
1922
use Thelia\Api\Resource\PropelResourceInterface;
2023
use Thelia\Api\Resource\PropelResourceTrait;
2124

@@ -66,6 +69,8 @@
6669
),
6770
new Get(
6871
uriTemplate: '/admin/customer_family_product_prices/{productSaleElementsId}/family/{customerFamilyCode}',
72+
uriVariables: ['productSaleElementsId', 'customerFamilyCode'],
73+
provider: CustomerFamilyPriceProvider::class,
6974
),
7075
new Put(
7176
uriTemplate: '/admin/customer_family_product_prices/reference/{productSaleElementsRef}/family/{customerFamilyCode}',
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Thelia package.
5+
* http://www.thelia.net
6+
*
7+
* (c) OpenStudio <info@thelia.net>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
namespace CustomerFamily\Api\State;
14+
15+
use ApiPlatform\Metadata\Delete;
16+
use ApiPlatform\Metadata\Operation;
17+
use ApiPlatform\Metadata\Post;
18+
use ApiPlatform\Metadata\Put;
19+
use ApiPlatform\State\ProcessorInterface;
20+
use ApiPlatform\State\ProviderInterface;
21+
use CustomerFamily\Api\Resource\CustomerFamilyProductPrice;
22+
use CustomerFamily\Model\CustomerFamilyProductPriceQuery;
23+
use CustomerFamily\Model\CustomerFamilyQuery;
24+
use Thelia\Api\Bridge\Propel\Service\ApiResourcePropelTransformerService;
25+
use Thelia\Model\ProductSaleElementsQuery;
26+
use TntSearch\Index\Customer;
27+
28+
class CustomerFamilyPriceProvider implements ProviderInterface
29+
{
30+
31+
public function __construct(
32+
private readonly ApiResourcePropelTransformerService $apiResourcePropelTransformerService
33+
)
34+
{
35+
}
36+
37+
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
38+
{
39+
if(!isset($uriVariables['customerFamilyCode']) || !isset($uriVariables['productSaleElementsId'])) {
40+
return null;
41+
}
42+
$customerFamily = CustomerFamilyQuery::create()->findOneByCode($uriVariables['customerFamilyCode']);
43+
if (null === $customerFamily) {
44+
return null;
45+
}
46+
$customerFamilyPrice = CustomerFamilyProductPriceQuery::create()
47+
->filterByCustomerFamilyId($customerFamily->getId())
48+
->filterByProductSaleElementsId($uriVariables['productSaleElementsId'])
49+
->findOne();
50+
if (null === $customerFamilyPrice) {
51+
return null;
52+
}
53+
return $this->apiResourcePropelTransformerService->modelToResource(
54+
CustomerFamilyProductPrice::class,
55+
$customerFamilyPrice,
56+
$context
57+
);
58+
}
59+
}

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.8</version>
10+
<version>3.1.9</version>
1111
<author>
1212
<name>Guillaume Barral / Etienne Perriere / Vincent Lopes</name>
1313
<email>gbarral@openstudio.fr / eperriere@openstudio.fr / vlopes@openstudio.fr</email>

0 commit comments

Comments
 (0)