Page 1 of 3

Latest products feeds

Posted: Mon May 09, 2011 7:30 pm
by tomtom
Note: This is adapted from the original Module from krikey here http://www.opencart.com/index.php?route ... order=DESC i wanted to post the code in the comments but it only allows 1000 characters max :choke:

To make this a valid RSS Feed I adapted the code a bit...

This is displaying:

Copyright
Language
Date Timestamp
Shop Logo
SEO Links
Product images (can be auto resized find "->resize($product['image'], 80, 80)" and change 80, 80 to what ever you want. Rss maximum allowed width 144/ height 400. )
Product price
Product description

Validates on http://validator.w3.org/feed/

Feeds are working for Facebook (Notes and RSSGraffiti)

Demo Feed can be seen here http://www.caprice-modeschmuck.de/index ... oducts_rss

Facebook Page here http://www.facebook.com/pages/Caprice-M ... 3201793290


copy and replace code in replace the code in catalog/controller/feed/latest_products_rss.php with the code below

Code: Select all

<?php

class ControllerFeedLatestProductsRSS extends Controller {

    public function index() {
	if ($this->config->get('latest_products_rss_status')) {
	    $output = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
	    $output .= '<rss version="2.0">' . "\n";
	    $output .= '<channel>' . "\n";
	    $output .= '<title>' . $this->config->get('config_name') . '</title>' . "\n";
	    $output .= '<copyright>' . 'Copyright (c) ' . date("Y") . ' ' . $this->config->get('config_name') . ' All rights reserved.' . '</copyright>' . "\n";
	    $output .= '<link>' . HTTP_SERVER . '</link>' . "\n";
	    $output .= '<description>' . $this->config->get('config_name') . ' Latest Products Feed' . '</description>' . "\n";
	    $output .= '<language>de-DE</language>' . "\n";
	    $output .= '<pubDate>' . gmdate("D\, d M Y H:i:s T") . '</pubDate>' . "\n";
		$output .= '<image>' . "\n";
	    $output .= '<title>' . $this->config->get('config_name') . '</title>' . "\n";
		$output .= '<width>142</width>' . "\n";
		$output .= '<height>18</height>' . "\n";

	    $output .= '<link>' . HTTP_SERVER . '</link>' . "\n";
		if( $this->config->get( 'config_logo' )
		&& file_exists( DIR_IMAGE . $this->config->get( 'config_logo' ) ) ) {
		    $output .= '<url>' . HTTP_IMAGE . $this->config->get( 'config_logo' ) . '</url>' . "\n";
			}else{
			$output .= '<url> </url>' . "\n";
		}
	    $output .= '</image>' . "\n";

	    $this->load->model('catalog/product');
	    $this->load->model('localisation/currency');
		$this->load->model('tool/image');
		$this->load->model('tool/seo_url');

 	    
	    $limit = $this->config->get('latest_products_rss_limit') ? $this->config->get('latest_products_rss_limit') : 100;
	    
	    $products = $this->model_catalog_product->getLatestProducts($limit);

	    if (isset($this->request->get['currency'])) {
		$currency = $this->request->get['currency'];
	    }
	    else {
		$currency = $this->currency->getCode();
	    }

	    foreach ($products as $product) {
		if ($product['description']) {
		    $output .= '<item>' . "\n";
		    $output .= '<title>' . html_entity_decode($product['name'], ENT_QUOTES, 'UTF-8') . '</title>' . "\n";
		    //$output .= '<link>' . HTTP_SERVER . 'index.php?route=product/product&product_id=' . $product['product_id'] . '</link>' . "\n";
		    $output .= '<link>' . str_replace('&', '&', $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $product['product_id'])) . '</link>';

		    $special = $this->model_catalog_product->getProductSpecial($product['product_id']);

		    if ($special) {
			$price = $this->currency->format($this->tax->calculate($special, $product['tax_class_id']), $currency, FALSE, TRUE);
		    } else {
			$price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency, FALSE, TRUE);
		    }

		    $p = htmlspecialchars('<p><strong>Price: ' . $price . '</strong></p>');

		    //$output .= '<description>' . $p . $product['description'] . '</description>' . "\n";
		    $output .= '<description>';
			
			if ($product['image']) {
				  $output .= '<a href="' . str_replace('&', '&', $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $product['product_id'])) . '">' . "\n";
				  $output .= '<img src="' . $this->model_tool_image->resize($product['image'], 80, 80) . '" border="0"/></a>' . $p . $product['description'] . '</description>' . "\n";
				} else {
				  $output .= $p . $product['description'] . '</description>' . "\n";
				}		    
		    $output .= '</item>' . "\n";

		}
	    }

	    $output .= '</channel>' . "\n";
	    $output .= '</rss>' . "\n";

	    $this->response->addHeader('Content-Type: application/rss+xml');
	    $this->response->setOutput($output, 0);
	}
    }
}

