1sweetman Posted January 8, 2013 Share Posted January 8, 2013 Hi, have in the past been using this code for a basic google feed <?php ///////////////////////////////////////////////////////////////////////////////////////////////////// // PHP Prestashop Product Export for Google Base Version 0.1 //Include the config files required ///////////////////////////////////////////////////////////////////////////////////////////////////// include_once(dirname(__FILE__).'/config/config.inc.php'); include_once(dirname(__FILE__).'/init.php'); include_once(dirname(__FILE__).'/classes/AdminTab.php'); function getproductLinks($product_id,$link_rewrite){ $link = new Link(); // create an object to get product links $product = new Product($product_id, true); //get an object containing the prodcuct $productlink = $link->getProductLink($product_id); //get the products url link //add product row in to the array $rewrited_url = $link->getProductLink($product->id, $product->link_rewrite); $category = new Category($product->id_category_default, 1); $catalias = $category->getLinkRewrite($product->id_category_default, 1); $productLink = "http://" . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').'/'.$catalias.'/'.$product_id.'-'.$link_rewrite.'.html'; $images = $product->getCover($product_id); // get the cover image link $imagelink = "http://" . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').$link->getImageLink($product->link_rewrite[1], $product->id .'-'. $images['id_image'],'large'); $links = array($productLink,$imagelink); return $links; //return the links in an array } //Define Query to return the product data $sql='SELECT p.`id_product`, price, `name`, `description`, `link_rewrite` FROM `ps_product` as p LEFT JOIN `ps_product_lang` pl ON (pl.`id_product` = p.`id_product`) WHERE pl.`id_lang`= 1 GROUP BY p.`id_product`'; $delimiter = ","; // set a delimiter $result = Db::getInstance()->Execute($sql); $productdump = array(); while ($row = mysql_fetch_assoc($result)) { // add sql results to array $productdump[] = $row; } for ($i = 0; $i < sizeof($productdump); $i++){ //Round the price to 2 Decimal places $productdump[$i]['price'] = round($productdump[$i]['price'],2); //round up the price to 2 decimal places //Tidy the Product description field - remove the html tags $productdump[$i]['description'] = strip_tags($productdump[$i]['description']); // add the condition of our product range which happens to be new. $productdump[$i]['condition'] = 'new'; //get the product links $links = getproductLinks($productdump[$i]['id_product'],$productdump[$i]['link_rewrite']); $productdump[$i] ['product_url'] = $links['0']; $productdump[$i] ['product_image_url'] = $links['1']; unset ($productdump[$i]['link_rewrite']); //drop the link_rewrite from the array we don't need it now we have got our links } $fileName = 'products_stream.csv'; header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header('Content-Description: File Transfer'); header("Content-type: text/csv;charset=UTF-8"); header("Content-Disposition: attachment; filename={$fileName}"); header("Expires: 0"); header("Pragma: public"); //Let's write our file //$fp = fopen('file.csv','w'); $fp = @fopen( 'php://output', 'w' ); //Let's set the column headers $column_header = array('id','price','title','description','condition','link','image_link'); fputcsv($fp,$column_header,","); //fputcsv($fp,$column_header,"\t"); //now write the product rows foreach ($productdump as $fields){ fputcsv($fp, $fields,","); //fputcsv($fp, $fields,"\t"); } fclose($fp); ?> But it no longer works with version 1.5.2 of Prestashop which I have now updated to. Can anyone suggest what needs changing to get it working again (or another free alternative). Many thanks in advance Link to comment Share on other sites More sharing options...
JensFindings Posted August 2, 2013 Share Posted August 2, 2013 Hi, did you ever get this working in 1.5.2? Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts