bebeboutik/modules/ant_configurations/cron_reorder_braderie.php
2017-05-12 12:18:24 +02:00

63 lines
2.2 KiB
PHP

<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
include dirname(__FILE__).'/../../config/config.inc.php';
$categories = array();
foreach(Db::getInstance()->ExecuteS('
SELECT pc.`id_category`
FROM `'._DB_PREFIX_.'privatesale_category` pc
LEFT JOIN `'._DB_PREFIX_.'privatesale` p ON (p.id_sale = pc.id_sale)
WHERE p.`braderie` = 1
') as $c){
$categories[] = $c['id_category'];
}
foreach ($categories as $key => $id_category) {
$products = Db::getInstance()->ExecuteS('
SELECT cp.`id_product`
FROM `'._DB_PREFIX_.'category_product` cp
RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product=p.id_product AND pl.`id_lang` = 1)
WHERE cp.id_category ='.(int)$id_category.' AND p.quantity != 0
ORDER BY cp.`position`
');
if($products){
foreach ($products as $key => $product) {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'category_product`
SET `position` = '. (int)($key) .'
WHERE `id_product` = '.(int)($product['id_product']).'
AND `id_category`='.(int)$id_category
);
}
}
$products_zero = Db::getInstance()->ExecuteS('
SELECT cp.`id_product`
FROM `'._DB_PREFIX_.'category_product` cp
RIGHT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product=cp.id_product)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product=p.id_product AND pl.`id_lang` = 1)
WHERE cp.id_category ='.(int)$id_category.' AND p.quantity = 0
ORDER BY cp.`position`
');
if($products_zero){
$position = count($products);
foreach ($products_zero as $key => $product) {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'category_product`
SET `position` = '. (int)($position) .'
WHERE `id_product` = '.(int)($product['id_product']).'
AND `id_category`='.(int)$id_category
);
$position++;
}
}
}