diff --git a/code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php b/code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php new file mode 100644 index 0000000000..f9f55fa442 --- /dev/null +++ b/code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php @@ -0,0 +1,21 @@ +getDefinition(StorageDefinition::class) + ->addTag('ibexa.product_catalog.attribute.storage_definition', ['type' => 'percent']); + } +} diff --git a/code_samples/catalog/custom_attribute_type/src/Kernel.php b/code_samples/catalog/custom_attribute_type/src/Kernel.php new file mode 100644 index 0000000000..464772c47c --- /dev/null +++ b/code_samples/catalog/custom_attribute_type/src/Kernel.php @@ -0,0 +1,20 @@ +addCompilerPass(new AddFloatStorageDefinitionTag()); + } +} diff --git a/deptrac.baseline.yaml b/deptrac.baseline.yaml index 62fe56828f..98de4ff9f2 100644 --- a/deptrac.baseline.yaml +++ b/deptrac.baseline.yaml @@ -78,6 +78,8 @@ deptrac: - Ibexa\CorporateAccount\Event\ApplicationWorkflowEvents - Ibexa\CorporateAccount\Persistence\Legacy\ApplicationState\HandlerInterface - Ibexa\CorporateAccount\Persistence\Values\ApplicationStateUpdateStruct + App\DependencyInjection\AddFloatStorageDefinitionTag: + - Ibexa\ProductCatalog\Local\Persistence\Legacy\Attribute\Float\StorageDefinition App\Discounts\Condition\IsAccountAnniversary: - Ibexa\Discounts\Value\AbstractDiscountExpressionAware App\Discounts\Condition\IsAccountAnniversaryConditionFactory: @@ -143,8 +145,6 @@ deptrac: - Ibexa\Bundle\Shipping\Form\Type\ShippingMethodChoiceType App\GraphQL\Schema\MyCustomFieldDefinitionMapper: - Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\DecoratingFieldDefinitionMapper - App\Kernel: - - Ibexa\Bundle\Core\DependencyInjection\IbexaCoreExtension App\Migrations\Action\AssignSection: - Ibexa\Migration\ValueObject\Step\Action App\Migrations\Action\AssignSectionExecutor: diff --git a/docs/pim/create_custom_attribute_type.md b/docs/pim/create_custom_attribute_type.md index 71fd03254f..b2831f4363 100644 --- a/docs/pim/create_custom_attribute_type.md +++ b/docs/pim/create_custom_attribute_type.md @@ -160,7 +160,9 @@ Register the converter as a service and tag it with `ibexa.product_catalog.attri ### Storage definition -Next, prepare a `PercentStorageDefinition` class, which implements `Ibexa\Contracts\ProductCatalog\Local\Attribute\StorageDefinitionInterface`. +You can either create a new storage definition or use an existing one. + +To create a new storage definition, prepare a `PercentStorageDefinition` class, which implements `Ibexa\Contracts\ProductCatalog\Local\Attribute\StorageDefinitionInterface`. ``` php [[= include_file('code_samples/catalog/custom_attribute_type/src/Attribute/Percent/Storage/PercentStorageDefinition.php') =]] @@ -172,6 +174,19 @@ Register the storage definition as a service and tag it with `ibexa.product_cata [[= include_file('code_samples/catalog/custom_attribute_type/config/custom_services.yaml', 41, 44) =]] ``` +If you prefer to use an existing storage definition, you need to create a Storage Definition Tag CompilerPass `src/DependencyInjection/AddFloatStorageDefinitionTag.php`: + +``` php +[[= include_file('code_samples/catalog/custom_attribute_type/src/DependencyInjection/AddFloatStorageDefinitionTag.php') =]] +``` + +Add the CompilerPass to the container. +Do it in a `src/Kernel.php` file or in your Bundle class: + +``` php hl_lines="5 7-8 14-20" +[[= include_file('code_samples/catalog/custom_attribute_type/src/Kernel.php') =]] +``` + ## Use new attribute type In the back office you can now add a new Percent attribute to your product type and create a product with it.