magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.54k stars 9.32k forks source link

Products updated_at field is not updating on save #6683

Closed mgsolutionscode closed 7 years ago

mgsolutionscode commented 8 years ago

Preconditions

  1. Magento 2.1.1, 2.1.0 - fresh install (no sample data)
  2. Not checked in previous versions 2.0.x
  3. PHP 5.6.25
  4. MySQL 5.6.28
  5. Product types: all

    Steps to reproduce

  6. Go to admin panel
  7. Create new product (fill all required data, category, related, upsell etc is not improtant)
  8. In catalog_product_entity table check updated_at value (it is same like created_at)
  9. Than go to edit same product
  10. Update any product's value like: category, description, short_description. Do not update SKU (basically do not update any field from catalog_product_entity table)
  11. Save the product
  12. Check updated_at value -> value is not changed

    Expected result

  13. After updating any products data updated_at column in catalog_product_entity should be updated. Not just when SKU is changed.

    Actual result

  14. updated_at column in catalog_product_entity table keep same value from moment when product is created.

    Problem Analyzes

Analyzing catalog_product_entity table it is clear that Default value for that field is CURRENT_TIMESTAMP and Extra is "on update CURRENT_TIMESTAMP".

I have debugging the issue and found source of the problem. When product is saved and if product is not new this class is responsible for updating data in entity table \Magento\Framework\EntityManager\Db\UpdateRow (vendor/magento/framework/EntityManager/Db/UpdateRow.php)

Method "execute" is receiving all product's data in $data variable including new correct value for updated_at field. On line 81 method prepareData return only fields which can be stored in catalog_product_entity table. But in the list of values updated_at is missing.

Now if we look inside prepareData method in the same class, on line 53 all columns which have CURRENT_TIMESTAMP for default values are ignored. And that is the source of problem.

Even if updated_at column has "on update CURRENT_TIMESTAMP" definition it will not update value automatically if values of columns in catalog_product_entity are not changed.

For example there is a product with SKU "testsku" in this case:

UPDATE catalog_product_entity SET sku = 'testsku' WHERE entity_id = 1;

updated_at field will not be updated and will not get new value. However, when product is saved it can get new Name or Description but updated_at info will not be changed.

However if query set new value for SKU field MySQL automatically will set CURRENT_TIMESTAMP to updated_at field. So this query will work:

UPDATE catalog_product_entity SET sku = 'newsku' WHERE entity_id = 1;

Conclusion is that fields which has DEFAULT value CURRENT_TIMESTAMP and "on update CURRENT_TIMESTAMP" definition should not be removed from $data array before save because values will not be updated. In this case it is clear that updated_at value will be changed only if value of any column is changed only in catalog_product_entity table but product entity contain multiple attribute values and updated_at need to be changed when any attribute value for product is changed on save.

Updated at value is important for example in case that we want to check if product is updated and for example pull new data to third party application or something.

Please let me know if you have any questions.

Thanks Milos

veloraven commented 8 years ago

@miskec thank you for your feedback. Please format your issue description according to the Issue reporting guidelines.

mgsolutionscode commented 8 years ago

@veloraven I have updated the issue description. I hope that is better now.

Regards

SantoDE commented 8 years ago

I just encountered that bug as well. Is there any ETA for a fix?

pboisvert commented 8 years ago

no ETA yet as the bug has not been confirmed. The original reporter has been asked for information to help us reproduce. Then we need to do that and if an issue then schedule a fix.

SantoDE commented 8 years ago

@pboisvert what else do you need? His report looks quite helpfull :)

mglavinic commented 8 years ago

@pboisvert it is very easy to reproduce the error. Just follow the steps from which I wrote in bug report. If I can help you somehow let me know.

pboisvert commented 8 years ago

I will let @veloraven answer that question. I just saw the "needs update" label which we use when more info is needed. I also see that the report has been edited so perhaps the missing info has been filled in now that was missing when the needs update tag was added. Looks complete to me now.

dthampy commented 8 years ago

Thank you for your bug report - internal jira ticket MAGETWO-60169 is created to track this issue.

tanghia commented 7 years ago

My shop has encountered same problem. After updating magento from 2.0 to 2.1, some old products can't update updated_at field.

bnayalivne commented 7 years ago

Same here, magento 2.1.0 not updating the "updated_at" field for products, except when the SKU changed.

robbanl commented 7 years ago

Same here, Magento 2.1.4... Even tried setting the updated_at field manually without any success. (DateTime, string, null, false, empty string)

brian4-tell commented 7 years ago

We also would like to see this fixed.

robbanl commented 7 years ago

Since my project depends on the updated_at field I created a simple module to solve this without hacking core. I know it's not a very neet fix, but it does it job. I've tried saving product using model in custom script and also in admin. And it works for me on Magento 2.1.4.

Created a module if anyone else was in need of the same functionality:

https://github.com/codepeak/magento2-productfix

titus213 commented 7 years ago

This is becoming a big problem with my store. Any idea when this is going to be fixed?

develpr commented 7 years ago

I'd also really like to know what the status / future is of this issue, or have some sort of patch provided. Also does anybody happen to know if a product going out of stock would generally update this timestamp? I'm sure that quantity updates would NOT cause an update, but stock status change would perhaps?

Datalink-Wouter commented 7 years ago

Any update on this? We're having the same issue with Magento 2.1.0

mrkhoa99 commented 7 years ago

AFAIK, the updated_at will update if the data of catalog_product_entity has changed. For example, the change the sku, product options. We can temporarily use Plugin or Observer to update this table.

i95devdivya commented 7 years ago

Now patch is available from Magento for this issue MDVA-3075_EE_2.1.3_v1_composer.patch 2/16/2017 2:47 PM

Datalink-Wouter commented 7 years ago

Is this only available for EE? Not for CE?

Ash-Radwan commented 7 years ago

Any update on when a patch for CE will be available?

Datalink-Wouter commented 7 years ago

@Ash-Radwan I used the module that robbanl created: https://github.com/codepeak/magento2-productfix You can always give it a try. Works great for me with Magento 2.1.4

veloraven commented 7 years ago

I'm closing this issue as a duplicate of #5385. It was already fixed for develop. Internal ticket for ver. 2.1 - MAGETWO-58514

careys7 commented 7 years ago

@veloraven I think #5385 is a different issue.

Repeating the original steps to reproduce on latest develop still gives us the "Actual Result" described here: https://github.com/magento/magento2/issues/6683#issue-178195771

Can you please re-open this issue?

This is causing us to lose a lot of admin edits when integrating the Magento catalog with third party systems (using updated_at to retrieve product changes and merge this with those from other sources).

Pankaj08 commented 6 years ago

@robbanl your code is working fine for the products. Can you help me with categories?