From f9a3af2d6bba48e2231deae221c9523df8bc6074 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Wed, 17 May 2017 12:20:24 +0200 Subject: [PATCH] script to associate product with category 83 --- bin/add_products_categoryall.php | 69 ++++++++++++++++++++++++++++++++ bin/index.php | 35 ++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 bin/add_products_categoryall.php create mode 100644 bin/index.php diff --git a/bin/add_products_categoryall.php b/bin/add_products_categoryall.php new file mode 100644 index 00000000..5944d7f5 --- /dev/null +++ b/bin/add_products_categoryall.php @@ -0,0 +1,69 @@ +executeS($sql); +$pIdExist = array(); +if (count($existResult) == 0) { + echo date('Y-m-d H:i:s')." - Aucun produit trouvé.\n"; + exit(1); +} else { + foreach($existResult as $item) { + $pIdExist[] = $item['id_product']; + } +} + +// Selection de la position max pour increment +$sql = "SELECT MAX(position) AS max FROM "._DB_PREFIX_."category_product WHERE id_category = 83"; +$result = Db::getInstance()->getRow($sql); +if ($result !== false) { + $max = $result['max']; +} + +echo date('Y-m-d H:i:s')." - Valeur increment = ".$max."\n"; + +// Selection de tous les produits +$sql = "SELECT id_product FROM "._DB_PREFIX_."product ORDER BY id_product ASC"; +$productResult = Db::getInstance()->executeS($sql); + +// Lier les produits dans ps_category_product +if (count($productResult) > 0) { + $insertSql = "INSERT INTO "._DB_PREFIX_."category_product (id_category, id_product, position) VALUES\n"; + foreach ($productResult as $p) { + if (!in_array($p['id_product'], $pIdExist)) { + $max++; + $insertSql.= "(".$categoryId.",".$p['id_product'].",".$max."),\n"; + } + } + $insertSql = substr_replace($insertSql, ";\n", -2); + if ($optDebug) { + echo $insertSql; + } else { + $result = Db::getInstance()->execute($insertSql); + if ($result) { + echo date('Y-m-d H:i:s')." - Insertion OK\n"; + } else { + echo date('Y-m-d H:i:s')." - Insertion ERREUR\n"; + } + } +} \ No newline at end of file diff --git a/bin/index.php b/bin/index.php new file mode 100644 index 00000000..ffdebb42 --- /dev/null +++ b/bin/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2015 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit;