Skip to content

Instantly share code, notes, and snippets.

@anddimario
Created November 9, 2019 08:49
Show Gist options
  • Save anddimario/6dc65e2ec555baccbd83d84fcd4fb0a0 to your computer and use it in GitHub Desktop.
Save anddimario/6dc65e2ec555baccbd83d84fcd4fb0a0 to your computer and use it in GitHub Desktop.
Bulk creation of SEO meta title and description for Prestashop
<?php
// Info:
// http://doc.prestashop.com/pages/viewpage.action?pageId=51184692
// Used tables: ps_manufacturer, ps_category_lang, ps_product_lang, ps_product
// Run: php create_meta_product.php
// Clean:
// UPDATE ps_product_lang SET meta_title = "", meta_description="";
require(dirname(__FILE__).'/./config/config.inc.php');
$sql = 'SELECT * FROM '._DB_PREFIX_.'product_lang';
if ($results = Db::getInstance()->ExecuteS($sql))
foreach ($results as $row)
if (!$row['meta_title']) {
$meta_description = '';
$meta_title = '';
echo $row['id_product'].' '.$row['name']."\n\r";
// Get category and manufacturer from product info
$sql_product_info = 'SELECT id_category_default, id_manufacturer FROM '._DB_PREFIX_.'product where id_product = '.$row['id_product'];
$product_info = Db::getInstance()->ExecuteS($sql_product_info);
if (!$product_info)
die('Error get product info.');
// Get manufacturer
$sql_manufacturer = 'SELECT name FROM '._DB_PREFIX_.'manufacturer where id_manufacturer = '.$product_info[0]["id_manufacturer"];
$manufacturer_info = Db::getInstance()->ExecuteS($sql_manufacturer);
if ($manufacturer_info && $manufacturer_info[0]) {
$meta_description .= $manufacturer_info[0]["name"].' ';
$meta_title .= $manufacturer_info[0]["name"].' ';
}
// Get category
$sql_category = 'SELECT name FROM '._DB_PREFIX_.'category_lang where id_category = '.$product_info[0]["id_category_default"];
$category_info = Db::getInstance()->ExecuteS($sql_category);
if ($category_info && $category_info[0]) {
$meta_description .= $category_info[0]["name"].' ';
}
$meta_description .= $row['name'];
$meta_title .= $row['name'];
$sql_meta = 'UPDATE '._DB_PREFIX_.'product_lang SET meta_title = "'.$meta_title.'", meta_description = "'.$meta_description.'" WHERE id_product = "'.$row['id_product'].'"';
if (!Db::getInstance()->execute($sql_meta))
die('Error update meta.');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment