I have a free Google Merchant datafeed generator and it works fine. My trouble is trying to modify the php file correctly to produce google's recommended specifications which is google product category and google product type. So my question is where and what do I need to insert to my googlemerchant.php file? I just want the output to be the same for each product_category and each product_ type.
For example each product category will be Apparel & Accessories > Clothing > Dresses
Each product type will be Apparel & Accessories > Clothing > Dresses > Summer
Here's a copy of the php file so someone can take a look at it. If I could afford the paid module I would buy it so your help is very much appreciated.
<?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 Merchant Center Feed'); $this->description = $this->l('Generate your feed for Google Merchant Center'); $this->_baseUrl = __PS_BASE_URI__; $this->_directory = dirname(__FILE__).'/../../'; $this->_filename = $this->_directory.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('Welcome to google merchant center for Prestashop.').'</h2>'; $this->_html .= '<h4>'.$this->l('For support email
[email protected]').'</h4>'; $this->_configureMain(); $this->_html .= ' <fieldset> <legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Feedfile Information').'</legend>'; $this->_html .= '<p>'.$this->l('Your Google Base feed file is online at the following address:').'<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('Configure Main').'</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('Feed Description').'</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('Preferred 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('Generate feed file') : $this->l('Update feed file')).'" 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'; // DO NOT CHANGE!!!! $langPrefix = strtolower(Language::getIsoById($this->_currLID)); $expire_date = date('Y-m-d', strtotime("+30 days")); $feedStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; $feedStr .= "<rss version =\"2.0\" xmlns:g=\"http://base.google.com/ns/1.0\">\n"; $feedStr .= "<channel>\n"; $feedStr .= '<title>'.Configuration::get('GOOGLEMERCHANT_FEEDTITLE').'</title>'."\n"; $feedStr .= '<description>'.Configuration::get('GOOGLEMERCHANT_FEEDDESC').'</description>'."\n"; foreach ($productArray AS $product) { if ($product['active']) { $image = Image::getImages($this->_currLID, $product['id_product']); $productLink = $link->getProductLink($product['id_product'], $product['link_rewrite']); $productPrice = Product::getPriceStatic(intval($product['id_product'])); $feedStr .= "<item>\n"; // ---- Item Fields Required by Google Merchant Center ---- $feedStr .= '<g:id>'.$feedPrefix.$langPrefix."-".$product['id_product']."</g:id>\n"; $feedStr .= '<title>'.$this->_XMLSafe($product['name'])."</title>\n"; $feedStr .= '<link>'. $this->_XMLSafe($productLink)."</link>\n"; $feedStr .= '<g:price>'.$productPrice."</g:price>\n"; $feedStr .= '<description>'.$this->_XMLSafe($product['description_short'])."</description>\n"; $feedStr .= "<g:condition>new</g:condition>\n"; $feedStr .= "<g:availability>in stock</g:availability>\n"; $feedStr .= "<g:condition>new</g:condition>\n"; // ---- End required GMC fields ---- $feedStr .= $this->_getGtinXML($product); $feedStr .= '<g:brand>'.$this->_XMLSafe($product['manufacturer_name'])."</g:brand>\n"; $feedStr .= "<g:expiration_date>$expire_date</g:expiration_date>\n"; $feedStr .= "</item>\n"; $feedStr .= "\n"; } } $feedStr .= "</channel>\n"; $feedStr .= "</rss>\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>'; } } ?>