?>

Re: Latest products feeds

Posted: Sat Sep 03, 2011 4:23 am
by FT Industriels
Thank you it's work perfectly

Do you plane to upgrade it for OC 1.5.1.x ?

Re: Latest products feeds

Posted: Sat Sep 03, 2011 5:43 am
by tomtom
Well, I have not switched over to 1.5 yet, but if I do I will and post it here.

Re: Latest products feeds

Posted: Wed Nov 30, 2011 3:25 am
by phatmaxi
working on an update

Re: Latest products feeds

Posted: Mon Dec 05, 2011 6:35 am
by straightlight
Now compatible with v1.5.1.x (to avoid the error messages on screen). As for the content sides, a bit more work may be required.

Re: Latest products feeds

Posted: Wed Dec 07, 2011 1:29 am
by phatmaxi

Re: Latest products feeds

Posted: Wed Dec 07, 2011 1:38 am
by straightlight
If you're referring to my ZIP file above, the feed folder is not what has been specified as a folder from my package. Although, I can't neither reproduce the error you're encountering nor having a line 73 on the file since it rathers ends on line 59 ...

Re: Latest products feeds

Posted: Wed Dec 07, 2011 2:26 am
by phatmaxi
straightlight wrote:If you're referring to my ZIP file above, the feed folder is not what has been specified as a folder from my package. Although, I can't neither reproduce the error you're encountering nor having a line 73 on the file since it rathers ends on line 59 ...
Not sure what you mean, my intention was to replicate the original extension and I accomplished that. The errors were from my playing around with the code. But the actual link is updated and valid. The goal is the have a starting point were we can all create a really nice rss feed. I have minimal php skills, this took some work for me. Check out the link:
http://rrautomotivegroup.com/shop/index ... oducts_rss



What's Missing from the original is the SEO and Specials price... didn't have time to figure it out.

Re: Latest products feeds

Posted: Wed Dec 07, 2011 2:29 am
by straightlight
It's a bit clearer now that not only a URL has been posted. ;)

Posted: Wed Dec 07, 2011 2:35 am
by phatmaxi
sorry for jacking your thread tomtom

Re: Latest products feeds

Posted: Wed Dec 07, 2011 2:36 am
by phatmaxi
straightlight wrote:It's a bit clearer now that not only a URL has been posted. ;)
:) awesome

Re: Latest products feeds

Posted: Sun Dec 11, 2011 4:59 am
by FTIndustriels
Thank you for this modification.
I need to use url seo, do you know how can I do that ?

Re: Latest products feeds

Posted: Wed Dec 14, 2011 10:33 pm
by FTIndustriels
Any one can do that for us ?

Re: Latest products feeds

Posted: Mon Dec 19, 2011 12:45 am
by barryhung
I install the model successfully in 1.5.1.3 , but can't enable it always. anyone know why?

Re: Latest products feeds

Posted: Mon Dec 19, 2011 12:49 am
by barryhung
I found the code in controller $this->config->get('rss_status') and anyone know where is the config I can found, DB or cache file?

Re: Latest products feeds

Posted: Mon Dec 19, 2011 1:08 am
by straightlight
In the setting table's value field from PHPMyAdmin, you will probably see it.

Re: Latest products feeds

Posted: Thu Dec 29, 2011 6:07 pm
by dklnd
Edit.

Oke I got it fixed!

dekloned.be/index.php?route=feed/latest_products_rss

It's showing the productinfo double; any ideas?

Re: Latest products feeds

Posted: Thu Dec 29, 2011 10:32 pm
by straightlight
Just by showing the RSS feeds won't really help to get the right information. The first things to know is starting from your 'got it fixed', what was the way to make that happen as a result of having double productinfo results ?

Re: Latest products feeds

Posted: Fri Dec 30, 2011 7:01 pm
by kralizec
anyone has figure it out the problem in enabling the plugin? I'm having the same issue of Barryhung on OC 1.5.1

Re: Latest products feeds

Posted: Fri Dec 30, 2011 10:51 pm
by straightlight
What is your version of what you did in order to get this problem ?