Post by jd_james » Mon Nov 07, 2011 5:02 pm

Guys,

I managed to get the product feed working under the module "Open Base".

With a little bit of coding i no longer get errors and everything runs fine without errors and i know google don't guarantee anything showing up but its strange how only one of 70 items i offer is showing online.. What makes that different?

http://www.google.co.uk/search?q=wallpa ... 70&bih=730

is the list.

Here is my opencart code:

Code: Select all

<?php 
class ControllerFeedOpenBase extends Controller {
	
	

	
	public function plainText($description){
		
		$description = strip_tags(html_entity_decode($description));
		$description = str_replace('&nbsp;', ' ', $description);
		$description = str_replace('"', '"', $description );
		$description = str_replace("'", ''', $description );
		$description = str_replace('<', '<', $description );
		$description = str_replace('>', '>', $description );
		$description = str_replace("\n", ' ', $description );
		$description = str_replace("\r", ' ', $description );
		$description = preg_replace('/&#?[a-z0-9]+;/i',' ',$description); // remove any html entities.. 	
		$description = preg_replace('/\s{2,}/i', ' ', $description );	
		return substr($description, 0, 5000 );	
	}
	
	
	public function index() {
		if ($this->config->get('open_base_status')) { 
			$output  = '<?xml version="1.0" encoding="UTF-8" ?>';
			$output .= '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">';
            $output .= '<channel>';
			$output .= '<title>' . $this->config->get('config_name') . '</title>'; 
			$output .= '<description>' . $this->config->get('config_meta_description') . '</description>';
			$output .= '<link>' . HTTP_SERVER . '</link>';
			$output .= '<g:google_product_category>Toys & Games</g:google_product_category>';
			
			$this->load->model('catalog/category');
			
			$this->load->model('catalog/product');
			$this->load->model('tool/image');
		
			
			$products = $this->model_catalog_product->getProducts();
			
			foreach ($products as $product) {
				
				
				if ($product['description']) {
					
				
					$output .= '<item>';
					$output .= '<title>' . $product['name'] . '</title>';
					$output .= '<link>' . HTTP_SERVER . 'index.php?route=product/product&product_id=' . $product['product_id'] . '</link>';
					$output .= '<description>' . $this->plainText($product['description']) . '</description>';
					$output .= '<g:brand>' . $this->plainText($product['manufacturer']) . '</g:brand>';
					$output .= '<g:condition>new</g:condition>';
					$output .= '<g:id>' . $product['product_id'] . '</g:id>';
					$output .= '<g:google_product_category>Office Supplies > Shipping Supplies > Packing Materials</g:google_product_category>';

					if ($product['image']) {
						$output .= '<g:image_link>' . $this->model_tool_image->resize($product['image'], 500, 500) . '</g:image_link>';
					} else {
						$output .= '<g:image_link>' . $this->model_tool_image->resize('no_image.jpg', 500, 500) . '</g:image_link>';
					}
					$output .= '<g:mpn>' . $product['model'] . '</g:mpn>';


					$supported_currencies = array('USD', 'EUR', 'GBP', 'AUD');

                    if (in_array($this->currency->getCode(), $supported_currencies)) {
                        $currency = $this->currency->getCode();
                    } else {
                        $currency = ($this->config->get('open_base_status')) ? $this->config->get('open_base_status') : 'USD';
                    }
					if ($product['quantity'] > 0) {
					$output .= '<g:availability>In Stock</g:availability>';
					} else {
					$output .= '<g:availability>' . $product['stock'] . '</g:availability>';
					}
									
					if ((float)$product['special']) {
                        $output .= '<g:price>' .  $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id']), $currency, FALSE, FALSE) . '</g:price>';
                    } else {
                        $output .= '<g:price>' . $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency, FALSE, FALSE) . '</g:price>';
                    }
			   
					$categories = $this->model_catalog_product->getCategories($product['product_id']);
					
					foreach ($categories as $category) {
						$path = $this->getPath($category['category_id']);
						
						if ($path) {
							$string = '';
							
							foreach (explode('_', $path) as $path_id) {
								$category_info = $this->model_catalog_category->getCategory($path_id);
								
								if ($category_info) {
									if (!$string) {
										$string = $category_info['name'];
									} else {
										$string .= ' > ' . $category_info['name'];
									}
								}
							}
						 
							$output .= '<g:product_type>' . $string . '</g:product_type>';
						}
					}
					
					$output .= '<g:quantity>' . $product['quantity'] . '</g:quantity>';

					$output .= '<g:upc>' . $product['sku'] . '</g:upc>';
					$output .= '<g:weight>' . $this->weight->format($product['weight'], $product['weight_class']) . '</g:weight>'; 
					$output .= '</item>';
				}
			}
			
			$output .= '</channel>'; 
			$output .= '</rss>';	

			$this->response->addHeader('Content-Type: text/xml;');
			$this->response->setOutput($output);
		}
	}
	
	protected function getPath($parent_id, $current_path = '') {
		$category_info = $this->model_catalog_category->getCategory($parent_id);
	
		if ($category_info) {
			if (!$current_path) {
				$new_path = $category_info['category_id'];
			} else {
				$new_path = $category_info['category_id'] . '_' . $current_path;
			}	
		
			$path = $this->getPath($category_info['parent_id'], $new_path);
					
			if ($path) {
				return $path;
			} else {
				return $new_path;
			}
		}
	}		
}
?>


Active Member

Posts

Joined
Fri Apr 15, 2011 10:55 pm

Post by uksitebuilder » Mon Nov 07, 2011 6:16 pm

That links shows 70 items

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by jd_james » Mon Nov 07, 2011 6:59 pm

What?

Surely thats not right.

Look here on the attachment, i searched last night from home and couldn't find anything and today from a different network & Computer and its not finding the rest either.

Hmmm.

Attachments

Capture.PNG

Capture.PNG (118.78 KiB) Viewed 1599 times


Active Member

Posts

Joined
Fri Apr 15, 2011 10:55 pm

Post by uksitebuilder » Mon Nov 07, 2011 7:35 pm

Very strange - probably just needs a little more time
Capture.JPG

Capture.JPG (16.67 KiB) Viewed 1593 times


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom
Who is online

Users browsing this forum: No registered users and 1 guest