2

I'd like to email the admin when the stock is 0.
In one option, I've tried to set a condition in rules based on the stock field, but I can't get the field to display in Entity has Bundle.

Are there other options?

I am using Drupal 9.5.10, Commerce Core 8.x-2.36, and Commerce Stock 8.x-1.1.

1 Answer 1

1

By looking at the code proposed by the module commerce_stock I believe you'll have to write a new EventSubscriber that subscribe to the event onOrderComplete.

So you create the file: modules/custom/my_custom_commerce_stock/src/EventSubscriber/SendEmailWhenNoStockSubscriber.php

<?php

namespace Drupal\my_custom_commerce_stock\EventSubscriber;

class SendEmailWhenNoStockSubscriber implements EventSubscriberInterface { 

  public static function getSubscribedEvents() { 
    'commerce_order.post_transition' => 'onOrderComplete', 
  }

  public function onOrderComplete(WorkflowTransitionEvent $event) {
    // code to send email.  
  }

}

If you don't know how to send an email with Drupal, this is very well documented:

If you don't want to code, you can try the following module https://www.drupal.org/project/commerce_stock_notifications

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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