clickandmortar/advanced-csv-connector-bundle
Installation:
composer.json under repositories:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ClickAndMortar/CustomEntityBundle"
}
]
composer require clickandmortar/advanced-csv-connector-bundle
config/bundles.php:
return [
// ...
ClickAndMortar\AdvancedCsvConnectorBundle\ClickAndMortarAdvancedCsvConnectorBundle::class => ['all' => true],
];
First Use Case:
Product or Family) by creating a custom mapping file in:
config/akeneo/advanced-csv-connector/mapping/[entity_name].php
return [
'columns' => [
'identifier' => 'sku',
'families' => 'family',
'enabled' => 'active',
// Custom mappings...
],
'headers' => [
'sku' => 'SKU',
'family' => 'Family',
'active' => 'Is Active',
],
];
Trigger a Test Export:
php bin/console akeneo:csv-export --entity=Product --file=test_export.csv
Define Mappings:
Product, Family, Category).columns key to map CSV headers to Akeneo entity properties.headers key to define the CSV header row (optional if using default headers).Dynamic Value Transformation (Lua):
# config/packages/click_and_mortar_advanced_csv_connector.yaml
click_and_mortar_advanced_csv_connector:
lua_enabled: true
price):
-- In your mapping file or a separate Lua script
function transformPrice(value)
return tonumber(value) * 1.1 -- Apply 10% tax
end
'price' => [
'header' => 'Price',
'transformer' => 'transformPrice',
],
Integration with Akeneo Jobs:
# config/akeneo/job_instance/[custom_job].yaml
job_instance:
code: custom_product_import
type: import
connector: advanced_csv
processor: custom_product_processor
// src/Akeneo/Pim/Enrichment/Processor/CustomProductProcessor.php
use ClickAndMortar\AdvancedCsvConnectorBundle\Processor\AdvancedCsvProcessor;
class CustomProductProcessor extends AdvancedCsvProcessor
{
public function process($data)
{
// Custom logic before/after parent processing
$this->applyCustomRules($data);
return parent::process($data);
}
}
Validation and Error Handling:
'columns' => [
'sku' => [
'header' => 'SKU',
'validator' => 'required|min:3|max:20',
],
],
// src/Akeneo/Pim/Enrichment/ErrorHandler/CustomErrorHandler.php
use ClickAndMortar\AdvancedCsvConnectorBundle\ErrorHandler\AdvancedCsvErrorHandler;
class CustomErrorHandler extends AdvancedCsvErrorHandler
{
public function handleError($error, $context)
{
// Custom error logging or notification
$this->logError($error);
return parent::handleError($error, $context);
}
}
| Pattern | Example Use Case | Implementation Tip |
|---|---|---|
| Column Remapping | Rename CSV headers for client compatibility | Use headers key in mapping files. |
| Dynamic Calculations | Apply business rules (e.g., discounts) | Use Lua scripts or PHP transformers. |
| Conditional Logic | Skip rows based on criteria | Extend AdvancedCsvProcessor with filters. |
| Multi-Entity Imports | Import Products + Families in one file | Use nested mappings or custom processors. |
| Localization Handling | Manage translated fields in CSV | Map locale fields explicitly in mappings. |
Mapping File Overrides:
config/ may be overwritten during updates.config_loader service to merge mappings dynamically:
# config/packages/click_and_mortar_advanced_csv_connector.yaml
click_and_mortar_advanced_csv_connector:
mapping_loader:
- '%kernel.project_dir%/config/akeneo/advanced-csv-connector/mapping'
Lua Security Restrictions:
'price' => [
'header' => 'Price',
'transformer' => 'App\Transformer\PriceTransformer',
];
Performance with Large Files:
php bin/console akeneo:csv-import --entity=Product --file=large_file.csv --chunk-size=100
Header Mismatches:
headers key to explicitly define the CSV header row:
'headers' => [
'custom_sku' => 'SKU',
'custom_family' => 'Family',
],
Dependency Conflicts:
akeneo/connect).composer.json for version constraints and use replace:
"replace": {
"akeneo/connect": "v1.0.*"
}
Enable Verbose Logging:
config/packages/monolog.yaml:
handlers:
advanced_csv:
type: stream
path: "%kernel.logs_dir%/advanced_csv.log"
level: debug
channels: ["akeneo"]
Validate Mappings:
akeneo:csv-validate command to check mappings before import/export:
php bin/console akeneo:csv-validate --entity=Product --file=test.csv
Inspect Processed Data:
public function process($data)
{
file_put_contents(
'/tmp/debug.csv',
print_r($data, true),
FILE_APPEND
);
return parent::process($data);
}
Custom Transformers:
# config/services.yaml
services:
App\Transformer\CustomTransformer:
tags: ['akeneo.csv.transformer']
Event Listeners:
akeneo_csv.pre_process or akeneo_csv.post_process events:
// src/EventListener/CsvListener.php
use ClickAndMortar\AdvancedCsvConnectorBundle\Event\CsvEvent;
class CsvListener
{
public function onPreProcess(CsvEvent $event)
{
$event->setData($this->modifyData($event->getData()));
}
}
Register the listener in services.yaml:
tags: ['kernel.event_listener', { event: 'akeneo_csv.pre_process', method: 'onPreProcess' }]
Custom Job Types:
export_to_s3):
// src/
How can I help you explore Laravel packages today?