mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
feat(product): #issue-13467 - add position field to ProductOptionValues
This commit is contained in:
parent
cbb32838fb
commit
23b15c12fd
17 changed files with 170 additions and 0 deletions
|
|
@ -49,6 +49,9 @@ sylius_twig_hooks:
|
||||||
code:
|
code:
|
||||||
template: '@SyliusAdmin/product_option/form/sections/values/value/code.html.twig'
|
template: '@SyliusAdmin/product_option/form/sections/values/value/code.html.twig'
|
||||||
priority: 200
|
priority: 200
|
||||||
|
position:
|
||||||
|
template: '@SyliusAdmin/product_option/form/sections/values/value/position.html.twig'
|
||||||
|
priority: 150
|
||||||
translations:
|
translations:
|
||||||
template: '@SyliusAdmin/product_option/form/sections/values/value/translations.html.twig'
|
template: '@SyliusAdmin/product_option/form/sections/values/value/translations.html.twig'
|
||||||
priority: 100
|
priority: 100
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,9 @@ sylius_twig_hooks:
|
||||||
code:
|
code:
|
||||||
template: '@SyliusAdmin/product_option/form/sections/values/value/code.html.twig'
|
template: '@SyliusAdmin/product_option/form/sections/values/value/code.html.twig'
|
||||||
priority: 200
|
priority: 200
|
||||||
|
position:
|
||||||
|
template: '@SyliusAdmin/product_option/form/sections/values/value/position.html.twig'
|
||||||
|
priority: 150
|
||||||
translations:
|
translations:
|
||||||
template: '@SyliusAdmin/product_option/form/sections/values/value/translations.html.twig'
|
template: '@SyliusAdmin/product_option/form/sections/values/value/translations.html.twig'
|
||||||
priority: 100
|
priority: 100
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div class="col-12">
|
||||||
|
{{ form_row(hookable_metadata.context.value_form.position, sylius_test_form_attribute('position')) }}
|
||||||
|
</div>
|
||||||
|
|
@ -59,6 +59,9 @@
|
||||||
</value>
|
</value>
|
||||||
</values>
|
</values>
|
||||||
</normalizationContext>
|
</normalizationContext>
|
||||||
|
<filters>
|
||||||
|
<filter>sylius_api.order_filter.admin.product_option_value</filter>
|
||||||
|
</filters>
|
||||||
</operation>
|
</operation>
|
||||||
</operations>
|
</operations>
|
||||||
</resource>
|
</resource>
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,14 @@
|
||||||
<group>sylius:shop:product_option_value:index</group>
|
<group>sylius:shop:product_option_value:index</group>
|
||||||
<group>sylius:shop:product_option_value:show</group>
|
<group>sylius:shop:product_option_value:show</group>
|
||||||
</attribute>
|
</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">
|
<attribute name="translations">
|
||||||
<group>sylius:admin:product_option_value:show</group>
|
<group>sylius:admin:product_option_value:show</group>
|
||||||
<group>sylius:admin:product_option:create</group>
|
<group>sylius:admin:product_option:create</group>
|
||||||
|
|
|
||||||
|
|
@ -393,6 +393,13 @@
|
||||||
<tag name="api_platform.filter" />
|
<tag name="api_platform.filter" />
|
||||||
</service>
|
</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">
|
<service id="sylius_api.search_filter.admin.locale" parent="api_platform.doctrine.orm.search_filter">
|
||||||
<argument type="collection">
|
<argument type="collection">
|
||||||
<argument key="code">partial</argument>
|
<argument key="code">partial</argument>
|
||||||
|
|
|
||||||
|
|
@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,7 @@ namespace Sylius\Bundle\ProductBundle\Form\Type;
|
||||||
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber;
|
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber;
|
||||||
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
|
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
|
||||||
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType;
|
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
|
||||||
final class ProductOptionValueType extends AbstractResourceType
|
final class ProductOptionValueType extends AbstractResourceType
|
||||||
|
|
@ -27,6 +28,10 @@ final class ProductOptionValueType extends AbstractResourceType
|
||||||
'entry_type' => ProductOptionValueTranslationType::class,
|
'entry_type' => ProductOptionValueTranslationType::class,
|
||||||
'label' => 'sylius.form.option.name',
|
'label' => 'sylius.form.option.name',
|
||||||
])
|
])
|
||||||
|
->add('position', IntegerType::class, [
|
||||||
|
'label' => 'sylius.form.option_value.position',
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
->addEventSubscriber(new AddCodeFormSubscriber())
|
->addEventSubscriber(new AddCodeFormSubscriber())
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
<field name="code" column="code" type="string" unique="true" />
|
<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">
|
<many-to-one target-entity="Sylius\Component\Product\Model\ProductOptionInterface" field="option" inversed-by="values">
|
||||||
<join-columns>
|
<join-columns>
|
||||||
<join-column name="option_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
|
<join-column name="option_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
|
||||||
|
|
|
||||||
|
|
@ -29,3 +29,4 @@ sylius:
|
||||||
option_value:
|
option_value:
|
||||||
add_value: Add value
|
add_value: Add value
|
||||||
value: Value
|
value: Value
|
||||||
|
position: Position
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,4 @@ sylius:
|
||||||
option_value:
|
option_value:
|
||||||
add_value: Add value
|
add_value: Add value
|
||||||
value: Value
|
value: Value
|
||||||
|
position: Position
|
||||||
|
|
|
||||||
|
|
@ -29,3 +29,4 @@ sylius:
|
||||||
option_value:
|
option_value:
|
||||||
add_value: Ajouter une valeur
|
add_value: Ajouter une valeur
|
||||||
value: Valeur
|
value: Valeur
|
||||||
|
position: Emplacement
|
||||||
|
|
|
||||||
|
|
@ -29,3 +29,4 @@ sylius:
|
||||||
option_value:
|
option_value:
|
||||||
add_value: Ajouter une valeur
|
add_value: Ajouter une valeur
|
||||||
value: Valeur
|
value: Valeur
|
||||||
|
position: Emplacement
|
||||||
|
|
|
||||||
|
|
@ -29,3 +29,4 @@ sylius:
|
||||||
option_value:
|
option_value:
|
||||||
add_value: Ajouter une valeur
|
add_value: Ajouter une valeur
|
||||||
value: Valeur
|
value: Valeur
|
||||||
|
position: Emplacement
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,9 @@ class ProductOptionValue implements ProductOptionValueInterface, \Stringable
|
||||||
/** @var ProductOptionInterface|null */
|
/** @var ProductOptionInterface|null */
|
||||||
protected $option;
|
protected $option;
|
||||||
|
|
||||||
|
/** @var int|null */
|
||||||
|
protected $position;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->initializeTranslationCollection();
|
$this->initializeTranslationCollection();
|
||||||
|
|
@ -67,6 +70,16 @@ class ProductOptionValue implements ProductOptionValueInterface, \Stringable
|
||||||
$this->option = $option;
|
$this->option = $option;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPosition(): ?int
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPosition(?int $position): void
|
||||||
|
{
|
||||||
|
$this->position = $position;
|
||||||
|
}
|
||||||
|
|
||||||
public function getValue(): ?string
|
public function getValue(): ?string
|
||||||
{
|
{
|
||||||
return $this->getTranslation()->getValue();
|
return $this->getTranslation()->getValue();
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,10 @@ interface ProductOptionValueInterface extends ResourceInterface, CodeAwareInterf
|
||||||
|
|
||||||
public function getName(): ?string;
|
public function getName(): ?string;
|
||||||
|
|
||||||
|
public function getPosition(): ?int;
|
||||||
|
|
||||||
|
public function setPosition(?int $position): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ProductOptionValueTranslationInterface
|
* @return ProductOptionValueTranslationInterface
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue