0

I'm currently working with a Magento 1.9.x Community Edition instance, trying to get an AvantLink metric tracking system to work properly. Most of the work has been done; they're seeing the calls to their tracking script from the success.phtml page with no issues. The problem is that they also need access to an RSS feed (they prefer Google Shopping format, I guess, but said that the standard RSS as is built in to Magento would be fine as well [legacy?]), and that can provide data on our products.

After making certain that all of the RSS capabilities [built in] were enabled, I gave them the URL, and they were able to successfully pull the feed. Unfortunately, while the feed gives them some of what they need, they are still missing the following vital bits of information:

  • id
  • product_type
  • image_link
  • price
  • sale_price

I've looked everywhere that I can in the admin page, and I've done plenty of google searching, with my (admittedly limited) google-fu. I've been able to turn up plenty of for-pay extensions that'll export a Google Shopping RSS feed, or other RSS feeds, that can be customized to this extent, I believe, but I'm not going to be able to sell my clients on a non-free extension to get this working.

Does anybody know if there is a way that I can add these fields to the RSS feeds, via the admin control page? If not, can anybody direct me to the appropriate locations, in code, where I might be able to code these additions myself? As always, any helpful tidbits, or even pointers in vaguely correct directions, are greatly appreciated.

Thanks in advance. Please feel free to let me know, if I've left out any information that is necessary for figuring this out.

-Damon

1
  • The key here - "without extensions" - the answer is no. You will absolutely need some kind of extension because Magento has no way of modifying the contents of the RSS from within the admin.
    – philwinkle
    Commented Aug 11, 2015 at 2:40

2 Answers 2

2

The blocks used in Rss creation are in app/code/core/Mage/Rss/Block

Just a guess, but maybe you want to modify the app/code/core/Mage/Rss/Block/Catalog/Category.php file? There are several, take a look at the blocks and see which affects the feed you are concerned with.

I would create a simple module that rewrites the block you need to modify. A quick example, assuming that your company is called Yourcompany :

app/code/local/Yourcompany/Rss/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Yourcompany_Rss>
            <version>0.1.0</version>
        </Yourcompany_Rss>
    </modules>
    <global>
        <blocks>
            <yourcompany_rss>
                <class>Yourcompany_Rss_Block</class>
            </yourcompany_rss>
            <rss>
                <rewrite>
                    <catalog_category>Yourcompany_Rss_Block_Rss_Catalog_Category</catalog_category>
                </rewrite>
            </rss>
        </blocks>
        <helpers>
            <yourcompany_rss>
                <class>Yourcompany_Rss_Helper</class>
            </yourcompany_rss>
        </helpers>
    </global>
</config>

app/code/local/Yourcompany/Rss/Block/Rss/Catalog/Category.php

class Yourcompany_Rss_Block_Rss_Catalog_Category extends Mage_Rss_Block_Catalog_Category {

protected function _toHtml()
{
    $categoryId = $this->getRequest()->getParam('cid');
    $storeId = $this->_getStoreId();
    $rssObj = Mage::getModel('rss/rss');
    if ($categoryId) {
        $category = Mage::getModel('catalog/category')->load($categoryId);
        if ($category && $category->getId()) {
            $layer = Mage::getSingleton('catalog/layer')->setStore($storeId);
            //want to load all products no matter anchor or not
            $category->setIsAnchor(true);
            $newurl = $category->getUrl();
            $title = $category->getName();
            $data = array('title' => $title,
                'description' => $title,
                'link'        => $newurl,
                'charset'     => 'UTF-8',
            );

            $rssObj->_addHeader($data);

            $_collection = $category->getCollection();
            $_collection->addAttributeToSelect('url_key')
                ->addAttributeToSelect('name')
                ->addAttributeToSelect('is_anchor')
                ->addAttributeToFilter('is_active',1)
                ->addIdFilter($category->getChildren())
                ->load()
            ;
            $productCollection = Mage::getModel('catalog/product')->getCollection();

            $currentCategory = $layer->setCurrentCategory($category);
            $layer->prepareProductCollection($productCollection);
            $productCollection->addCountToCategories($_collection);

            $category->getProductCollection()->setStoreId($storeId);
            /*
            only load latest 50 products
            */
            $_productCollection = $currentCategory
                ->getProductCollection()
                ->addAttributeToSort('updated_at','desc')
                ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
                ->setCurPage(1)
                ->setPageSize(50)
            ;

            if ($_productCollection->getSize()>0) {
                $args = array('rssObj' => $rssObj);
                foreach ($_productCollection as $_product) {
                    $args['product'] = $_product;
                    $this->addNewItemXmlCallback($args);
                }
            }
        }
    }
    return $rssObj->createRssXml();
}

}

In this case, if you modify the collection at ~ line 47

$_productCollection = $currentCategory
                    ->getProductCollection()

to include the attributes you need you should have them in the feed.

You will also need your module declared in app/etc/modules, but your question was about rss, not custom modules ; )

So, take a look at the contents of app/code/core/Mage/Rss/Block/ , and rewrite the file that corresponds to your feed.

** I used a module name of Rss, that was totally arbitrary, you can name the module anything you want.

2
  • Thank you; I knew that there had to be some sort of a way to do this with an override or event/observer tie in, if nothing else. I really appreciate the time that you took to spell everything out in such detail, also. This is much more than just the starting point I needed; one of the best and most helpful replies I've gotten on here. Thanks again and I wish you the best! Commented Aug 11, 2015 at 14:27
  • Glad that helped. Good luck on building it out!
    – AreDubya
    Commented Aug 11, 2015 at 19:07
0

I am trying to get the same result in-order to integrate with mailchimp Rss feed mailer.

I need product_image, image_link, price, sale_price

I am trying to customize app/code/core/Mage/Rss/Block/Catalog/Special.php to achieve this. But then again i cannot find the proper way to add tag or to add custom rss tags into code.

Hope you have already made this working for your needs.

Expected end result: https://blog.mailchimp.com/rss-to-email-enhancement-for-publishers/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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