2

Is there a way to override model class with custom model class only when going to custom url? Example:When going to

http://example.com/admin/adminhtml/sitemap/index/key/aa6f86507bb01ef052dc1baf515d87ca9a3b3098f6d2aa474c4b1e080b3d0775/

uses core model on generation. Now I want when going to my custom route

http://example.com/admin/customproduct/sitemap/index/key/aa6f86507bb01ef052dc1baf515d87ca9a3b3098f6d2aa474c4b1e080b3d0775/

rewrite core model with di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sitemap\Model\Sitemap" type="Product\Sitemap\Model\Sitemap"/>
</config>
1

Assuming that you would be injecting your class , Product\Sitemap\Model\Sitemap, to your Custom Controller's __construct method,

I would suggest, just extend your Custom Sitemap class to the Core Sitemap class.

Assuming that you have a function or method which you wanted to customize from the 'Core' Sitemap, declare the method in your custom sitemap, make the necessary customization and return the required response.

Let me know how it goes.

0

When extending Adminhtml controller generate action class execute method, change model load to your desired model. In my case it was:

$sitemap = $this->_objectManager->create(\Product\Sitemap\Model\Sitemap::class);
    /* @var $sitemap \Product\Sitemap\Model\Sitemap */

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.