Closed
Description
Preconditions
- Magento CE 2.1.5
Steps to reproduce
- Have a category in the database where the
created_at
timestamp is a valid date, and theupdated_at
timestamp is0000-00-00 00:00:00
I don't think you can manage this by manually creating a category in the backend of Magento, but we managed to have some categories like this by importing them using a custom PHP script. - Generate a sitemap.xml file
- Look at the generated sitemap.xml file for that category.
Expected result
- The
lastmod
value in the xml should contain thecreated_at
timestamp
Actual result
- The
lastmod
value in the xml looks like this:
<lastmod>-001-11-30T00:00:00+00:00</lastmod>
The negative value is most likely caused by our timezone setting: Europe/Brussels
.
Possible solution
diff --git a/app/code/Magento/Sitemap/Model/Sitemap.php b/app/code/Magento/Sitemap/Model/Sitemap.php
index 3b6f646f9a5..434393ae63a 100644
--- a/app/code/Magento/Sitemap/Model/Sitemap.php
+++ b/app/code/Magento/Sitemap/Model/Sitemap.php
@@ -341,9 +341,10 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel
$changefreq = $sitemapItem->getChangefreq();
$priority = $sitemapItem->getPriority();
foreach ($sitemapItem->getCollection() as $item) {
+ $lastmod = $item->getUpdatedAt() === '0000-00-00 00:00:00' ? $item->getCreatedAt() : $item->getUpdatedAt();
$xml = $this->_getSitemapRow(
$item->getUrl(),
- $item->getUpdatedAt(),
+ $lastmod,
$changefreq,
$priority,
$item->getImages()
Discussion
I'm not sure if this is an actual bug in Magento, due to the fact that we inserted some data in the database in a possibly incorrect way.
Also: what should happen when the created_at
timestamp contains '0000-00-00 00:00:00'? In that case the lastmod
field shouldn't appear I assume, since it is optional: https://www.sitemaps.org/protocol.html#xmlTagDefinitions
If somebody could let me know what the best solution would be in this case, I can create a pull request for this.
If it is decided that this isn't an actual bug, then we should fix our custom import code I guess.
Please let me know, thanks! :)
Metadata
Metadata
Assignees
Labels
The issue has been fixed in 2.2 release lineThe issue has been fixed in 2.3 release lineGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.2 release