magento-2-blog
magento-2-blog copied to clipboard
Sitemap generation fails because of missing image info
Preconditions (*)
- Magento 2.4.1
- PHP 7.3
Steps to reproduce (*)
- Create blog posts with image(s)
- Generate sitemap
Expected result (*)
- Sitemap gets generated with all products, categories and blog posts
Actual result (*)
- Generation fails with error "TypeError: Argument 1 passed to Magento\Sitemap\Model\Sitemap::escapeXmlText() must be of the type string, null given, called in /vendor/magento/module-sitemap/Model/Sitemap.php on line 576 and defined in /vendor/magento/module-sitemap/Model/Sitemap.php:598"
In magento's function _getSitemapRow (\vendor\magento\module-sitemap\Model\Sitemap.php) the $images object is supposed to contain a title which is passed to escapeXmlText().
I created a dump on each item to see what's wrong. This is an image (data object) of a product:
Array
(
[collection] => Array
(
[0] => Magento\Framework\DataObject Object
(
[_data:protected] => Array
(
[url] => https://www.example.com/media/catalog/product/cache/4014ca3c284ee8bfa0947c8aaa649e60/t/e/test.jpg
[caption] =>
)
)
)
[title] => My awesome product
[thumbnail] => https://www.example.com/media/catalog/product/cache/4014ca3c284ee8bfa0947c8aaa649e60/t/e/test.jpg
)
This is an image of a blog post:
Array
(
[collection] => Array
(
[0] => Magento\Framework\DataObject Object
(
[_data:protected] => Array
(
[url] => https://www.example.com/media/mageplaza/blog/post/t/e/test.jpg
[caption] =>
)
)
)
)
It is missing the title property which results in $images->getTitle() to return NULL instead of a string. escapeXmlText expects a string, which is why it fails.
Hi @OvalMedia , Please download this file and replace it with the path: app/code/Mageplaza/Blog/Model/Sitemap.php Sitemap.zip
I'd rather have this fixed in the repo since it is managed via composer inside the vendor folder.
Hi, So you just need replace it with the path: vendor/mageplaza/Blog/Model/Sitemap.php
I understand. But I manage the code with composer. Another "composer update" and the replacement is gone.
Does not work for me - any update?
Hi, You can update the file using Magento 2 patches technique
Please follow these steps.
https://www.classyllama.com/blog/create-apply-patches-magento-2
This is months old. Why can't you just fix it and push it into the repo?
@OvalMedia ,
I'm also facing the same issue but that file did not work for me, I just suggest a technique to modify the vendor file using patches.
If you have found out a solution can you please share here?
I gave up with th Mageplaza on this isuue, they had fixed it for me before, but lose the fix every time i upgrade
I fixed using their own sitemap module https://www.mageplaza.com/magento-2-google-sitemap/
Seems to generate OK now
Why is there even a DI preference in the first place? This is an overwrite of the sitemap. Instead there should be a decent solution by adding an ItemProvider.
Anyway, I created a PR that works for me.
when I generate a site map via marketing/seo&search/site map/generate, I also get this error. Magento version: V2.4.2-p1 blog version: 4.1.0 so, please kindly advise how to fix this?
This is exact same error is happening to us after we updated to Magento 2.4.2pt-1. Mageplaza_Blog latest version 4.1.1.
ERRROR:
Cron Job sitemap_generate has an error: Argument 1 passed to Magento\Sitemap\Model\Sitemap::escapeXmlText() must be of the type string, null given, called in /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/module-sitemap/Model/Sitemap.php on line 582. Statistics: {"sum":0,"count":1,"realmem":0,"emalloc":0,"realmem_start":347078656,"emalloc_start":339914360}
After disabling blog we are able to generate sitemap, however, on live site we are not wanting to disable mageplaza blog and we are hoping for a quick solution. We tried the file from @phutx, however, that did not work.
Today I will submit a support ticket to mageplaza and maybe even try there sitemap extension.
Looking at the exception log here is the full stack trace for this error.
TypeError: Argument 1 passed to Magento\Sitemap\Model\Sitemap::escapeXmlText() must be of the type string, null given, called in /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/module-sitemap/Model/Sitemap.php on line 582 and defined in /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/module-sitemap/Model/Sitemap.php:604 Stack trace: #0 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/module-sitemap/Model/Sitemap.php(582): Magento\Sitemap\Model\Sitemap->escapeXmlText(NULL) #1 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/module-sitemap/Model/Sitemap.php(466): Magento\Sitemap\Model\Sitemap->_getSitemapRow('https://upperli...', '2020-11-25 07:1...', NULL, NULL, Object(Magento\Framework\DataObject)) #2 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/module-sitemap/Controller/Adminhtml/Sitemap/Generate.php(58): Magento\Sitemap\Model\Sitemap->generateXml() #3 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate->execute() #4 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->___callParent('execute', Array) #5 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/App/Action/Plugin/ActionFlagNoDispatchPlugin.php(51): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->Magento\Framework\Interception\{closure}() #6 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Framework\App\Action\Plugin\ActionFlagNoDispatchPlugin->aroundExecute(Object(Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor), Object(Closure)) #7 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->Magento\Framework\Interception\{closure}() #8 /var/www/vhosts/upperlimitsinc.com/httpdocs/generated/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate/Interceptor.php(23): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->___callPlugins('execute', Array, Array) #9 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/App/Action/Action.php(111): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->execute() #10 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/module-backend/App/AbstractAction.php(151): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http)) #11 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http)) #12 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->___callParent('dispatch', Array) #13 /var/www/vhosts/upperlimitsinc.com/httpdocs/app/code/WeltPixel/Backend/Plugin/Utility.php(76): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http)) #14 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(135): WeltPixel\Backend\Plugin\Utility->aroundDispatch(Object(Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http)) #15 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(143): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http)) #16 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http)) #17 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http)) #18 /var/www/vhosts/upperlimitsinc.com/httpdocs/generated/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate/Interceptor.php(32): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->___callPlugins('dispatch', Array, NULL) #19 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/App/FrontController.php(186): Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http)) #20 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/App/FrontController.php(118): Magento\Framework\App\FrontController->processRequest(Object(Magento\Framework\App\Request\Http), Object(Magento\Sitemap\Controller\Adminhtml\Sitemap\Generate\Interceptor)) #21 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http)) #22 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array) #23 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http)) #24 /var/www/vhosts/upperlimitsinc.com/httpdocs/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array) #25 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http)) #26 /var/www/vhosts/upperlimitsinc.com/httpdocs/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch() #27 /var/www/vhosts/upperlimitsinc.com/httpdocs/vendor/magento/framework/App/Bootstrap.php(263): Magento\Framework\App\Http\Interceptor->launch() #28 /var/www/vhosts/upperlimitsinc.com/httpdocs/pub/index.php(29): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor)) #29 {main}
@JonathanHelvey
I have fixed the sitemap manually after I get the error.
- go to the path of generated sitemap
- edit your_sitemap.xml
- add
</urlset>
in a new line at the end of the sitemap.xml - save your_sitemap.xml
- visit yourdomain.com/your_sitemap.xml to check it.
I fixed it in file app/code/Mageplaza/Blog/Model/Sitemap.php Line: 87 $images = new DataObject(['collection' => $imagesCollection]); Replaced $images = new DataObject(['collection' => $imagesCollection, 'title' => $item->getData('name')]);
@Henry17888 I opened up a support ticket with mageplaza and they gave me the correct vendor/mageplaza/magento-2-blog-extension/Model/Sitemap.php file and now everything is working.
Hi, I'm Shox from Mageplaza. We have now found a solution to this problem and it will be applied to future versions of the Blog module. So please wait until the new version of the Blog module is released. Thank you very much for your contributions.
This error is resolved with version 4.1.3