Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Product model #21

Closed
naydav opened this issue May 19, 2017 · 0 comments
Closed

Fix Product model #21

naydav opened this issue May 19, 2017 · 0 comments
Assignees

Comments

@naydav
Copy link

naydav commented May 19, 2017

Full context in documentation

[HLD] Inconsistent saving of Stock Data

Description

1. Replace 'getExtensionAttributes' method

/**
 * {@inheritdoc}
 *
 * @return \Magento\Catalog\Api\Data\ProductExtensionInterface
 */
public function getExtensionAttributes()
{
    $extensionAttributes = $this->_getExtensionAttributes();
    if (!$extensionAttributes) {
        /** @var \Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes */
        $extensionAttributes = $this->extensionAttributesFactory->create(
            \Magento\Catalog\Api\Data\ProductInterface::class
        );
        $this->setExtensionAttributes($extensionAttributes);
    }
    return $extensionAttributes;
}

After replacing, we nave a problem: the extensionAttributes is recreated every time the method is called.

2. Fix 'toArray' and 'fromArray'

The entities:

  • \Magento\Catalog\Model\Product::toArray
  • \Magento\Catalog\Model\Product::fromArray
    must be changed to get the stock inventory data from the current StockItem.

3. Remove reindexing from 'afterSave'

Remove the following from the \Magento\Catalog\Model\Product::afterSave:

if ($this->getStockData()) {
    $this->setForceReindexEavRequired(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant