Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I create a custom RSS feed? 
 
karynn
Member
 
Avatar
Total Posts:  70
Joined:  2008-02-07
 

Until something like the singlefeed feature is available (http://www.magentocommerce.com/boards/viewthread/5482/), I would like to customize the Product RSS feed to include additional attributes and have more control over the XML produced.

I see there are some attributes defined in this file:
\app\code\core\Mage\Rss\Block\Catalog\Category.php

Would I only need to add my attributes here:

$data = array(
                                    
'title'         => $_product->getName(),
                                    
'link'          => $_product->getProductUrl(),
                                    
'description'   => $description,
                                    );

or do I need to edit additional files? I’m afraid to muck about in these and was hoping someone might have experience doing this.

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Princeanil
Jr. Member
 
Total Posts:  28
Joined:  2008-05-06
 

Hi !

I need to create an RSS feed of all products on the store, in case anyone knows how thats possible, pls inform

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
alwoodjs
Jr. Member
 
Total Posts:  6
Joined:  2009-01-21
 

Did either of you find an answer to this? I would like to be able to edit the rss feed to only show the item title and not the description.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Way to go
Jr. Member
 
Total Posts:  18
Joined:  2009-02-16
 

Need help as well…

 
Magento Community Magento Community
Magento Community
Magento Community
 
jmlee
Member
 
Total Posts:  53
Joined:  2008-06-23
 

You can modify the feed output by modifying the following file:

\app\code\core\Mage\Rss\Block\Catalog

inside the above folder, you can choose the modify the new products feed (new.php) or products in a certain category (category.php), etc.

and just scroll down to about line 99-104, you will see a declaration of description variable, you can freely modify the html output there to take out description etc.

Good luck.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Forsh
Jr. Member
 
Total Posts:  4
Joined:  2009-12-10
 
jmlee - 11 November 2009 06:50 AM

You can modify the feed output by modifying the following file:

\app\code\core\Mage\Rss\Block\Catalog

inside the above folder, you can choose the modify the new products feed (new.php) or products in a certain category (category.php), etc.

and just scroll down to about line 99-104, you will see a declaration of description variable, you can freely modify the html output there to take out description etc.

Good luck.

I am in a similar situation, but when I add new XML tags to that $data array they are not included in the actual XML output.  Has anybody got any ideas how to change the data model that it expects?  I’ve got a feeling that editting just catalog.php on its own will not be sufficient.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Forsh
Jr. Member
 
Total Posts:  4
Joined:  2009-12-10
 

Just a quick one to let you know that I solved this one!

The working Cooliris wall can be seen here:  http://beaumonaco.com/bracelets.html

and the feed itself is at:  http://beaumonaco.com/rss/catalog/category/cid/35/store_id/1/

It required 2 modifications to the Core code.

The first, to get the thumbnails and images up to 400x400px, was to

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

Around line 111, add this line:-

$imgLink=$this->helper('catalog/image')->init($_product'thumbnail')->resize(400400);

And in the block beneath that where $description is defined, change the block of code to:-

$description '<table><tr>'.
                            
'<td><a href="'.$_product->getProductUrl().'"><img src="' $imgLink
                            
.'" border="0" align="left" height="400" width="400"></a></td>'.
                            
'<td  style="text-decoration:none;">'.$_product->getDescription().
                            
'<p> Price:'.Mage::helper('core')->currency($_product->getPrice()).
                            (
$_product->getPrice() != $final_price  ' Special Price:'Mage::helper('core')->currency($final_price) : '').
                            
'</p>'.
                            
'</td>'.
                            
'</tr></table>'
                        
;

Which basically just puts the new image into the description.

The next change is a bit fiddly, but I added it to the Zend RSS feed builder:-

lib/Zend/Feed/Rss.php

On or around line 400, AFTER this block of code:

$description $this->_element->createElement('description');
            
$description->appendChild($this->_element->createCDATASection($dataentry->description));
            
$item->appendChild($description);

I added the following code, in order to include some additional elements in the resulting feed:

$description2 $this->_element->createElement('media:description');
            
$description2->appendChild($this->_element->createCDATASection($dataentry->description));
            
$item->appendChild($description2);
           
/* media:thumbnail processing */
        // extract all <img> tags and place in an array.  Should just be one for each description
        
preg_match_all('/<img[^>]+>/i',$dataentry->description$imgresult); 
        
$thumb=$this->_element->createElement('media:thumbnail');
        
        
// Extract the "src=" portion of the resulting image attribute
        
preg_match_all('/(src)=("[^"]*")/i',$imgresult[0][0]$img);
        
preg_match('/"([^"]+)"/'html_entity_decode($img[2][0]), $noquotes);
        
// strip the starting and ending quotes
        
$thumb->setAttribute('url'substr($noquotes[0],1,-1));
        
$item->appendChild($thumb);
                
// Using the same image as the thumbnail
        
$content2$this->_element->createElement('media:content');
        
$content2->setAttribute('url'substr($noquotes[0],1,-1));
        
$item->appendChild($content2);

And finally I added some more code at the end, in the saveXml function:-

Change it as follows, to add 2 new namespaces to the feed:-

// Content namespace
        $root->setAttributeNS('http://www.w3.org/2000/xmlns/''xmlns:content''http://purl.org/rss/1.0/modules/content/'); // existing line - added 2 below
     
$root->setAttributeNS('http://www.w3.org/2000/xmlns/''xmlns:media''http://search.yahoo.com/mrss/'); // AJF added media namespace
      
$root->setAttributeNS('http://www.w3.org/2000/xmlns/''xmlns:atom''http://www.w3.org/2005/Atom'); // AJF added media namespace

Thats about it!  I know it’s not recommended to edit core Zend code, but I couldn’t think of an easier way due to the short timescale for my project.  If anyone can think of a better way then I would be interested in seeing it smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
bulgariafilm
Jr. Member
 
Total Posts:  6
Joined:  2012-04-23
 

Wait… here we don’t want to add all info inside the DESCRIPTION field....

The point here is to add new fields to the feed.
Google Base (for example) expects each info to be in a separate field and a RSS FEED hat has all this stuff inside DESCRIPTION will not work.

Google base wants (some are compulsory some just suggested) the following…

TITLE, LINK, DESCRIPTION, (and these we have.. but also..) CONDITION, ID, PRICE, SHIPPING, BRAND, AVAILABILITY, MPN, IMAGE LINK.

Is it possible to add lines that extract these other info? What should we write? I am not a programmer.. can somebody help me?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top