class OrderPlacedSubscriber in Commerce Invoice 8.2
Hierarchy
- class \Drupal\commerce_invoice\EventSubscriber\OrderPlacedSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of OrderPlacedSubscriber
1 string reference to 'OrderPlacedSubscriber'
1 service uses OrderPlacedSubscriber
File
- src/
EventSubscriber/ OrderPlacedSubscriber.php, line 10
Namespace
Drupal\commerce_invoice\EventSubscriberView source
class OrderPlacedSubscriber implements EventSubscriberInterface {
/**
* The invoice generator.
*
* @var \Drupal\commerce_invoice\InvoiceGeneratorInterface
*/
protected $invoiceGenerator;
/**
* Constructs a new OrderPlacedSubscriber object.
*
* @param \Drupal\commerce_invoice\InvoiceGeneratorInterface $invoice_generator
* The invoice generator.
*/
public function __construct(InvoiceGeneratorInterface $invoice_generator) {
$this->invoiceGenerator = $invoice_generator;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = [
'commerce_order.place.post_transition' => [
'onPlace',
],
];
return $events;
}
/**
* Generates an invoice when an order is placed if configured to do so.
*
* @param \Drupal\state_machine\Event\WorkflowTransitionEvent $event
* The event we subscribed to.
*/
public function onPlace(WorkflowTransitionEvent $event) {
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $event
->getEntity();
/** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
$order_type = OrderType::load($order
->bundle());
$invoice_settings = $order_type
->getThirdPartySettings('commerce_invoice');
// Check if invoices should be generated automatically when an order
// is placed for this order type.
if (empty($invoice_settings['invoice_type']) || empty($invoice_settings['order_placed_generation'])) {
return;
}
$values = [
'uid' => $order
->getCustomerId(),
'type' => $invoice_settings['invoice_type'],
];
$this->invoiceGenerator
->generate([
$order,
], $order
->getStore(), $order
->getBillingProfile(), $values);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OrderPlacedSubscriber:: |
protected | property | The invoice generator. | |
OrderPlacedSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
OrderPlacedSubscriber:: |
public | function | Generates an invoice when an order is placed if configured to do so. | |
OrderPlacedSubscriber:: |
public | function | Constructs a new OrderPlacedSubscriber object. |