shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

google_base.php (5442B)


      1 <?php
      2 class ControllerExtensionFeedGoogleBase extends Controller {
      3 	public function index() {
      4 		if ($this->config->get('feed_google_base_status')) {
      5 			$output  = '<?xml version="1.0" encoding="UTF-8" ?>';
      6 			$output .= '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">';
      7 			$output .= '  <channel>';
      8 			$output .= '  <title>' . $this->config->get('config_name') . '</title>';
      9 			$output .= '  <description>' . $this->config->get('config_meta_description') . '</description>';
     10 			$output .= '  <link>' . $this->config->get('config_url') . '</link>';
     11 
     12 			$this->load->model('extension/feed/google_base');
     13 			$this->load->model('catalog/category');
     14 			$this->load->model('catalog/product');
     15 
     16 			$this->load->model('tool/image');
     17 
     18 			$product_data = array();
     19 
     20 			$google_base_categories = $this->model_extension_feed_google_base->getCategories();
     21 
     22 			foreach ($google_base_categories as $google_base_category) {
     23 				$filter_data = array(
     24 					'filter_category_id' => $google_base_category['category_id'],
     25 					'filter_filter'      => false
     26 				);
     27 
     28 				$products = $this->model_catalog_product->getProducts($filter_data);
     29 
     30 				foreach ($products as $product) {
     31 					if (!in_array($product['product_id'], $product_data) && $product['description']) {
     32 						
     33 						$product_data[] = $product['product_id'];
     34 						
     35 						$output .= '<item>';
     36 						$output .= '<title><![CDATA[' . $product['name'] . ']]></title>';
     37 						$output .= '<link>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</link>';
     38 						$output .= '<description><![CDATA[' . strip_tags(html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8')) . ']]></description>';
     39 						$output .= '<g:brand><![CDATA[' . html_entity_decode($product['manufacturer'], ENT_QUOTES, 'UTF-8') . ']]></g:brand>';
     40 						$output .= '<g:condition>new</g:condition>';
     41 						$output .= '<g:id>' . $product['product_id'] . '</g:id>';
     42 
     43 						if ($product['image']) {
     44 							$output .= '  <g:image_link>' . $this->model_tool_image->resize($product['image'], 500, 500) . '</g:image_link>';
     45 						} else {
     46 							$output .= '  <g:image_link></g:image_link>';
     47 						}
     48 
     49 						$output .= '  <g:model_number>' . $product['model'] . '</g:model_number>';
     50 
     51 						if ($product['mpn']) {
     52 							$output .= '  <g:mpn><![CDATA[' . $product['mpn'] . ']]></g:mpn>' ;
     53 						} else {
     54 							$output .= '  <g:identifier_exists>false</g:identifier_exists>';
     55 						}
     56 
     57 						if ($product['upc']) {
     58 							$output .= '  <g:upc>' . $product['upc'] . '</g:upc>';
     59 						}
     60 
     61 						if ($product['ean']) {
     62 							$output .= '  <g:ean>' . $product['ean'] . '</g:ean>';
     63 						}
     64 
     65 						$currencies = array(
     66 							'USD',
     67 							'EUR',
     68 							'GBP'
     69 						);
     70 
     71 						if (in_array($this->session->data['currency'], $currencies)) {
     72 							$currency_code = $this->session->data['currency'];
     73 							$currency_value = $this->currency->getValue($this->session->data['currency']);
     74 						} else {
     75 							$currency_code = 'USD';
     76 							$currency_value = $this->currency->getValue('USD');
     77 						}
     78 
     79 						if ((float)$product['special']) {
     80 							$output .= '  <g:price>' .  $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</g:price>';
     81 						} else {
     82 							$output .= '  <g:price>' . $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</g:price>';
     83 						}
     84 
     85 						$output .= '  <g:google_product_category>' . $google_base_category['google_base_category_id'] . '</g:google_product_category>';
     86 
     87 						$categories = $this->model_catalog_product->getCategories($product['product_id']);
     88 
     89 						foreach ($categories as $category) {
     90 							$path = $this->getPath($category['category_id']);
     91 
     92 							if ($path) {
     93 								$string = '';
     94 
     95 								foreach (explode('_', $path) as $path_id) {
     96 									$category_info = $this->model_catalog_category->getCategory($path_id);
     97 
     98 									if ($category_info) {
     99 										if (!$string) {
    100 											$string = $category_info['name'];
    101 										} else {
    102 											$string .= ' &gt; ' . $category_info['name'];
    103 										}
    104 									}
    105 								}
    106 
    107 								$output .= '<g:product_type><![CDATA[' . $string . ']]></g:product_type>';
    108 							}
    109 						}
    110 
    111 						$output .= '  <g:quantity>' . $product['quantity'] . '</g:quantity>';
    112 						$output .= '  <g:weight>' . $this->weight->format($product['weight'], $product['weight_class_id']) . '</g:weight>';
    113 						$output .= '  <g:availability><![CDATA[' . ($product['quantity'] ? 'in stock' : 'out of stock') . ']]></g:availability>';
    114 						$output .= '</item>';
    115 					}
    116 				}
    117 			}
    118 
    119 			$output .= '  </channel>';
    120 			$output .= '</rss>';
    121 
    122 			$this->response->addHeader('Content-Type: application/rss+xml');
    123 			$this->response->setOutput($output);
    124 		}
    125 	}
    126 
    127 	protected function getPath($parent_id, $current_path = '') {
    128 		$category_info = $this->model_catalog_category->getCategory($parent_id);
    129 
    130 		if ($category_info) {
    131 			if (!$current_path) {
    132 				$new_path = $category_info['category_id'];
    133 			} else {
    134 				$new_path = $category_info['category_id'] . '_' . $current_path;
    135 			}
    136 
    137 			$path = $this->getPath($category_info['parent_id'], $new_path);
    138 
    139 			if ($path) {
    140 				return $path;
    141 			} else {
    142 				return $new_path;
    143 			}
    144 		}
    145 	}
    146 }