Commit 219e06b2 authored by Robert Kasza's avatar Robert Kasza Committed by Róbert Kasza
Browse files

Issue #3003349 by kaszarobert, mirom: Add submodule with example implementation

parent e5feb52d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -52,7 +52,9 @@ SuperFaktura account) and other invoice details on page
/admin/commerce/config/superfaktura
```

Next step is to create own module with subscriber to call SuperFaktura service.
Next step is to set when should the invoice creating service run. If you want to send invoices just when the order was placed, then enable the **superfaktura_invoice_place** submodule.

Otherwise create an own module with subscriber to call SuperFaktura service.
In example below SuperFaktura service is called when Order is placed.

```
+36 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\superfaktura_invoice_place\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\state_machine\Event\WorkflowTransitionEvent;

/**
 * Superfaktura event subscriber.
 */
class SuperfakturaSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      'commerce_order.place.pre_transition' => ['createInvoice', -200],
    ];
  }

  /**
   * Create Invoice in Superfaktura from created order.
   *
   * @param \Drupal\state_machine\Event\WorkflowTransitionEvent $event
   *   Transition Event.
   */
  public function createInvoice(WorkflowTransitionEvent $event) {
    /** @var \Drupal\commerce_order\Entity\Order $order */
    $order = $event->getEntity();
    /** @var \Drupal\superfaktura\InvoiceService $invoice */
    $invoice = \Drupal::service('superfaktura.invoice_service');
    $invoice->createInvoice($order);
  }

}
+7 −0
Original line number Diff line number Diff line
name: Superfaktura Invoice Place Example Integration
type: module
description: Sample integration module that creates a Superfaktura invoice when an order is placed.
package: Commerce
core_version_requirement: ^8 || ^9
dependencies:
  - state_machine:state_machine
+5 −0
Original line number Diff line number Diff line
services:
  superfaktura_invoice_place.event_subscriber:
    class: Drupal\superfaktura_invoice_place\EventSubscriber\SuperfakturaSubscriber
    tags:
      - { name: event_subscriber }