Jump to content

Añadir campo "ean13" en feed para Google Merchant


rastreator

Recommended Posts

Buenas,

 

Estoy usando el módulo gratuito (que ya no está disponible) googlebase, al cual le faltan los siguientes campos obligatorios ahora para google merchant: Availability, brand, gtin, product type y google product category.

 

He solucionado todo añadiendo al archivo "googlebase.php" cada cosa, pero me falta el campo gtin(ean)

 

En el campo gtin hay que poner el código EAN de cada producto (los he creado con un modulo, así que estan en el campo ean)

 

Lo único que necesito es saber qué tengo que escribir para que genere en el feed una línea con ese dato en cada producto.

 

Se me ocurrió poner esta línea:

$feedStr.="<g:gtin>".$product['ean13']."</g:gtin>\n";
Pero no funciona, en el feed aparece sólo esto en la línea de ese dato
<g:gtin></g:gtin>
Aquí el código completo modificado por mi de "googlebase.php"
<?php

class GoogleBase extends Module
{
  private $_html = '';
  private $_directory;
  private $_filename;
  private $_filename_http;
  private $_postErrors = array();
  private $_cookie;
 
  private $_host;
  private $_baseUrl;
 
  private $_description = "Our fantastic range of products";
 
  public function __construct()
  {
    global $cookie;
    $this->_cookie = $cookie;
    $this->name = 'googlebase';
    $this->tab = 'Tools';
    $this->version = 0.4;
    
    // If you are using a local server to generate a product feed, you can change
    // base addresses here (enter the live addresses)
    $this->_host = $_SERVER['HTTP_HOST'];
    $this->_baseUrl = __PS_BASE_URI__;
    
    $this->_directory = dirname(__FILE__).'/../../';
    $this->_filename = $this->_directory.strtolower(Language::getIsoById($this->_cookie->id_lang)).'_googlebase.xml';
    $this->_filename_http = 'http://' . $this->_host . $this->_baseUrl . strtolower(Language::getIsoById($this->_cookie->id_lang)).'_googlebase.xml';
    
    parent::__construct();
    
    /* The parent construct is required for translations */
    $this->page = basename(__FILE__, '.php');
    $this->displayName = $this->l('Google Base Feed Products');
    $this->description = $this->l('Generate your products feed for Google Base. www.ecartservice.net');
  }
 
  public function uninstall()
  {
    foreach(Language::getLanguages() as $lang)
    {
	  @unlink($this->_directory.strtolower($lang['iso_code']).'_googlebase.xml');
    }
    
    parent::uninstall();
  }
 
  private function _postValidation()
  {
    @unlink($this->_filename);
    $fp = fopen($this->_filename, 'wb');
    fclose($fp);
    if (!file_exists($this->_filename))
    {
	  $this->_postErrors[] = $this->l('Cannot write').' '.realpath($this->_filename);
    }
  }
 
  private function _addToFeed($str)
  {
    if(file_exists($this->_filename))
    {
	  $fp = fopen($this->_filename, 'ab');
	  fwrite($fp, $str, strlen($str));
	  fclose($fp);
    }
  }
 
  private function _postProcess()
  {
    $link = new Link();
    $Products = Product::getProducts(intval($this->_cookie->id_lang), 0, NULL, 'id_product', 'ASC');
    
    if($Products)
    {
	  $feedStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\n";
	  $feedStr .= "<rss version =\"2.0\" xmlns:g=\"http://base.google.com/ns/1.0\">\n\n";
Edited by rastreator (see edit history)
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...