Skip to content

Commit

Permalink
php attributes for doctrine mappings added
Browse files Browse the repository at this point in the history
  • Loading branch information
gewebe committed May 7, 2024
1 parent f421390 commit a978b6a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ use Sylius\Component\Core\Model\Address as BaseAddress;
* @ORM\Entity
* @ORM\Table(name="sylius_address")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_address')]
class Address extends BaseAddress implements VatNumberAddressInterface
{
use VatNumberAwareTrait;
Expand Down Expand Up @@ -128,6 +130,8 @@ use Sylius\Component\Core\Model\ShopBillingData as BaseShopBillingData;
* @ORM\Entity
* @ORM\Table(name="sylius_shop_billing_data")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_shop_billing_data')]
class ShopBillingData extends BaseShopBillingData implements ShopBillingDataVatNumberInterface
{
use ShopBillingDataVatNumberAwareTrait;
Expand Down
3 changes: 3 additions & 0 deletions src/Entity/ShopBillingDataVatNumberAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Gewebe\SyliusVATPlugin\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

Expand All @@ -19,6 +20,8 @@ trait ShopBillingDataVatNumberAwareTrait
*
* @Groups({"admin:shop_billing_data:read"})
*/
#[ORM\Column(name: 'vat_number', type: Types::STRING, nullable: true)]
#[Groups(['admin:shop_billing_data:read'])]
protected ?string $vatNumber = null;

public function getVatNumber(): ?string
Expand Down
8 changes: 8 additions & 0 deletions src/Entity/VatNumberAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Gewebe\SyliusVATPlugin\Entity;

use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
Expand All @@ -23,20 +24,27 @@ trait VatNumberAwareTrait
*
* @Groups({"shop:address:read", "shop:address:create", "shop:address:update"})
*/
#[ORM\Column(name: 'vat_number', type: Types::STRING, nullable: true)]
#[Gedmo\Versioned()]
#[Groups(['shop:address:read', 'shop:address:create', 'shop:address:update'])]
protected ?string $vatNumber = null;

/**
* @ORM\Column(name="vat_valid", type="boolean")
*
* @Groups({"shop:address:read"})
*/
#[ORM\Column(name: 'vat_valid', type: Types::BOOLEAN)]
#[Groups(['shop:address:read'])]
protected bool $vatValid = false;

/**
* @ORM\Column(name="vat_validated_at", type="datetime", nullable=true)
*
* @Groups({"shop:address:read"})
*/
#[ORM\Column(name: 'vat_validated_at', type: Types::DATETIME_MUTABLE, nullable: true)]
#[Groups(['shop:address:read'])]
protected ?DateTime $vatValidatedAt = null;

public function getVatNumber(): ?string
Expand Down
2 changes: 1 addition & 1 deletion tests/Application/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ doctrine:
mappings:
App:
is_bundle: false
type: annotation
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'Tests\Gewebe\SyliusVATPlugin\Application\src\Entity'
alias: App
2 changes: 2 additions & 0 deletions tests/Application/src/Entity/Addressing/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @ORM\Entity
* @ORM\Table(name="sylius_address")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_address')]
class Address extends BaseAddress implements VatNumberAddressInterface
{
use VatNumberAwareTrait;
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/src/Entity/Channel/ShopBillingData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @ORM\Entity
* @ORM\Table(name="sylius_shop_billing_data")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_shop_billing_data')]
class ShopBillingData extends BaseShopBillingData implements ShopBillingDataVatNumberInterface
{
use ShopBillingDataVatNumberAwareTrait;
Expand Down

0 comments on commit a978b6a

Please sign in to comment.