Skip to content

Resolve problem with origin data #22

@naydav

Description

@naydav

Full context in documentation

[HLD] Inconsistent saving of Stock Data

Description

We have the following situation in _\Magento\Catalog\Model\Product.php#L2298

/**
 * Check whether stock status changed
 *
 * @return bool
 */
private function isStockStatusChanged()
{
    $stockItem = null;
    $extendedAttributes = $this->getExtensionAttributes();
    if ($extendedAttributes !== null) {
        $stockItem = $extendedAttributes->getStockItem();
    }
    $stockData = $this->getStockData();
    return (
        (is_array($stockData))
        && array_key_exists('is_in_stock', $stockData)
        && (null !== $stockItem)
        && ($stockItem->getIsInStock() != $stockData['is_in_stock'])
    );
}

We need to DELETE or REFACT this code.
So, we need to check the origin of the Stock Status value. We can solve in several ways:

  1. [Recommended] Create a mechanism for tracking the origin entity data, based on EntityStateInterface. For this, a separate HLD is required.
  2. Use origin data from StockItem like as $stockItem->getOriginData('status')
  3. Create a simple model like this:
class ProductOriginStockStatusChecker
{
    public function getValue()
    {
        // resolving from origin data or direct call to db or 
    } 
}
  1. Using of private property in Product model for storing stock status data.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions