Score:1

How can Drupal Commerce Stock email admin when stock is 0?

cn flag

Drupal: 9.5.10 Commerce: 8.x-2.36 Commerce Stock: 8.x-1.1

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" Other options?

Score:1
in flag

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

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.