About 2 years ago, I tried Drupal Commerce 2 and the module itself doesn't have comment system that a shop owner can use to make a note to let customer know and customer can also check that note in order information page. Shop owner can decided to send notification to customer though an Email, if needed. At that time, I decided to use Drupal Core Comment together with Rules module to create a comment form and use to communicate with customers. Until now, Drupal Commerce 2 still doesn't have this feature built-in but well, at least I can make it work using Drupal Core and no programming at all which should be good enough.
After waited several years for Drupal Commerce 2 to have a few features I need which should be comparable to my old Drupal 6 + Ubercart 2.x website, I think I should try it again. This time, with ECA: Event - Condition – Action module, a lot of things can be done without programming. (ECA module is similar to Rules module but can do a lot more.)
To be able to migrate data from my old Drupal 6 + Ubercart 2.x, I decided to use Commerce Feeds module. What I need is only product data. I can feeds import everything like Product Images, Price, Weight, Meta Tags but the only data I need and can't import is stock value in Drupal Commerce Stock. Since Drupal Commerce Stock uses transaction, Feeds import is not support.
Then, I found a good article Out of Stock feature in Drupal Commerce 2.x to create a custom module to check for out of stock item. This is only need so that the Add to cart button change to Out of stock when stock is 0 or less.
UPDATE 2024.09.03 : in case you don't want to use custom module, you can just use ECA to do Out of stock check. Here is how to do it -> Drupal Commerce 2 - Create Simple Stock with ECA (Part 2)
Here is what I do:
- Start by create an integer field name field_eca_stock in Product Variation
Create a module from here. in VariationAvailabilityChecker.php , Change this line:
if ($entity->field_stock->value <= 0) {
to
if ($entity->field_eca_stock->value <= 0) {
- Create a View in Views for ECA to retrieve Order item list with Contextual filters "Order item: Order"
- Use ECA to adjust stock value. So, I create 3 ECA models below:
- ECA - Stock - Adjust Stock when Insert, Update, Delete Items in Admin Order page.
- ECA - Stock - Adjust Stock when customer complete an order.
- ECA - Stock - Prevent customer to order if stock is not enough.
I don't know if the performance will be a problem with my solution or not, I will have to try it someday soon after I find all solutions I need. Also, please note that I'm not a programmer, I understand that a lot of things can be done easily if you know how to program. I, myself, can only read some code but can't create it especially with PHP OOP. So, anything with GUI is the best solution for me.
ECA Process :
Views - Contextual Filter :
Software :
- Drupal 9.5.9
- ECA: Event - Condition – Action module 1.1.3
Source:
Attachment | Size |
---|---|
2023-06-23-ECA-Stock-Insert-Update-Delete (5 KB) | 5 KB |
2023-06-23-ECA-Stock-Prevent-Order-Overstock (6.36 KB) | 6.36 KB |
2023-06-23-ECA-Stock-Completed-Order (6.19 KB) | 6.19 KB |
Commerce Stock Check Module From https://gorannikolovski.com/blog/out-stock-feature-drupal-commerce-2x (5.54 KB) | 5.54 KB |