I have one 'select' field in product page it has value 'Open', 'Closed'.I want to changed to 'Closed' after completing the first order of this product.
There is one issue which someone answered for Drupal 7 and it is done by using 'Rules' module. How I can change the value of a commerce product field after Completion process?
How I can do that using Hooks and without Rules module?
EDIT: I feel we can use below hooks. But how we can find the product and change the custom field value of the product?
function hook_commerce_checkout_complete($order) {
if($order->status == 'completed') {
}
}
hook_commerce_checkout_complete
EDIT 2:
Got the solution for Order Complete event - https://medium.com/@sumanthkumarc/writing-event-subscriber-for-order-complete-event-in-drupal-8-commerce-2-x-196292330b1c. Now question is How I can modify the product custom field value?
public function orderCompleteHandler(WorkflowTransitionEvent $event) {
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $event->getEntity();
$items = $order->getItems();
}
How can i get the product id from the order items and change the custom field(field_prodstat
) value