Installation Add the package via Composer:
composer require aimeos/ai-symfony
Require the bundle in config/bundles.php:
return [
// ...
Aimeos\Symfony\Bundle\AimeosBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console aimeos:config:init
Update config/packages/aimeos.yaml with your Aimeos backend (e.g., MySQL, SQLite, or Elasticsearch):
aimeos:
client:
name: "default"
type: "mysql"
host: "localhost"
user: "root"
password: ""
database: "aimeos"
context:
name: "default"
First Use Case Fetch a product list in a Symfony controller:
use Aimeos\Symfony\Client\Factory\ClientFactoryInterface;
use Aimeos\MShop\Common\Item\Product\Standard\Standard;
class ProductController extends AbstractController
{
public function list(ClientFactoryInterface $clientFactory)
{
$client = $clientFactory->create('default');
$search = $client->createSearch('product');
$search->setConditions($search->compare('==', 'product.active', 1));
$result = $client->search($search);
$products = $result->getItems();
return $this->render('product/list.html.twig', [
'products' => $products,
]);
}
}
Product Management
ClientFactory to interact with product data:
$client = $clientFactory->create('default');
$product = $client->createItem('product');
$product->setCode('my-product');
$product->setPrice([1000]); // 10.00 EUR
$client->saveItem($product);
$search = $client->createSearch('product');
$search->setConditions($search->compare('==', 'product.price', ['<=', 5000]));
$result = $client->search($search);
Order Processing
$order = $client->createItem('order/base');
$order->setSiteId('default');
$order->setOrderTime(new \DateTime());
$client->saveItem($order);
$orderItem = $client->createItem('order/base/item');
$orderItem->setOrderId($order->getId());
$orderItem->setProductId('my-product');
$orderItem->setPrice([1000]);
$client->saveItem($orderItem);
Customer Management
$client = $clientFactory->create('default');
$customer = $client->createItem('customer');
$customer->setEmail('user@example.com');
$customer->setPassword('securepassword');
$client->saveItem($customer);
# config/packages/security.yaml
providers:
aimeos_user_provider:
id: aimeos.security.user_provider
firewalls:
main:
provider: aimeos_user_provider
Integration with Symfony Forms
use Aimeos\MShop\Common\Item\Product\Standard\Standard;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class ProductType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('code')
->add('price', MoneyType::class);
}
}
use Aimeos\Symfony\Event\AimeosEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AimeosEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
AimeosEvents::PRODUCT_SAVE_AFTER => 'onProductSaved',
];
}
public function onProductSaved($event)
{
$product = $event->getItem();
// Custom logic (e.g., log, notify, or sync with another system)
}
}
Context Management
default) for all operations. Forgetting to set it in aimeos.yaml will throw ContextNotFoundException.context.name in your config.Client Initialization
ClientFactory) to ensure a fresh client per request.Search Complexity
== vs =).Aimeos\MShop\Common\Search\Factory\Standard for helper methods:
$search->setConditions($search->compare('==', 'product.active', 1));
Transaction Handling
$entityManager = $this->getDoctrine()->getManager();
$entityManager->beginTransaction();
try {
$client->saveItem($product);
$entityManager->commit();
} catch (\Exception $e) {
$entityManager->rollback();
throw $e;
}
Caching Quirks
php bin/console cache:clear
php bin/console aimeos:cache:clear
Enable Aimeos Logging
Add to config/packages/monolog.yaml:
handlers:
aimeos:
type: stream
path: "%kernel.logs_dir%/aimeos.log"
level: debug
channels: ["aimeos"]
Then configure Aimeos to use the channel:
# config/packages/aimeos.yaml
aimeos:
client:
logger: "@monolog.logger.aimeos"
SQL Debugging Enable SQL logging for MySQL/PostgreSQL backends:
# config/packages/aimeos.yaml
aimeos:
client:
type: "mysql"
debug: true
Common Errors & Fixes
| Error | Cause | Solution |
|---|---|---|
ContextNotFoundException |
Missing context.name |
Set context.name: "default" in config. |
InvalidArgumentException |
Malformed search condition | Use compare() helper methods. |
PDOException |
Database connection failed | Verify host, user, password in config. |
ClassNotFoundException |
Missing Aimeos namespace | Ensure use Aimeos\MShop\... is correct. |
Custom Search Providers Extend Aimeos’ search with custom providers (e.g., Algolia):
use Aimeos\MShop\Common\Search\Provider\Standard;
class AlgoliaSearchProvider extends Standard
{
public function search($search)
{
// Custom Algolia logic
return $this->createResult($search, $items);
}
}
Register in aimeos.yaml:
aimeos:
search:
provider: "App\Search\AlgoliaSearchProvider"
Override Default Items
Replace Aimeos’ standard items (e.g., Standard\Standard) with custom implementations:
use Aimeos\MShop\Common\Item\Product\Standard\Standard as BaseProduct;
class CustomProduct extends BaseProduct
{
public function getCustomField()
{
return $this->getAttribute('custom_field');
}
}
Bind in services.yaml:
services:
App\MShop\Common\Item\Product\Standard\CustomProduct:
tags: ['aimeos.item.product']
3
How can I help you explore Laravel packages today?