Tutorial: RSS product feed in Bakery module

/ Tutorials, Webdevelopment

When I was fiddling with the Bakery module for the CMS Websitebaker, I found a little shortcoming – there is no RSS feed for the new products. Therefore I have decided to write it myself. For those, who would like to use this RSS feed, I have prepared te following tutorial.

We will be working with our MySQL database (via phpMyAdmin), one file from the Bakery module and we will create a new file for outputting the RSS feed.

Before you follow this tutorial, please make sure to backup your database!

Log in to your phpMyAdmin, your webhosting provider should supply you with your login details. Open a window for making SQL queries.

We will be editing the mod_bakery_items table, in which we will add a column named ‘created_when’. This will be used for the date and time a new product was added to the store.

Now you ask, why don’t we use ‘modified_when’ instead, when it’s already in the table? The answer is easy. This field is updated everytime a product gets modified. This way the RSS feed would be updated as well with old products.

We will add the column with this query:

ALTER TABLE mod_bakery_items ADD created_when INT(11) AFTER full_desc;

If you have picked some prefix for your database, don’t forget to include that!

Next we will populate the column with values from the field ‘modified_when’. This is for existing products only.

UPDATE mod_bakery_items SET created_when=modified_when;

The table will need to be updated each time new products are added, so we need to edit the file modules/bakery/add_item.php on line 33, where the product is inserted into the database. We will simply add ‘created_when’ and for getting the current time and date we will use the PHP function mktime().

 $database->query("INSERT INTO ".TABLE_PREFIX."mod_bakery_items (section_id,page_id,
position,active,created_when) VALUES ('$section_id','$page_id','$position','1',
".@mktime().")");

Now we need to create a new file for outputting the RSS feed. You can download the file below and then upload it to your host (for example in your root directory). Don’t forget to edit the file with your details!

Download RSS feed

And we’re done!

If you’re using Lastitems snippet for displaying recently added products, you may have noticed that after editing an item, the product displays as newly added, which is not always desirable. Now that we have edited the database, editing the snippet is easy.

We will edit the file modules/lastitems/include.php on line 113. The new database query will look like this:

$query_items = $database->query("SELECT item_id, title, price, link, description, 
main_image FROM ".TABLE_PREFIX."mod_bakery_items WHERE active = '1' AND 
title != '' ORDER BY modified_when DESC LIMIT ".$num_items);

If you have any questions or something is not working for you, please let me know, I’m happy to help! :)


Webdesigner Dana Svedova

I'm a freelance webdesigner and my hobbies include reading, writing and music. During my experience in this industry, I have participated in a variety of projects. I pride myself on personal communication with my clients, responsible and thorough approach to the project.

Subscribe to my blog

Want to get updates? Fill in the details below!

Comments

Commenting is closed for this article.

← Older    Newer →