-
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.
Customise ProductVariant to generate gift card with given value
- Loading branch information
Showing
4 changed files
with
114 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Form\Extension; | ||
|
||
use Sylius\Bundle\MoneyBundle\Form\Type\MoneyType; | ||
use Sylius\Bundle\ProductBundle\Form\Type\ProductVariantType; | ||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
final class ProductVariantTypeExtension extends AbstractTypeExtension | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('generatedGiftCardValue', MoneyType::class, [ | ||
'currency' => 'USD', | ||
]) | ||
; | ||
} | ||
|
||
public static function getExtendedTypes(): iterable | ||
{ | ||
yield ProductVariantType::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,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 Version20240508115429 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('ALTER TABLE sylius_product_variant ADD generated_gift_card_value INT DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE sylius_product_variant DROP generated_gift_card_value'); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
templates/bundles/SyliusAdminBundle/ProductVariant/Tab/_details.html.twig
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,43 @@ | ||
{% from '@SyliusAdmin/Macro/translationForm.html.twig' import translationForm %} | ||
|
||
<div class="ui active tab" data-tab="details"> | ||
<h3 class="ui dividing header">{{ 'sylius.ui.details'|trans }}</h3> | ||
|
||
<div class="ui segments"> | ||
{{ translationForm(form.translations) }} | ||
<div class="ui hidden divider"></div> | ||
<div class="ui segment"> | ||
{{ form_row(form.code) }} | ||
{{ form_row(form.enabled) }} | ||
</div> | ||
<div class="ui hidden divider"></div> | ||
<div class="ui segment"> | ||
<div class="two fields"> | ||
{{ form_row(form.shippingCategory) }} | ||
</div> | ||
<div class="one field"> | ||
{{ form_row(form.shippingRequired) }} | ||
</div> | ||
</div> | ||
{% if form.optionValues is defined and form.optionValues|length > 0 %} | ||
<div class="ui hidden divider"></div> | ||
<div class="ui segment"> | ||
<h4 class="ui dividing header">{{ 'sylius.ui.options'|trans }}</h4> | ||
{% for option_form in form.optionValues %} | ||
{{ form_row(option_form) }} | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
<div class="ui hidden divider"></div> | ||
<div class="ui segment"> | ||
<h4 class="ui dividing header">{{ 'sylius.ui.properties'|trans }}</h4> | ||
{{ form_row(form.height) }} | ||
{{ form_row(form.width) }} | ||
{{ form_row(form.depth) }} | ||
{{ form_row(form.weight) }} | ||
{{ form_row(form.generatedGiftCardValue) }} | ||
</div> | ||
</div> | ||
|
||
{{ sylius_template_event(['sylius.admin.product_variant.' ~ action ~ '.tab_details', 'sylius.admin.product_variant.tab_details'], {'form': form}) }} | ||
</div> |