1
+ <?php
2
+
3
+ namespace CustomerFamily \Api \Resource ;
4
+
5
+ use CustomerFamily \Model \CustomerCustomerFamilyQuery ;
6
+ use CustomerFamily \Model \CustomerFamilyQuery ;
7
+ use CustomerFamily \Model \Map \CustomerCustomerFamilyTableMap ;
8
+ use Propel \Runtime \ActiveRecord \ActiveRecordInterface ;
9
+ use Propel \Runtime \Exception \PropelException ;
10
+ use Propel \Runtime \Map \TableMap ;
11
+ use Symfony \Component \Serializer \Annotation \Ignore ;
12
+ use Symfony \Component \Serializer \Attribute \Groups ;
13
+ use Thelia \Api \Resource \Customer as CustomerRessource ;
14
+ use Thelia \Api \Resource \Order as OrderRessource ;
15
+ use Thelia \Api \Resource \PropelResourceInterface ;
16
+ use Thelia \Api \Resource \ResourceAddonInterface ;
17
+ use Thelia \Api \Resource \ResourceAddonTrait ;
18
+
19
+ class CustomerCustomerFamily implements ResourceAddonInterface
20
+ {
21
+ use ResourceAddonTrait;
22
+
23
+ public ?int $ id = null ;
24
+
25
+ #[Groups([CustomerRessource::GROUP_ADMIN_READ , CustomerRessource::GROUP_ADMIN_WRITE , CustomerRessource::GROUP_FRONT_READ_SINGLE , OrderRessource::GROUP_ADMIN_READ ])]
26
+ public ?string $ code = null ;
27
+
28
+ #[Ignore] public static function getResourceParent (): string
29
+ {
30
+ return \Thelia \Api \Resource \Customer::class;
31
+ }
32
+
33
+ #[Ignore] public static function getPropelRelatedTableMap (): ?TableMap
34
+ {
35
+ return new CustomerCustomerFamilyTableMap ();
36
+ }
37
+
38
+ /**
39
+ * @throws PropelException
40
+ */
41
+ public function buildFromModel (ActiveRecordInterface $ activeRecord , PropelResourceInterface $ abstractPropelResource ): ResourceAddonInterface
42
+ {
43
+ if (null === $ customerCustomerFamily = CustomerCustomerFamilyQuery::create ()->filterByCustomerId ($ activeRecord ->getId ())->findOne ()) {
44
+ return $ this ;
45
+ }
46
+
47
+ $ this ->setCode (
48
+ $ activeRecord ->hasVirtualColumn ('CustomerCustomerFamily_code ' )
49
+ ? $ activeRecord ->getVirtualColumn ('CustomerCustomerFamily_code ' )
50
+ : $ customerCustomerFamily ->getCustomerFamily ()->getCode ()
51
+ );
52
+
53
+
54
+ return $ this ;
55
+ }
56
+
57
+ public function buildFromArray (array $ data , PropelResourceInterface $ abstractPropelResource ): ResourceAddonInterface
58
+ {
59
+ $ this ->setCode ($ data ['code ' ] ?? null );
60
+
61
+ return $ this ;
62
+ }
63
+
64
+ /**
65
+ * @throws PropelException
66
+ */
67
+ public function doSave (ActiveRecordInterface $ activeRecord , PropelResourceInterface $ abstractPropelResource ): void
68
+ {
69
+ $ model = new \CustomerFamily \Model \CustomerCustomerFamily ();
70
+
71
+ if ($ activeRecord ->getCustomerCustomerFamily ()) {
72
+ $ id = $ activeRecord ->getCustomerCustomerFamily ()->getCustomerId ();
73
+ $ model = CustomerCustomerFamilyQuery::create ()->filterByCustomerId ($ id )->findOne ();
74
+ }
75
+
76
+ $ model ->setCustomerId ($ activeRecord ->getId ());
77
+ $ model ->setCustomerFamilyId (CustomerFamilyQuery::create ()->findOneByCode ($ this ->getCode ())?->getId());
78
+ $ model ->save ();
79
+ }
80
+
81
+ public function doDelete (ActiveRecordInterface $ activeRecord , PropelResourceInterface $ abstractPropelResource ): void
82
+ {
83
+ $ activeRecord ->getCustomerCustomerFamily ()?->delete();
84
+ }
85
+
86
+ public function getId (): ?int
87
+ {
88
+ return $ this ->id ;
89
+ }
90
+
91
+ public function setId (?int $ id ): CustomerCustomerFamily
92
+ {
93
+ $ this ->id = $ id ;
94
+ return $ this ;
95
+ }
96
+
97
+ public function getCode (): ?string
98
+ {
99
+ return $ this ->code ;
100
+ }
101
+
102
+ public function setCode (?string $ code ): CustomerCustomerFamily
103
+ {
104
+ $ this ->code = $ code ;
105
+ return $ this ;
106
+ }
107
+ }
0 commit comments