I am doing an offsite redirection payment with drupal commerce.
I have a custom payment workflow defined in my_module.workflow.yml
as follows:
order_linktypeplus_validation:
id: order_linktypeplus_validation
group: commerce_order
label: 'linktypeplus order workflow'
states:
draft:
label: Draft
pending:
label: Pending
completed:
label: Completed
canceled:
label: Canceled
transitions:
place:
label: 'Place order'
from: [draft]
to: pending
fulfill:
label: 'Fulfill order'
from: [draft, pending]
to: completed
cancel:
label: 'Cancel order'
from: [draft, pending]
to: canceled
My usecase is that for some order (eg: storefront orders) i don't the order need to be completed immediately. But put the order in Pending
state and later on it can complete. But for some orders it needs to be completed immediately.
So as per this, when the order is get placed first order will be moved to Pending
state (which is fine).
And for some orders i need to get it completed without the pending state (ie. from draft to completed
)
I was doing this in my controller after offsite payment has been successfully returned,
$order->unlock();
$order->getState()->applyTransitionById('fulfill');
$order->save();
It was not placing the order (But still in cart).
But there is a catch.. I can make the order to appear in orders by doing
$order->getState()->applyTransitionById('fulfill');
$order->setPlacedTime(\Drupal::time()->getCurrentTime());
$order->setOrderNumber($order_id);
$order->set('cart', 0);
$order->save();
I know its not the correct way. So my question is, is there anyway to make the order when we do a custom workflow transition?
When i checked in the cart, the item is still in cart. and it says`Order moved from Draft to Completed by the Fulfillorder transition`.