Skip to content

Commit

Permalink
Add AgeAwareProductInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Sep 25, 2024
1 parent e095f13 commit 5fd56fe
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ public function getConfigTreeBuilder(): TreeBuilder
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
->scalarNode('option')
->info('This is an example configuration option')
->isRequired()
->cannotBeEmpty()
;

return $treeBuilder;
}
}
15 changes: 15 additions & 0 deletions src/Model/AgeAwareProductInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusAgeVerificationPlugin\Model;

interface AgeAwareProductInterface
{
/**
* Null means no age verification is required
*/
public function getMinimumAge(): ?int;

public function setMinimumAge(?int $minimumAge): void;
}
24 changes: 24 additions & 0 deletions src/Model/AgeAwareProductTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusAgeVerificationPlugin\Model;

use Doctrine\ORM\Mapping as ORM;

trait AgeAwareProductTrait
{
/** @ORM\Column(type="smallint", nullable=true, options={"unsigned"=true}) */
#[ORM\Column(type: 'smallint', nullable: true, options: ['unsigned' => true])]
protected ?int $minimumAge = null;

public function getMinimumAge(): ?int
{
return $this->minimumAge;
}

public function setMinimumAge(?int $minimumAge): void
{
$this->minimumAge = $minimumAge;
}
}
20 changes: 20 additions & 0 deletions tests/Application/Model/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusAgeVerificationPlugin\Tests\Application\Model;

use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusAgeVerificationPlugin\Model\AgeAwareProductInterface;
use Setono\SyliusAgeVerificationPlugin\Model\AgeAwareProductTrait;
use Sylius\Component\Core\Model\Product as BaseProduct;

/**
* @ORM\Entity()
*
* @ORM\Table(name="sylius_product")
*/
class Product extends BaseProduct implements AgeAwareProductInterface
{
use AgeAwareProductTrait;
}
6 changes: 6 additions & 0 deletions tests/Application/config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ sylius_shop:

sylius_api:
enabled: true

sylius_product:
resources:
product:
classes:
model: Setono\SyliusAgeVerificationPlugin\Tests\Application\Model\Product
10 changes: 10 additions & 0 deletions tests/Application/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ doctrine:
charset: UTF8

url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/Model'
prefix: 'Setono\SyliusAgeVerificationPlugin\Tests\Application\Model'
alias: App
Empty file.

0 comments on commit 5fd56fe

Please sign in to comment.