Frameworks
Drupal 10 — Scell.io integration
Drupal module via PHP SDK + Hook System
The `scell/sdk` PHP SDK v3.5.0 integrates into a Drupal 10 module via root-level `composer require`. Service defined in `mymodule.services.yml`, injected into controllers/services via DI. `hook_entity_insert()` to generate an invoice on Commerce order creation. Compatible with Drupal Commerce 3.
Key facts
- `composer require scell/sdk` at Drupal root
- Service defined in `mymodule.services.yml`
- `hook_entity_insert()` for Commerce orders
- Config via `Drupal::config('mymodule.settings')`
- Compatible with Drupal 10.2+, PHP 8.2+
Code example
use Scell\Sdk\Client;
use Drupal\commerce_order\Entity\OrderInterface;
function mymodule_commerce_order_insert(OrderInterface $order) {
$apiKey = \Drupal::config('mymodule.settings')->get('scell_api_key');
$client = new Client($apiKey);
$builder = $client->invoices()->builder()->facturX();
foreach ($order->getItems() as $item) {
$builder->addLine($item->getTitle(), (int)$item->getQuantity(), (float)$item->getTotalPrice()->getNumber(), 20.0);
}
$invoice = $builder->create();
$order->set('field_scell_invoice', $invoice->id)->save();
}