// Fix main flag for shop_url when a shop_url is updated

This commit is contained in:
rMalie
2011-10-11 13:32:18 +00:00
parent 7b392d6233
commit a114eec8b3
+12 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -93,6 +93,17 @@ class ShopUrlCore extends ObjectModel
$res &= Db::getInstance()->autoExecute(_DB_PREFIX_.'shop_url', array('main' => 1), 'UPDATE', 'id_shop_url = '.(int)$this->id);
$this->main = true;
// Reset main URL for all shops to prevent problems
$sql = 'SELECT s1.id_shop_url FROM '._DB_PREFIX_.'shop_url s1
WHERE (
SELECT COUNT(*) FROM '._DB_PREFIX_.'shop_url s2
WHERE s2.main = 1
AND s2.id_shop = s1.id_shop
) = 0
GROUP BY s1.id_shop';
foreach (Db::getInstance()->executeS($sql) as $row)
Db::getInstance()->autoExecute(_DB_PREFIX_.'shop_url', array('main' => 1), 'UPDATE', 'id_shop_url = '.$row['id_shop_url']);
return $res;
}