class OrderSubscriber in Drupal Commerce Connector for AvaTax 8
Hierarchy
- class \Drupal\commerce_avatax\EventSubscriber\OrderSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of OrderSubscriber
1 string reference to 'OrderSubscriber'
1 service uses OrderSubscriber
File
- src/
EventSubscriber/ OrderSubscriber.php, line 14
Namespace
Drupal\commerce_avatax\EventSubscriberView source
class OrderSubscriber implements EventSubscriberInterface {
/**
* The AvaTax library.
*
* @var \Drupal\commerce_avatax\AvataxLibInterface
*/
protected $avataxLib;
/**
* The AvaTax configuration.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* Constructs a new CommitTransactionSubscriber object.
*
* @param \Drupal\commerce_avatax\AvataxLibInterface $avatax_lib
* The AvaTax library.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
*/
public function __construct(AvataxLibInterface $avatax_lib, ConfigFactoryInterface $config_factory) {
$this->avataxLib = $avatax_lib;
$this->config = $config_factory
->get('commerce_avatax.settings');
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = [
'commerce_order.place.post_transition' => [
'commitTransaction',
],
'commerce_order.cancel.pre_transition' => [
'onOrderCancel',
],
OrderEvents::ORDER_DELETE => [
'onOrderDelete',
],
];
return $events;
}
/**
* Commits a transaction or the order in AvaTax.
*
* @param \Drupal\state_machine\Event\WorkflowTransitionEvent $event
* The workflow transition event.
*/
public function commitTransaction(WorkflowTransitionEvent $event) {
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $event
->getEntity();
if ($this->config
->get('disable_commit') || !Avatax::hasAvataxAdjustments($order)) {
return;
}
$this->avataxLib
->transactionsCreate($order, 'SalesInvoice');
}
/**
* Voids the AvaTax transaction on order cancellation.
*
* @param \Drupal\state_machine\Event\WorkflowTransitionEvent $event
* The workflow transition event.
*/
public function onOrderCancel(WorkflowTransitionEvent $event) {
$this
->voidTransaction($event
->getEntity());
}
/**
* Voids the AvaTax transaction on order deletion.
*
* @param \Drupal\commerce_order\Event\OrderEvent $event
* The order event.
*/
public function onOrderDelete(OrderEvent $event) {
$this
->voidTransaction($event
->getOrder());
}
/**
* Voids a transaction in AvaTax for the given order.
*
* @param \Drupal\commerce_order\Entity\OrderInterface $order
* The order.
*/
protected function voidTransaction(OrderInterface $order) {
if (!Avatax::hasAvataxAdjustments($order)) {
return;
}
$this->avataxLib
->transactionsVoid($order);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OrderSubscriber:: |
protected | property | The AvaTax library. | |
OrderSubscriber:: |
protected | property | The AvaTax configuration. | |
OrderSubscriber:: |
public | function | Commits a transaction or the order in AvaTax. | |
OrderSubscriber:: |
public static | function | ||
OrderSubscriber:: |
public | function | Voids the AvaTax transaction on order cancellation. | |
OrderSubscriber:: |
public | function | Voids the AvaTax transaction on order deletion. | |
OrderSubscriber:: |
protected | function | Voids a transaction in AvaTax for the given order. | |
OrderSubscriber:: |
public | function | Constructs a new CommitTransactionSubscriber object. |