Jump to content

PHP - URL Image module


ronymac

Recommended Posts

Hello I'm doing a module to generate XML for the Rocket, using the basic Google Base is now missing only the last step when I put the parameters used for the image, it does not work. Already activated and took the friendly url.

<?php

class googlemerchant extends Module{

   private $_html = '';
   private $_currLID;
   private $_host;
   private $_feedDescription;
   private $_baseUrl, $_directory, $_filename, $_filename_http;

   public function __construct(){
	global $cookie;
	
	$this->name = 'googlemerchant';
	$this->_currLID = intval($cookie->id_lang);
	
	$this->_host = $_SERVER['HTTP_HOST'];
	
	parent::__construct();
	
	$this->tab = 'seo';
	$this->version = '0.1';
	$this->page = basename(__FILE__, '.php');
	$this->displayName = $this->l('Google XML -  Por Imaginare Digital');
	$this->description = $this->l('Google XML -  Por Imaginare Digital | [email protected]');
	
	$this->_baseUrl = __PS_BASE_URI__;
	$this->_directory = dirname(__FILE__).'/../../';
    	$this->_filename = $this->_directory.strtolower(Language::getIsoById($this->_currLID)).'_googlebase.xml';
    	$this->_filename_http = 'http://' . $this->_host . $this->_baseUrl . strtolower(Language::getIsoById($this->_currLID)).'_googlebase.xml';
	
   }
     
   public function uninstall() {
   
   	@unlink($_this->_filename);
   	parent::uninstall();
   	
   
   }
   
   public function getContent(){
   
   	if(!empty($_POST)){
   	
   		$this->_configure($_POST['configuration']);
   	
   	}
   	
   	$this->_html .= '<h2>'.$this->l('Bem vindo ao Google XML.').'</h2>';
   	$this->_html .= '<h4>'.$this->l('Para suporte envie um e-mail para [email protected]').'</h4>';
   	
   	$this->_configureMain();
   	
   	$this->_html .=  '  	   <fieldset>
   		<legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Informações de Feed').'</legend>';
   	
   	$this->_html .= '<p>'.$this->l('O seu arquivo de feed Google Base é on-line no seguinte endereço:').'<br /><a href="'.$this->_filename_http.'" target="_gmerchant"><b>'.$this->_filename_http.'</b></a></p><br />';
   	
   	$this->_html .= '</fieldset>';
   	
   	$this->_writeFeed($this->_buildFeed());
   	
   	return $this->_html;
   	
   
   }
   
   private function _configureMain(){
   
   	$this->_html .= '
   	<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
   	   <fieldset>
   		<legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Configuração Principal').'</legend>
   		<div class="margin-form">
	   		<label>'.$this->l('Feed Title').'</label>
	   		<input type="text" name="configuration[feedtitle]" id="gmc_feedtitle" value="'.Configuration::get('GOOGLEMERCHANT_FEEDTITLE').'" size="60" maxlength="60" />
	   	</div>
	   	<div class="margin-form">
	   		<label>'.$this->l('Descrição do Feed').'</label>
	   		<input type="text" name="configuration[feeddesc]" id="gmc_feeddescription" value="'.Configuration::get('GOOGLEMERCHANT_FEEDDESC').'" size="60" maxlength="60" />
	   	</div>
	   	<div class="margin-form">
	   		<label>'.$this->l('Prefere GTIN').'</label>
	   		<select name="configuration[feedgtin]" id="gmc_feedgtin">
	   		      <option value="" '.((strcmp('none', Configuration::get('GOOGLEMERCHANT_GTIN'))==0)?'selected="selected"':''). '>None</option>
  			      <option value="upc" '.((strcmp('upc', Configuration::get('GOOGLEMERCHANT_GTIN'))==0)?'selected="selected"':''). '>UPC</option>
    			      <option value="ean13" '.((strcmp('ean13', Configuration::get('GOOGLEMERCHANT_GTIN'))==0)?'selected="selected"':'').'>EAN13</option>
	   		</select>
	   	</div>
	   	<div class="margin-form">
	   		<input name="btnSubmit" class="button" value="'.((!file_exists($this->_filename)) ? $this->l('Gerar Feed') : $this->l('Atualizar Feed')).'" type="submit" />
	   	</div>
   	   </fieldset>
   	</form>
   	
   	
   	';
   
   }
   
