1

I had implemented a "Event Subscriber" controller to change the stock value in the product variation. Stock is a field in product variation.

Depending upon the quantity in order items I am decreasing the value of stock by subscribing to Drupal 8 event order $events['commerce_order.place.post_transition']. Similarly I increased stock value if he cancels the order using the event $events['commerce_order.cancel.post_transition'].

If somebody revise the order quantity from Back-office that time, stock should be increased or decreased accordingly. How can we achieve that? Is there any event when order items is edited? we are currently decreasing stock when order is placed... how can we decrease/increase when somebody edit the order from backend manually?

1

Is there any event when order items is edited?

You could use hook_ENTITY_TYPE_update

/*
 * Implements hook_ENTITY_TYPE_update()
 */
function mymodule_order_update(\Drupal\commerce_order\Entity\OrderInterface $order) {
  // your code goes here
}

If you don't want to use a hook, then consider using the Hook Event Dispatcher module.

This module dispatches events for several Drupal core hooks. This allows you to use the D8 Event Subscriber system, instead of the outdated hook system, to react on certain events. The module includes events for the most common hooks.

2
  • Thanks for the comment. I will try this, I had never used hook. I am new to drupal.
    – Rifas Ali
    Dec 28 '18 at 10:51
  • @RifasAli this hook gets placed inside your mymodule.module file and replace mymodule with your actual module name of course.
    – No Sssweat
    Dec 28 '18 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.