In the previous story "Drupal Commerce 2 - Create Simple Stock with Custom Module and ECA", I created simple stock using custom module together with ECA module. Later, I found that I can use just ECA to check availability of the product. It's quite easy. Here is what I do:
- Start by create an integer field name field_eca_stock in Product Variation
- Create a new ECA model as below:
- Event "Build Form" -> Restricted by entity type id "commerce_order_item"
- Condition : "Compare Two Scalar Value"
- First value : [entity:purchased_entity:entity:field_eca_stock]
- Comparation Operator : Less than
- Second value : 1
- Action : Form Field: Set as Disable
- Field name : submit
- Set as disabled : yes
That's it.
Software :
- Drupal 10.3.2
- ECA: Event - Condition – Action module 2.0.4