Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ai Symfony Laravel Package

aimeos/ai-symfony

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    ];
    
  2. 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"
    
  3. 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,
            ]);
        }
    }
    

Implementation Patterns

Common Workflows

  1. Product Management

    • CRUD Operations: Use 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 & Filtering: Leverage Aimeos' search API for dynamic queries:
      $search = $client->createSearch('product');
      $search->setConditions($search->compare('==', 'product.price', ['<=', 5000]));
      $result = $client->search($search);
      
  2. Order Processing

    • Create Orders:
      $order = $client->createItem('order/base');
      $order->setSiteId('default');
      $order->setOrderTime(new \DateTime());
      $client->saveItem($order);
      
    • Add Order Items:
      $orderItem = $client->createItem('order/base/item');
      $orderItem->setOrderId($order->getId());
      $orderItem->setProductId('my-product');
      $orderItem->setPrice([1000]);
      $client->saveItem($orderItem);
      
  3. Customer Management

    • Authentication:
      $client = $clientFactory->create('default');
      $customer = $client->createItem('customer');
      $customer->setEmail('user@example.com');
      $customer->setPassword('securepassword');
      $client->saveItem($customer);
      
    • Session Handling: Use Symfony’s security component with Aimeos:
      # config/packages/security.yaml
      providers:
          aimeos_user_provider:
              id: aimeos.security.user_provider
      firewalls:
          main:
              provider: aimeos_user_provider
      
  4. Integration with Symfony Forms

    • Bind Aimeos entities to 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);
          }
      }
      

Event-Driven Extensions

  • Listen to Aimeos Events:
    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)
        }
    }
    

Gotchas and Tips

Pitfalls

  1. Context Management

    • Aimeos requires a context (e.g., default) for all operations. Forgetting to set it in aimeos.yaml will throw ContextNotFoundException.
    • Fix: Always verify context.name in your config.
  2. Client Initialization

    • Reusing the same client instance across requests can lead to stale data if not properly flushed.
    • Tip: Use dependency injection (via ClientFactory) to ensure a fresh client per request.
  3. Search Complexity

    • Aimeos’ search syntax is powerful but verbose. Common mistakes:
      • Forgetting to escape special characters in conditions (e.g., == vs =).
      • Tip: Use Aimeos\MShop\Common\Search\Factory\Standard for helper methods:
        $search->setConditions($search->compare('==', 'product.active', 1));
        
  4. Transaction Handling

    • Aimeos operations are not automatically transactional in Symfony. Wrap critical sections in a transaction:
      $entityManager = $this->getDoctrine()->getManager();
      $entityManager->beginTransaction();
      try {
          $client->saveItem($product);
          $entityManager->commit();
      } catch (\Exception $e) {
          $entityManager->rollback();
          throw $e;
      }
      
  5. Caching Quirks

    • Aimeos caches search results aggressively. Clear cache manually when testing:
      php bin/console cache:clear
      php bin/console aimeos:cache:clear
      

Debugging Tips

  1. 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"
    
  2. SQL Debugging Enable SQL logging for MySQL/PostgreSQL backends:

    # config/packages/aimeos.yaml
    aimeos:
        client:
            type: "mysql"
            debug: true
    
  3. 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.

Extension Points

  1. 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"
    
  2. 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

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle