script to associate product with category 83
This commit is contained in:
parent
58a7b2fc56
commit
f9a3af2d6b
69
bin/add_products_categoryall.php
Normal file
69
bin/add_products_categoryall.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Association de tous les produits à la catégorie 183 "Tous les produits"
|
||||
*/
|
||||
|
||||
$optsLong = array(
|
||||
"debug",
|
||||
);
|
||||
$opts = getopt("", $optsLong);
|
||||
|
||||
$optDebug = false;
|
||||
if (array_key_exists('debug', $opts)) {
|
||||
$optDebug = true;
|
||||
}
|
||||
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
require_once dirname(__FILE__).'/../config/config.inc.php';
|
||||
|
||||
echo date('Y-m-d H:i:s')." - Associations produit / category .\n";
|
||||
|
||||
$categoryId = 83;
|
||||
|
||||
// Selection des produits déjà associés
|
||||
$sql = "SELECT id_product FROM "._DB_PREFIX_."category_product WHERE id_category = ".$categoryId;
|
||||
$existResult = Db::getInstance()->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";
|
||||
}
|
||||
}
|
||||
}
|
35
bin/index.php
Normal file
35
bin/index.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2015 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @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;
|
Loading…
Reference in New Issue
Block a user