- Issue created by @ekes
- Status changed to Fixed
about 1 year ago 2:10pm 19 September 2023 - πΊπΈUnited States goose2000
I created an event subscriber for when a Drupal Commerce order has been moved to a 'complete' state. I thinking I could then use this module to invoke an enrollment at that time. I.E. purchase a moodle course.
namespace Drupal\moodle_rest_enroll\EventSubscriber; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\state_machine\Event\WorkflowTransitionEvent; use Drupal\Core\Entity\EntityTypeManager; /** * Class OrderCompleteSubscriber. * * @package Drupal\moodle_rest_enroll */ class OrderCompleteSubscriber implements EventSubscriberInterface { /** * Drupal\Core\Entity\EntityTypeManager definition. * * @var \Drupal\Core\Entity\EntityTypeManager */ protected $entityTypeManager; /** * Constructor. */ public function __construct(EntityTypeManager $entity_type_manager) { $this->entityTypeManager = $entity_type_manager; } /** * {@inheritdoc} */ static function getSubscribedEvents() { $events['commerce_order.place.post_transition'] = ['orderCompleteHandler']; return $events; } /** * This method is called whenever the commerce_order.place.post_transition event is * dispatched. * * @param WorkflowTransitionEvent $event */ public function orderCompleteHandler(WorkflowTransitionEvent $event) { /** @var \Drupal\commerce_order\Entity\OrderInterface $order */ $order = $event->getEntity(); // Order items in the cart. $items = $order->getItems(); \Drupal::logger('moodle_rest_enroll')->notice("Subscricer for orderCompleteHandler WORKED!", []); // Write your custom logic here. Enrol a user into a Moodle course here... } }
Automatically closed - issue fixed for 2 weeks with no activity.