From 258ba2829c8e8280e9770048af4a009153f8567a Mon Sep 17 00:00:00 2001 From: vChabot Date: Mon, 21 May 2012 08:20:19 +0000 Subject: [PATCH] [-] BO : BugFix : #PSCFV-2465 : When creating a shop without importing categories, I can still see the default category from other shop --- classes/shop/Shop.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index ef6433b5e..66888884b 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -806,10 +806,22 @@ class ShopCore extends ObjectModel if (isset($row['primary'])) unset($res[$row['primary']]); - $keys = implode('`, `', array_keys($res)); - $sql = 'INSERT IGNORE INTO `'._DB_PREFIX_.$table_name.'` (`'.$keys.'`, '.$id.') + $categories = Tools::getValue('categoryBox'); + if ($table_name == 'product_shop' && count($categories) > 0) + { + unset($res['id_category_default']); + $keys = implode('`, `', array_keys($res)); + $sql = 'INSERT IGNORE INTO `'._DB_PREFIX_.$table_name.'` (`'.$keys.'`, `id_category_default`, '.$id.') + (SELECT `'.$keys.'`, '.(int)$categories[0].', '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.' + WHERE `'.$id.'` = '.(int)$old_id.')'; + } + else + { + $keys = implode('`, `', array_keys($res)); + $sql = 'INSERT IGNORE INTO `'._DB_PREFIX_.$table_name.'` (`'.$keys.'`, '.$id.') (SELECT `'.$keys.'`, '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.' WHERE `'.$id.'` = '.(int)$old_id.')'; + } Db::getInstance()->execute($sql); } }