feat(product): #issue-13467 - add position field to ProductOptionValues

This commit is contained in:
johbuch 2026-06-24 10:28:26 +02:00
parent cbb32838fb
commit 23b15c12fd
17 changed files with 170 additions and 0 deletions

View file

@ -49,6 +49,9 @@ sylius_twig_hooks:
code:
template: '@SyliusAdmin/product_option/form/sections/values/value/code.html.twig'
priority: 200
position:
template: '@SyliusAdmin/product_option/form/sections/values/value/position.html.twig'
priority: 150
translations:
template: '@SyliusAdmin/product_option/form/sections/values/value/translations.html.twig'
priority: 100

View file

@ -51,6 +51,9 @@ sylius_twig_hooks:
code:
template: '@SyliusAdmin/product_option/form/sections/values/value/code.html.twig'
priority: 200
position:
template: '@SyliusAdmin/product_option/form/sections/values/value/position.html.twig'
priority: 150
translations:
template: '@SyliusAdmin/product_option/form/sections/values/value/translations.html.twig'
priority: 100

View file

@ -0,0 +1,3 @@
<div class="col-12">
{{ form_row(hookable_metadata.context.value_form.position, sylius_test_form_attribute('position')) }}
</div>

View file

@ -59,6 +59,9 @@
</value>
</values>
</normalizationContext>
<filters>
<filter>sylius_api.order_filter.admin.product_option_value</filter>
</filters>
</operation>
</operations>
</resource>

View file

@ -34,6 +34,14 @@
<group>sylius:shop:product_option_value:index</group>
<group>sylius:shop:product_option_value:show</group>
</attribute>
<attribute name="position">
<group>sylius:admin:product_option_value:index</group>
<group>sylius:admin:product_option_value:show</group>
<group>sylius:admin:product_option:index</group>
<group>sylius:admin:product_option:show</group>
<group>sylius:admin:product_option:create</group>
<group>sylius:admin:product_option:update</group>
</attribute>
<attribute name="translations">
<group>sylius:admin:product_option_value:show</group>
<group>sylius:admin:product_option:create</group>

View file

@ -393,6 +393,13 @@
<tag name="api_platform.filter" />
</service>
<service id="sylius_api.order_filter.admin.product_option_value" parent="api_platform.doctrine.orm.order_filter">
<argument type="collection">
<argument key="position" />
</argument>
<tag name="api_platform.filter" />
</service>
<service id="sylius_api.search_filter.admin.locale" parent="api_platform.doctrine.orm.search_filter">
<argument type="collection">
<argument key="code">partial</argument>

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\CoreBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Sylius\Bundle\CoreBundle\Doctrine\Migrations\AbstractMigration;
final class Version20260623000000 extends AbstractMigration
{
private const TABLE_NAME = 'sylius_product_option_value';
public function getDescription(): string
{
return 'Add position column to sylius_product_option_value (MySQL)';
}
public function up(Schema $schema): void
{
if (!$schema->hasTable(self::TABLE_NAME)) {
return;
}
$table = $schema->getTable(self::TABLE_NAME);
if ($table->hasColumn('position')) {
return;
}
$this->addSql('ALTER TABLE ' . self::TABLE_NAME . ' ADD position INT NOT NULL DEFAULT 0');
}
public function down(Schema $schema): void
{
if (!$schema->hasTable(self::TABLE_NAME)) {
return;
}
$table = $schema->getTable(self::TABLE_NAME);
if (!$table->hasColumn('position')) {
return;
}
$this->addSql('ALTER TABLE ' . self::TABLE_NAME . ' DROP COLUMN position');
}
}

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\CoreBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Sylius\Bundle\CoreBundle\Doctrine\Migrations\AbstractPostgreSQLMigration;
final class Version20260623000001 extends AbstractPostgreSQLMigration
{
private const TABLE_NAME = 'sylius_product_option_value';
public function getDescription(): string
{
return 'Add position column to sylius_product_option_value (PostgreSQL)';
}
public function up(Schema $schema): void
{
if (!$schema->hasTable(self::TABLE_NAME)) {
return;
}
$table = $schema->getTable(self::TABLE_NAME);
if ($table->hasColumn('position')) {
return;
}
$this->addSql('ALTER TABLE ' . self::TABLE_NAME . ' ADD position INT NOT NULL DEFAULT 0');
}
public function down(Schema $schema): void
{
if (!$schema->hasTable(self::TABLE_NAME)) {
return;
}
$table = $schema->getTable(self::TABLE_NAME);
if (!$table->hasColumn('position')) {
return;
}
$this->addSql('ALTER TABLE ' . self::TABLE_NAME . ' DROP COLUMN position');
}
}

View file

@ -16,6 +16,7 @@ namespace Sylius\Bundle\ProductBundle\Form\Type;
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormBuilderInterface;
final class ProductOptionValueType extends AbstractResourceType
@ -27,6 +28,10 @@ final class ProductOptionValueType extends AbstractResourceType
'entry_type' => ProductOptionValueTranslationType::class,
'label' => 'sylius.form.option.name',
])
->add('position', IntegerType::class, [
'label' => 'sylius.form.option_value.position',
'required' => false,
])
->addEventSubscriber(new AddCodeFormSubscriber())
;
}

View file

@ -20,6 +20,8 @@
<field name="code" column="code" type="string" unique="true" />
<field name="position" type="integer" />
<many-to-one target-entity="Sylius\Component\Product\Model\ProductOptionInterface" field="option" inversed-by="values">
<join-columns>
<join-column name="option_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />

View file

@ -29,3 +29,4 @@ sylius:
option_value:
add_value: Add value
value: Value
position: Position

View file

@ -26,3 +26,4 @@ sylius:
option_value:
add_value: Add value
value: Value
position: Position

View file

@ -29,3 +29,4 @@ sylius:
option_value:
add_value: Ajouter une valeur
value: Valeur
position: Emplacement

View file

@ -29,3 +29,4 @@ sylius:
option_value:
add_value: Ajouter une valeur
value: Valeur
position: Emplacement

View file

@ -29,3 +29,4 @@ sylius:
option_value:
add_value: Ajouter une valeur
value: Valeur
position: Emplacement

View file

@ -32,6 +32,9 @@ class ProductOptionValue implements ProductOptionValueInterface, \Stringable
/** @var ProductOptionInterface|null */
protected $option;
/** @var int|null */
protected $position;
public function __construct()
{
$this->initializeTranslationCollection();
@ -67,6 +70,16 @@ class ProductOptionValue implements ProductOptionValueInterface, \Stringable
$this->option = $option;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): void
{
$this->position = $position;
}
public function getValue(): ?string
{
return $this->getTranslation()->getValue();

View file

@ -32,6 +32,10 @@ interface ProductOptionValueInterface extends ResourceInterface, CodeAwareInterf
public function getName(): ?string;
public function getPosition(): ?int;
public function setPosition(?int $position): void;
/**
* @return ProductOptionValueTranslationInterface
*/