clickandmortar/advanced-enrich-bundle
## Getting Started
### Minimal Setup
1. **Installation**:
```bash
composer require clickandmortar/advanced-enrich-bundle
Ensure compatibility with your Akeneo version (check the versions table in the README).
Enable the Bundle:
Add the bundle to config/bundles.php:
ClickAndMortar\AdvancedEnrichBundle\ClickAndMortarAdvancedEnrichBundle::class => ['all' => true],
First Use Case:
Key Files to Explore:
config/akeneo/advanced_enrich.yaml (if provided by the bundle).src/Resources/config/services.xml (for bundle services).src/DependencyInjection/ (for configuration overrides).Extending Attribute Types:
pim_enrich.entity.attribute_type.advanced).# config/akeneo/advanced_enrich.yaml
advanced_enrich:
attribute_types:
my_custom_type:
class: 'App\Entity\CustomAttributeType'
label: 'Custom Attribute'
Custom Field Rendering:
templates/advanced_enrich/).{# templates/advanced_enrich/attribute_type/my_custom_type/_form.html.twig #}
<input type="text" data-type="my_custom_type" />
Integration with Akeneo Events:
pim_enrich_attribute_type.pre_save or pim_enrich_attribute.pre_save events to validate or modify attribute data:
// src/EventListener/CustomAttributeListener.php
public function onPreSaveAttribute(PreSaveAttributeEvent $event) {
$attribute = $event->getAttribute();
if ($attribute->getType() === 'my_custom_type') {
// Custom logic here
}
}
Register the listener in services.xml:
<service id="app.custom_attribute_listener" class="App\EventListener\CustomAttributeListener">
<tag name="kernel.event_listener" event="pim_enrich_attribute.pre_save" method="onPreSaveAttribute" />
</service>
Mass Actions and Export/Import:
pim_enrich.attribute_type.export service to add custom logic:
# config/services.yaml
pim_enrich.attribute_type.export:
class: 'App\Service\CustomExportAttributeType'
arguments:
- '@pim_enrich.attribute_type.export.default'
API and REST Integration:
NormalizerInterface:
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class CustomAttributeNormalizer implements NormalizerInterface {
public function normalize($object, $format = null, array $context = []) {
return ['data' => $object->getValue()];
}
}
Akeneo Version Mismatch:
Missing Configuration:
advanced_enrich.yaml). If you encounter issues, check if you need to create this file manually in config/akeneo/.Template Overrides:
advanced_enrich/attribute_type/my_type/_form.html.twig) will result in 404 errors.Event Listener Conflicts:
pim_enrich_attribute.pre_save), execution order matters. Use priority tags in services.xml to control order:
<tag name="kernel.event_listener" event="pim_enrich_attribute.pre_save" method="onPreSaveAttribute" priority="200" />
Database Schema Changes:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
Caching Issues:
php bin/console cache:clear
Enable Debug Mode:
APP_DEBUG=1 in .env to get detailed error logs for template or service issues.Log Attribute Events:
public function onPreSaveAttribute(PreSaveAttributeEvent $event) {
\Pim\Tool\Log\Logger::info('Custom attribute saved', ['attribute' => $event->getAttribute()->getCode()]);
}
Check Bundle Assets:
Validate YAML Configuration:
php bin/console config:validate
Custom Attribute Types:
// src/Entity/CustomAttributeType.php
namespace App\Entity;
use ClickAndMortar\AdvancedEnrichBundle\Entity\AbstractAdvancedAttributeType;
class CustomAttributeType extends AbstractAdvancedAttributeType {
// Custom logic here
}
services.xml:
<service id="pim_enrich.attribute_type.custom" class="App\Entity\CustomAttributeType" />
Form Field Customization:
{# templates/advanced_enrich/attribute_type/custom/_form.html.twig #}
<div class="custom-input">
<input type="text" {{ attribute_form_attributes }} />
<span class="custom-label">{{ attribute.label }}</span>
</div>
API Serialization:
class CustomAttributeDenormalizer implements DenormalizerInterface {
public function denormalize($data, $class, $format = null, array $context = []) {
$attribute = new CustomAttribute();
$attribute->setValue($data['value']);
return $attribute;
}
}
Mass Edit Actions:
use Pim\Enrichment\Component\Attribute\AttributeRepositoryInterface;
class CustomMassEditAction {
public function __construct(private AttributeRepositoryInterface $attributeRepository) {}
public function edit(CustomAttribute $attribute, $value) {
$attribute->setValue($value);
$this->attributeRepository->save($attribute);
}
}
Validation Rules:
use Symfony\Component\Validator\Constraints as Assert;
class CustomAttribute {
/**
* @Assert\NotBlank(message="Value cannot be blank")
* @Assert\Length(max=255)
*/
private $value;
}
---
How can I help you explore Laravel packages today?