0

I try to override Mage_Sitemap_Model_Resource_Catalog_Product class. Here is my files:

File \magento\app\etc\modules\Own_Sitemap.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
        <modules>
            <Own_Sitemap>
                <active>true</active>
                <codepool>local</codepool>
            </Own_Sitemap>
        </modules>
    </config>

File \magento\app\code\local\Own\Sitemap\etc\config.xml

    <?xml version="1.0"?>
    <config>
    <modules>
        <Own_Sitemap>
            <version>0.1</version>
        </Own_Sitemap>
    </modules>
    <global>
        <models>
            <sitemap>
                <catalog_resource>
                    <rewrite>
                        <product>Own_Sitemap_Model_Resource_Catalog_Product</product>
                    </rewrite>
                </catalog_resource>
            </sitemap>
        </models>
    </global>
    </config>

File \magento\app\code\local\Own\Sitemap\Model\Resource\Catalog\Product.php

class Own_Sitemap_Model_Resource_Catalog_Product extends Mage_Sitemap_Model_Resource_Catalog_Product
{
    /**
     * Get product collection array
     *
     * @param int $storeId
     * @return array
     */
    public function getCollection($storeId)
    {
        /* @var $store Mage_Core_Model_Store */
        $store = Mage::app()->getStore($storeId);
        if (!$store) {
            return false;
        }

        $this->_select = $this->_getWriteAdapter()->select()
            ->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName()))
            ->join(
                array('w' => $this->getTable('catalog/product_website')),
                'main_table.entity_id = w.product_id',
                array()
            )
            ->where('w.website_id=?', $store->getWebsiteId());

        $storeId = (int)$store->getId();

        /** @var $urlRewrite Mage_Catalog_Helper_Product_Url_Rewrite_Interface */
        $urlRewrite = $this->_factory->getProductUrlRewriteHelper();
        $urlRewrite->joinTableToSelect($this->_select, $storeId);

        $this->_addFilter($storeId, 'visibility',
            Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds(), 'in'
        );
        $this->_addFilter($storeId, 'status',
            Mage::getSingleton('catalog/product_status')->getVisibleStatusIds(), 'in'
        );

        $entries = $this->_loadEntities();
        $this->_addFilter($storeId, 'inchoo_meta_robots', array(200, 201), 'in');
        $noindex = $this->_loadEntities();

        foreach ($entries as $k => $v){
            if (array_key_exists($k, $noindex)) {
                unset($entries[$k]);
            }
        }
        return $entries;
    }

}

When I try to generate new sitemap, application stiil use Mage class. I tried to remove the cache, but it did not help. What am I doing wrong?

  • Are you sure no other modules has rewritten that class? – Sander Mangel Aug 18 '15 at 9:14
0

Use below config instead of above to rewrite model

    #File \magento\app\code\local\Own\Sitemap\etc\congif.xml

    <?xml version="1.0"?>
    <config>
        <modules>
            <Own_Sitemap>
                <version>0.1</version>
            </Own_Sitemap>
        </modules>
        <global>
            <models>
                <sitemap>                    
                    <rewrite>
                        <resource_catalog_product>Own_Sitemap_Model_Resource_Catalog_Product</resource_catalog_product>
                    </rewrite>                   
                </sitemap>
            </models>
        </global>
    </config>
  • Problem still not solved. – Vitalii Prodan Aug 14 '15 at 12:13
  • I modified above code, try this – amit_game Aug 14 '15 at 12:22
  • Does not work. Thank you for trying – Vitalii Prodan Aug 14 '15 at 12:32
  • I have gone through the above code and tested it on the same module to rewrite and its working perfectly, any thing else which you want to tell, me any error, some what else – amit_game Aug 14 '15 at 13:16
  • I set xdebug breakpoints and I see that magento still use core class. In Configuration > Advanced > Advanced this block is enabled i.imgur.com/UYvPUWa.png – Vitalii Prodan Aug 14 '15 at 13:37
0

Replace your code in File \magento\app\etc\modules\Own_Sitemap.xml

From

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Own_Sitemap>
            <active>true</active>
            <codepool>local</codepool>
        </Own_Sitemap>
    </modules>
</config>

To

<?xml version="1.0"?>
<config>
    <modules>
        <Own_Sitemap>
            <active>true</active>
            <codePool>local</codePool>
        </Own_Sitemap>
    </modules>
</config>

Note: Magento will first take the node value (watch the upper case P in the node name).Then it is must be codePool

Replace your code in File \magento\app\code\local\Own\Sitemap\etc\config.xml

From

<?xml version="1.0"?>
<config>
    <modules>
        <Own_Sitemap>
            <version>0.1</version>
        </Own_Sitemap>
    </modules>
    <global>
        <models>
            <sitemap>
                <catalog_resource>
                    <rewrite>
                        <product>Own_Sitemap_Model_Resource_Catalog_Product</product>
                    </rewrite>
                </catalog_resource>
            </sitemap>
        </models>
    </global>
</config>

To

 <?xml version="1.0"?>
 <config>
    <modules>
        <Own_Sitemap>
            <version>0.1</version>
        </Own_Sitemap>
    </modules>
    <global>
        <models>
            <sitemap_resource>
                <rewrite>
                    <product>Own_Sitemap_Model_Resource_Catalog_Product</product>
                </rewrite>
            </sitemap_resource>
        </models>
    </global>
 </config>
0

Above Answer is not working : correct configuration will be

<global>
  <models>    
    <sitemap_resource>
        <rewrite>
            <catalog_product>Own_Sitemap_Model_Resource_Catalog_Product</catalog_product>
        </rewrite>
    </sitemap_resource>
  </models>
</global>

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.