akeneo/extended-attribute-type
Installation:
composer require akeneo/extended-attribute-type:2.1
Ensure your Akeneo PIM version matches the requirements.
Bundle Registration:
Add the bundle to app/AppKernel.php:
new Pim\Bundle\ExtendedAttributeTypeBundle\PimExtendedAttributeTypeBundle(),
Elasticsearch Configuration:
Update app/config/pim_parameters.yml to include the new Elasticsearch mappings:
elasticsearch_index_configuration_files:
- '%kernel.root_dir%/../vendor/akeneo/pim-community-dev/src/Pim/Bundle/CatalogBundle/Resources/elasticsearch/index_configuration.yml'
- '%kernel.root_dir%/../vendor/akeneo/extended-attribute-type/src/Resources/config/elasticsearch/index_configuration.yml'
For Enterprise Edition, include the additional EE-specific file.
Reset Indexes (if upgrading or migrating):
php bin/console cache:clear --no-warmup --env=prod
php bin/console akeneo:elasticsearch:reset-indexes --env=prod
php bin/console pim:product:index --all --env=prod
php bin/console pim:product-model:index --all --env=prod
First Use Case: Create a TextCollection attribute type via the Akeneo UI:
Attribute Creation & Management:
Data Population:
{
"data": {
"item": {
"identifier": "product_123",
"values": {
"pim_catalog_textcollection_attribute": {
"data": ["Feature 1", "Feature 2", "https://example.com"]
}
}
}
}
}
pim_catalog_textcollection_attribute column.Querying & Filtering:
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "pim_catalog_textcollection_attribute",
"query": {
"match": {
"pim_catalog_textcollection_attribute.data": "Feature 1"
}
}
}
}
]
}
}
}
Pim\Bundle\CatalogBundle\Provider\Product\Query\ProductQueryBuilder to filter products:
$queryBuilder->addFilter('pim_catalog_textcollection_attribute', 'Feature 1', 'contains');
Template Integration:
{% for item in product.get('pim_catalog_textcollection_attribute') %}
<li>{{ item }}</li>
{% endfor %}
{% for item in product.get('pim_catalog_textcollection_attribute') %}
{% if item matches '/^https?:\/\//' %}
<a href="{{ item }}">{{ item }}</a>
{% else %}
{{ item }}
{% endif %}
{% endfor %}
Validation:
Custom Attribute Types:
Pim\Bundle\ExtendedAttributeTypeBundle\Model\Attribute\TextCollectionAttribute.services.yml and updating Elasticsearch mappings.Event Listeners:
# app/config/services.yml
services:
app.textcollection_listener:
class: AppBundle\EventListener\TextCollectionListener
tags:
- { name: kernel.event_listener, event: pim_catalog.product.update.pre, method: onPreUpdate }
public function onPreUpdate(ProductUpdateEvent $event) {
$product = $event->getProduct();
$collection = $product->get('pim_catalog_textcollection_attribute');
// Modify collection logic here
}
Migration Scripts:
$em = $this->getEntityManager();
$products = $em->getRepository('PimCatalogBundle:Product')->findAll();
foreach ($products as $product) {
$product->set('pim_catalog_textcollection_attribute', ['Old data', 'Migrated']);
$em->flush();
}
Testing:
public function testTextCollectionAttribute() {
$product = $this->createProduct();
$product->set('pim_catalog_textcollection_attribute', ['Test 1', 'Test 2']);
$this->assertEquals(['Test 1', 'Test 2'], $product->get('pim_catalog_textcollection_attribute'));
}
Elasticsearch Index Reset:
php bin/console akeneo:elasticsearch:reset-indexes --env=prod
Data Serialization:
// Correct:
$collection = json_decode($product->get('pim_catalog_textcollection_attribute'), true);
// Incorrect (may fail for non-JSON data):
$collection = $product->get('pim_catalog_textcollection_attribute');
UI Glitches:
Performance:
Version Compatibility:
2.1.* bundle version).Check Elasticsearch Mappings:
curl -XGET 'http://localhost:9200/pim_product/_mapping?pretty'
pim_catalog_textcollection_attribute under properties.Log Attribute Data:
use Symfony\Component\Debug\Debug;
Debug::dump($product->get('pim_catalog_textcollection_attribute'));
Common Errors:
Custom Validators:
# config/validation.yml
Pim\Bundle\CatalogBundle\Entity\Product:
constraints:
- Akeneo\Bundle\ExtendedAttributeTypeBundle\Validator\Constraints\TextCollection:
maxItems: 10
allowedPatterns: ["^https?://"]
Custom Templates:
How can I help you explore Laravel packages today?