1
+ <?php
2
+
3
+ namespace CustomerFamily \Api \Controller ;
4
+
5
+ use CustomerFamily \Api \Resource \CustomerFamilyProductPrice ;
6
+ use CustomerFamily \Model \CustomerFamilyProductPriceQuery ;
7
+ use Symfony \Component \HttpFoundation \Request ;
8
+ use Symfony \Component \HttpKernel \Attribute \AsController ;
9
+ use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
10
+ use Thelia \Api \Bridge \Propel \Service \ApiResourcePropelTransformerService ;
11
+
12
+ #[AsController]
13
+ class CustomerFamilyProductPriceUpdateByRef
14
+ {
15
+ public function __construct (
16
+ private ApiResourcePropelTransformerService $ apiResourcePropelTransformerService
17
+ )
18
+ {
19
+ }
20
+
21
+ public function __invoke (string $ productSaleElementsRef , string $ customerFamilyCode , Request $ request )
22
+ {
23
+ $ customerFamilyProductPrice = CustomerFamilyProductPriceQuery::create ()
24
+ ->useProductSaleElementsQuery ()
25
+ ->filterByRef ($ productSaleElementsRef )
26
+ ->endUse ()
27
+ ->useCustomerFamilyQuery ()
28
+ ->filterByCode ($ customerFamilyCode )
29
+ ->endUse ()
30
+ ->findOne ()
31
+ ;
32
+
33
+ if (!$ customerFamilyProductPrice ){
34
+ throw new NotFoundHttpException ('NotFound ' );
35
+ }
36
+ /** @var CustomerFamilyProductPrice $customerFamilyProductPriceResource */
37
+ $ customerFamilyProductPriceResource = $ this ->apiResourcePropelTransformerService ->modelToResource (CustomerFamilyProductPrice::class,$ customerFamilyProductPrice ,[]);
38
+
39
+ /** @var CustomerFamilyProductPrice $data */
40
+ $ data = $ request ->get ('data ' );
41
+
42
+ return $ customerFamilyProductPriceResource
43
+ ->setPromo (isset ($ data ->promo ) ? $ data ->getPromo () : $ customerFamilyProductPriceResource ->getPromo () )
44
+ ->setPrice ( isset ($ data ->price ) ? $ data ->getPrice () : $ customerFamilyProductPriceResource ->getPrice ())
45
+ ->setPromoPrice ( isset ($ data ->promoPrice ) ? $ data ->getPromoPrice () : $ customerFamilyProductPriceResource ->getPromoPrice () );
46
+ }
47
+ }
0 commit comments