Consider refactoring the stock level field to allow for initializing the stock level before a product variation is saved

Created on 3 March 2018, almost 7 years ago
Updated 12 January 2024, about 1 year ago

When I create new product, Simple Stock widget is empty. I found the following code in field widget:

    if ($entity->isNew()) {
      // We can not work with entities before they are fully created.
      return [];
    }

It is not good idea to hide this widget on new entities, because it forces content manager to edit products immediately after its creation.

That is because, the stock field is a computed field as it does not hold a stock value and creates transactions that are used to calculate the available stock. The stock level field needs an entity id to create the transactions records against.

A possible solution is outlined in the comments below. We could store the value of the initial stock in database and create the very first transaction in StockLevel::postSave()

We won't use the database entries after the initial transaction. Maybe it's an acceptable price to pay.

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇧🇾Belarus gun_dose

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024