Skip to content

Commit cf001f5

Browse files
Add Api customer family code (#27)
* Add Api customer family code * remove extend query
1 parent f91099f commit cf001f5

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
}

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

0 commit comments

Comments
 (0)