-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
260 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
sylius_fixtures: | ||
suites: | ||
gift_card: | ||
listeners: | ||
logger: ~ | ||
fixtures: | ||
gift_card: | ||
name: gift_card | ||
options: | ||
amount: 5 | ||
|
||
services: | ||
App\GiftCard\: | ||
resource: '../../src/GiftCard/*' | ||
autowire: true | ||
autoconfigure: true | ||
|
||
App\GiftCard\Menu\AdminMenuListener: | ||
tags: | ||
- { name: kernel.event_listener, event: sylius.menu.admin.main, method: addGiftCardMenu } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GiftCard\Entity; | ||
|
||
use App\GiftCard\Form\Type\GiftCardAdminType; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Sylius\Resource\Metadata\AsResource; | ||
use Sylius\Resource\Metadata\Create; | ||
use Sylius\Resource\Metadata\Delete; | ||
use Sylius\Resource\Metadata\Index; | ||
use Sylius\Resource\Metadata\Update; | ||
use Sylius\Resource\Model\ResourceInterface; | ||
|
||
#[ORM\Entity] | ||
#[ORM\Table(name: 'app_gift_card')] | ||
#[AsResource(section: 'admin', templatesDir: '@SyliusAdmin/Crud')] | ||
#[Index(routePrefix: '/admin', grid: 'app_admin_gift_card')] | ||
#[Create(routePrefix: '/admin', formType: GiftCardAdminType::class)] | ||
#[Update(routePrefix: '/admin', formType: GiftCardAdminType::class)] | ||
#[Delete(routePrefix: '/admin')] | ||
class GiftCard implements ResourceInterface | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue(strategy: 'AUTO')] | ||
#[ORM\Column(type: 'integer')] | ||
private int $id; | ||
|
||
#[ORM\Column(type: 'string')] | ||
private ?string $code; | ||
|
||
#[ORM\Column(type: 'integer')] | ||
private ?int $amount; | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getCode(): ?string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function setCode(?string $code): void | ||
{ | ||
$this->code = $code; | ||
} | ||
|
||
public function getAmount(): ?int | ||
{ | ||
return $this->amount; | ||
} | ||
|
||
public function setAmount(?int $amount): void | ||
{ | ||
$this->amount = $amount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GiftCard\Fixture; | ||
|
||
use App\GiftCard\Entity\GiftCard; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Faker\Factory; | ||
use Faker\Generator; | ||
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
|
||
final class GiftCardFixture extends AbstractFixture | ||
{ | ||
private Generator $faker; | ||
|
||
public function __construct(private EntityManagerInterface $entityManager) | ||
{ | ||
$this->faker = Factory::create(); | ||
} | ||
|
||
public function load(array $options): void | ||
{ | ||
for ($i = 0; $i < $options['amount']; ++$i) { | ||
$giftCard = new GiftCard(); | ||
$giftCard->setCode($this->faker->uuid); | ||
$giftCard->setAmount($this->faker->randomElement([100, 200, 500, 1000, 10000])); | ||
|
||
$this->entityManager->persist($giftCard); | ||
} | ||
|
||
$this->entityManager->flush(); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'gift_card'; | ||
} | ||
|
||
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void | ||
{ | ||
$optionsNode | ||
->children() | ||
->integerNode('amount')->isRequired()->min(0)->end() | ||
->end() | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GiftCard\Form\Type; | ||
|
||
use Sylius\Bundle\MoneyBundle\Form\Type\MoneyType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
final class GiftCardAdminType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder | ||
->add('code', TextType::class) | ||
->add('amount', MoneyType::class, [ | ||
'currency' => 'USD', | ||
]) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GiftCard\Grid; | ||
|
||
use App\GiftCard\Entity\GiftCard; | ||
use Sylius\Bundle\GridBundle\Builder\Action\CreateAction; | ||
use Sylius\Bundle\GridBundle\Builder\Action\DeleteAction; | ||
use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction; | ||
use Sylius\Bundle\GridBundle\Builder\ActionGroup\ItemActionGroup; | ||
use Sylius\Bundle\GridBundle\Builder\ActionGroup\MainActionGroup; | ||
use Sylius\Bundle\GridBundle\Builder\Field\StringField; | ||
use Sylius\Bundle\GridBundle\Builder\Field\TwigField; | ||
use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface; | ||
use Sylius\Bundle\GridBundle\Grid\AbstractGrid; | ||
use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface; | ||
|
||
final class AdminGiftCardGrid extends AbstractGrid implements ResourceAwareGridInterface | ||
{ | ||
public static function getName(): string | ||
{ | ||
return 'app_admin_gift_card'; | ||
} | ||
|
||
public function buildGrid(GridBuilderInterface $gridBuilder): void | ||
{ | ||
$gridBuilder | ||
->addField(StringField::create('code')->setLabel('Code')) | ||
->addField(TwigField::create('amount', 'Admin/GiftCard/_amount.html.twig')->setLabel('Amount')) | ||
->addActionGroup(MainActionGroup::create( | ||
CreateAction::create(), | ||
)) | ||
->addActionGroup(ItemActionGroup::create() | ||
->addAction(UpdateAction::create()) | ||
->addAction(DeleteAction::create()) | ||
); | ||
; | ||
} | ||
|
||
public function getResourceClass(): string | ||
{ | ||
return GiftCard::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GiftCard\Menu; | ||
|
||
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent; | ||
|
||
final class AdminMenuListener | ||
{ | ||
public function addGiftCardMenu(MenuBuilderEvent $event): void | ||
{ | ||
$menu = $event->getMenu(); | ||
$salesSubmenu = $menu->getChild('sales'); | ||
|
||
$salesSubmenu | ||
->addChild('gift_cards', ['route' => 'app_admin_gift_card_index']) | ||
->setLabel('app.ui.gift_cards') | ||
->setLabelAttribute('icon', 'gift') | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20240508104628 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE app_gift_card (id INT AUTO_INCREMENT NOT NULL, code VARCHAR(255) NOT NULL, amount INT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('DROP TABLE app_gift_card'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ data|sylius_format_money('USD', app.locale) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
app: | ||
ui: | ||
gift_cards: 'Gift Cards' | ||
packagings: 'Packagings' |