Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace App\DependencyInjection;

use Ibexa\ProductCatalog\Local\Persistence\Legacy\Attribute\Float\StorageDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AddFloatStorageDefinitionTag implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$container->getDefinition(StorageDefinition::class)
->addTag('ibexa.product_catalog.attribute.storage_definition', ['type' => 'percent']);
}
}
20 changes: 20 additions & 0 deletions code_samples/catalog/custom_attribute_type/src/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace App;

use App\DependencyInjection\AddFloatStorageDefinitionTag;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
{
use MicroKernelTrait;

public function build(ContainerBuilder $container): void
{
parent::build($container);

$container->addCompilerPass(new AddFloatStorageDefinitionTag());
}
}
16 changes: 15 additions & 1 deletion docs/pim/create_custom_attribute_type.md
Original file line number Diff line number Diff line change
Expand Up @@ -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') =]]
Expand All @@ -172,6 +174,18 @@ 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:
Copy link
Contributor

@dabrt dabrt Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Add the CompilerPass to the container. Do it in a `src/Kernel.php` file or in your Bundle class:
Add the CompilerPass to the container.
Do it in a `src/Kernel.php` file or in your Bundle class:

@mateuszdebinski Thank you for directly contributing to the documentation!


``` 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.
Expand Down