Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- order_fulfillment:
- id: order_fulfillment
- group: commerce_order
- label: 'Fulfillment'
- states:
- draft:
- label: Draft
- awaitingpayment:
- label: Pay Later (Furikomi)
- fulfillment:
- label: Fulfillment
- completed:
- label: Completed
- canceled:
- label: Canceled
- transitions:
- place:
- label: 'Place order'
- from: [draft, awaitingpayment]
- to: fulfillment
- paylater:
- label: 'Pay later'
- from: [draft]
- to: awaitingpayment
- fulfill:
- label: 'Fulfill order'
- from: [fulfillment]
- to: completed
- cancel:
- label: 'Cancel order'
- from: [draft, fulfillment]
- to: canceled
- public function onPlaceTransition(WorkflowTransitionEvent $event) {
- $order = $event->getEntity();
- $order_type = $order->bundle();
- $payment_method = NULL;
- $payment_gateway = NULL;
- if (!$order->get('payment_method')->isEmpty()) {
- $payment_method = $order->get('payment_method')->first()->entity->id();
- }
- if (!$order->get('payment_gateway')->isEmpty()) {
- $payment_gateway = $order->get('payment_gateway')->first()->entity->label();
- }
- if ($order_type === 'ABC') {
- // https://drupal.stackexchange.com/a/186333/5147
- if ($payment_gateway === "Pay Later") {
- // https://drupal.stackexchange.com/a/252624/5147
- // Set order status to "payment pending"
- $order_state = $order->getState();
- // Get the allowed transitions for the current state.
- $transitions = $order_state->getTransitions();
- $order_state->applyTransition($transitions['paylater']);
- $order->save();
Add Comment
Please, Sign In to add comment