Skip to content

Conversation

@woutersamaey
Copy link
Contributor

The flag is set incorrectly, because some product data was added to the stock item, making Magento believe there was an actual change, when in fact there wasn't. This is the best way to reset this.

… a product.

The flag is set incorrectly, because some product data was added to the stock item, making Magento believe there was an actual change, when in fact there wasn't. This is the best way to reset this.
@woutersamaey
Copy link
Contributor Author

Keeping the "_hasDataChanges" clean leads to greater performance because no save will happen if there aren't any real changes. Not exactly the same, but there's also some discussion in #1306

@github-actions github-actions bot added the Component: CatalogInventory Relates to Mage_CatalogInventory label Nov 13, 2020
@kiatng
Copy link
Contributor

kiatng commented Nov 15, 2020

May be a better fix on skipping model save is to add this method:

// In app\code\core\Mage\CatalogInventory\Model\Stock\Item.php
    /**
     * Checks that stock item model has data changes.
     * Call save stock item if model need to save in DB
     *
     * @return boolean
     */
    protected function _hasModelChanged()
    {
        if (!$this->hasDataChanges()) {
            return false;
        }

        return $this->_getResource()->hasDataChanged($this);
    }

@colinmollenhour
Copy link
Member

@woutersamaey Sorry, I should have looked at this long ago.. I approve of this change but while I was applying some other changes for #1306 I went ahead and implemented an alternative solution that is perhaps a bit more "kosher" in #2066. (adds a proper protected property to reference the stockItem instead of using _data).

Copy link
Member

@colinmollenhour colinmollenhour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve, but if #2066 is merged this does not need to also be merged.

@fballiano
Copy link
Contributor

I think #2066 would be a more comprensive solution :-)

@fballiano
Copy link
Contributor

Since #2066 is already merged we don't need this one.

@fballiano fballiano closed this Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: CatalogInventory Relates to Mage_CatalogInventory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants