0

I've had a plugin working on 2.2.2 version but it's not working on 2.3.4. Its seem that collectSitemapItems() method is not firing even in native magento WHen I print_r('Die');die;

public function collectSitemapItems()
    {
        print_r('Not firing');die;
        /** @var $helper \Magento\Sitemap\Helper\Data */
    ...

But it's printing under protected method _initSitemapItems()

/**
     * Initialize sitemap
     *
     * @return void
     */
    protected function _initSitemapItems()
    {
     print_r('Working Here');die; 
    ...

My plugin have afterCollectSitemapItems() Method:

public function afterCollectSitemapItems(
        Sitemap $subject
    )
    {
        print_r('Not firing here either');die;

My Plugin di.xml:

 <type  name="Magento\Sitemap\Model\Sitemap">
   <plugin name="vendor-sitemap" sortOrder="1"  disabled="false" type="Vendor\Module\Plugin\Sitemap\Plugin"/>
 </type>

Any ideas why this isn't working anymore?

1

Try this below and add your die as well

   public function __construct(
        \Magento\Sitemap\Helper\Data $helper
        ) {
            $this->helper = $helper;
    }
    public function afterCollectSitemapItems(
        \Magento\Sitemap\Model\Sitemap $subject
        )
    {

        die('Not firing here either');
        $storeId = $subject->getStoreId();
        $newRecords = [];
        $object = new \Magento\Framework\DataObject();
        $object->setId(['test_id']);
        $object->setUrl('test-url');
        $object->setUpdatedAt('2020-04-17 14:24:38');

        $newRecords['test_id'] = $object;

        $subject->addSitemapItem(new  \Magento\Framework\DataObject(
            [

                'changefreq' => $this->helper->getPageChangefreq($storeId),
                'priority' => $this->helper->getPagePriority($storeId),
                'collection' => $newRecords,
            ]
         ));
    }

}
| improve this answer | |
  • can I see your DI.XML file – jibin george Apr 17 at 13:27
  • this is exactly what I have. it seems that CollectSitemapItems or in my plugin afterCollectSitemapItems isn't doing anything. but Ive found a way around it. – Juliano Vargas Apr 17 at 13:27
  • @JulianoVargas the issue might be where you using the di.xml. When i did it i didnt put it inside frontend or adminhtml. I kept my di.xml in etx/di.xml but if you got it working that's good news will you let me know how you fixed it just wanted to see what was the error with it – jibin george Apr 17 at 13:30
1

I've found out that my plugin is firing ok after printing in __constructor bu method afterCollectSitemapItems not any more. So using public method generateXml like so:

public function __construct(
        \Magento\Sitemap\Helper\Data $helper
        ) {
            $this->helper = $helper;
    }
    public function beforeGenerateXml(
        \Magento\Sitemap\Model\Sitemap $subject
        )
    {
        $storeId = $subject->getStoreId();
        $newRecords = [];
        $object = new \Magento\Framework\DataObject();
        $object->setId(['test_id']);
        $object->setUrl('test-url');
        $object->setUpdatedAt('2020-04-17 14:24:38');
        $newRecords['test_id'] = $object;
        $subject->addSitemapItem(new  \Magento\Framework\DataObject(
            ['changefreq' => $this->helper->getPageChangefreq($storeId),
             'priority' => $this->helper->getPagePriority($storeId),
             'collection' => $newRecords,]
         ));
    }

}

Worked, Sorted!

Note/Tip: only before method works on generateXml and also when generating always open xml in incognito mode as is caches in chrome browser.

| improve this answer | |
  • Thanks for that @Juliano – jibin george Apr 17 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.