  private function _buildFeed(){
   	
   	$productArray = Product::getProducts($this->_currLID, 0, NULL, 'id_product', 'ASC');   	
   
	    if(isset($productArray) && is_array($productArray))
	    {
	      $link = new Link();
	      $feedPrefix = 'gmc'; 
	      $langPrefix = strtolower(Language::getIsoById($this->_currLID));
	      $expire_date = date('Y-m-d', strtotime("+30 days"));
	    /** <?xml version="1.0" encoding="ISO-8859-1"?>   /**/
		 $feedStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
		  $feedStr .= "<E-Presentes>\n";
	
	      foreach ($productArray AS $product)
	      {
	        if ($product['active']) {


$patch=$link->getImageLink(Tools::link_rewrite($image['legend']), $image['id_product'].'-'.$image['id_image']);


	          $productLink = $link->getProductLink($product['id_product'], $product['link_rewrite']);
	          $productPrice = Product::getPriceStatic(intval($product['id_product']));
								  $feedStr .= "<E-Presentes>\n";

	          $feedStr .= "<produto>\n";
			  $feedStr .= '<id>'.$feedPrefix.$langPrefix."-".$product['id_product']."</id>\n";
			  $feedStr .= '<titulo>'.$this->_XMLSafe($product['name'])."</titulo>\n";
		      $feedStr .= '<link_prod>'. $this->_XMLSafe($productLink)."</link_prod>\n";
		      $feedStr .= '<preco>'.$productPrice."</preco>\n";
			  $feedStr .= '<parcelamento>'."6x sem juros ou 12x ."."</parcelamento>\n";
			  $feedStr .= '<disponibilidade>'."Em estoque."."</disponibilidade>\n";
		      $feedStr .= '<imagem>'.$patch."</imagem>\n";
			  
			  $feedStr .= '<categoria>'."Relogios."."</categoria>\n";
	          	          		  

	          $feedStr .= $this->_getGtinXML($product);

	          
	          $feedStr .= "</produto>\n";
			  
	          $feedStr .= "\n";
			  $feedStr .= "</E-Presentes>\n";
	        }
	      }
	      $feedStr .= "</E-Presentes>\n";
	      return $feedStr;
	    }
	    
   
   }
   
   private function _writeFeed($feedStr){
	$fp = fopen($this->_filename, 'w');
      	fwrite($fp, $feedStr, strlen($feedStr));
      	fclose($fp);
      	
   }
   
   public function _configure($config){
   
   	Configuration::updateValue('GOOGLEMERCHANT_FEEDDESC', $config['feeddesc']);
   	Configuration::updateValue('GOOGLEMERCHANT_FEEDTITLE', $config['feedtitle']);
   	Configuration::updateValue('GOOGLEMERCHANT_GTIN',$config['feedgtin']);
   
   }
   
   private function _XMLSafe($str){
   
   	return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
   
   }
   
   private function _getGtinXML($product){
   
   	switch(Configuration::get('GOOGLEMERCHANT_GTIN')){
   	
   	   case 'upc':
   	   	
   	   	return '<g:gtin>' . $product['upc'] . '</g:gtin>';
   	   
   	   	
   	   case 'ean13':
   	   
   	   	return '<g:gtin>' . $product['ean13'] . '</g:gtin>';
   	   
   	   	
   	   default:
   	   
   	   	return '';
   	
   	}
   
   }
   
   
   private function _getDBInfo(){
   
	
	$Products = Product::getProducts($this->_currLID, 0, NULL, 'id_product', 'ASC');
	
	$this->_html .= $this->_print_rp($Products);
   
   }
   
   private function _print_rp($array){
   
   	return '<pre>'.print_r($array,1).'</pre>';
   }
	

}
?>

Where is the error that is not passing the friendly URL to display the image.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...