diff --git a/admin-dev/tabs/AdminShopUrl.php b/admin-dev/tabs/AdminShopUrl.php index 85c0cee1b..e0a11c2bd 100755 --- a/admin-dev/tabs/AdminShopUrl.php +++ b/admin-dev/tabs/AdminShopUrl.php @@ -61,7 +61,7 @@ class AdminShopUrl extends AdminTab if ($beforeUpdate->main AND !Tools::getValue('main')) $this->_errors[] = Tools::displayError('You must have a main url per shop'); } - if ($object->canAddThisUrl(Tools::getValue('domain'), Tools::getValue('domain_ssl'), Tools::getValue('uri'))) + if ($object->canAddThisUrl(Tools::getValue('domain'), Tools::getValue('domain_ssl'), Tools::getValue('physical_uri'), Tools::getValue('virtual_uri'))) $this->_errors[] = Tools::displayError('A shop url that use this domain and uri already exists'); Tools::generateHtaccess(dirname(__FILE__).'/../../.htaccess', Configuration::get('PS_REWRITING_SETTINGS'), Configuration::get('PS_HTACCESS_CACHE_CONTROL'), ''); diff --git a/classes/AdminTab.php b/classes/AdminTab.php index 8ade4341b..885dfca98 100644 --- a/classes/AdminTab.php +++ b/classes/AdminTab.php @@ -872,6 +872,9 @@ abstract class AdminTabCore protected function updateAssoShop($id_object = false) { + if (!Shop::isMultiShopActivated()) + return ; + $shopAsso = Shop::getAssoTables(); $groupShopAsso = GroupShop::getAssoTables(); if (isset($shopAsso[$this->table]) && $shopAsso[$this->table]['type'] == 'shop') @@ -1300,7 +1303,7 @@ abstract class AdminTabCore else if (!preg_match('#(\s|,)\s*a\.`?'.pSQL($this->identifier).'`?(\s|,|$)#', $this->_group)) $this->_group .= ', a.'.pSQL($this->identifier); - if (Shop::isMultiShopActivated() && Shop::context() == Shop::CONTEXT_ALL) + if (Shop::isMultiShopActivated() && Context::shop() == Shop::CONTEXT_ALL) $filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.' IN ('.implode(', ', $idenfierShop).'))'; } diff --git a/classes/Shop.php b/classes/Shop.php index bae168a0b..be9e3203c 100644 --- a/classes/Shop.php +++ b/classes/Shop.php @@ -256,7 +256,7 @@ class ShopCore extends ObjectModel { if (!$this->theme_name) $this->loadShopInfos(); - return $this->physical_uri.$this->virtual_uri.'/'; + return $this->physical_uri.$this->virtual_uri; } public function getPhysicalURI() diff --git a/classes/ShopUrl.php b/classes/ShopUrl.php index dd7633f46..39b8298df 100755 --- a/classes/ShopUrl.php +++ b/classes/ShopUrl.php @@ -51,13 +51,14 @@ class ShopUrlCore extends ObjectModel parent::validateFields(); $this->physical_uri = trim($this->physical_uri, '/'); - $this->physical_uri .= '/'.$this->physical_uri; if ($this->physical_uri) - $this->physical_uri = preg_replace('#/+#', '/', $this->physical_uri); + $this->physical_uri = preg_replace('#/+#', '/', '/'.$this->physical_uri.'/'); + else + $this->physical_uri = '/'; $this->virtual_uri = trim($this->virtual_uri, '/'); if ($this->virtual_uri) - $this->virtual_uri = '/'.preg_replace('#/+#', '/', trim($this->virtual_uri, '/')); + $this->virtual_uri = preg_replace('#/+#', '/', trim($this->virtual_uri, '/')).'/'; $fields['domain'] = pSQL($this->domain); $fields['domain_ssl'] = pSQL($this->domain_ssl); @@ -94,13 +95,24 @@ class ShopUrlCore extends ObjectModel return $res; } - public function canAddThisUrl($domain, $domain_ssl, $uri) + public function canAddThisUrl($domain, $domain_ssl, $physical_uri, $virtual_uri) { + $physical_uri = trim($physical_uri, '/'); + if ($physical_uri) + $physical_uri = preg_replace('#/+#', '/', '/'.$physical_uri.'/'); + else + $this->physical_uri = '/'; + + $virtual_uri = trim($virtual_uri, '/'); + if ($virtual_uri) + $virtual_uri = preg_replace('#/+#', '/', trim($virtual_uri, '/')).'/'; + $sql = 'SELECT id_shop_url FROM '._DB_PREFIX_.'shop_url - WHERE uri=\''.pSQL($uri).'\' - AND (domain=\''.pSQL($domain).'\' '.(($domain_ssl) ? 'OR domain_ssl=\''.pSQL($domain_ssl).'\'' : '').')' - .($this->id ? ' AND id_shop_url !='.(int)$this->id : ''); + WHERE physical_uri = \''.pSQL($physical_uri).'\' + AND virtual_uri = \''.pSQL($virtual_uri).'\' + AND (domain = \''.pSQL($domain).'\' '.(($domain_ssl) ? ' OR domain_ssl = \''.pSQL($domain_ssl).'\'' : '').')' + .($this->id ? ' AND id_shop_url != '.(int)$this->id : ''); return Db::getInstance()->getValue($sql); } @@ -126,4 +138,3 @@ class ShopUrlCore extends ObjectModel return self::$main_domain_ssl; } } - diff --git a/install-dev/php/create_multistore.php b/install-dev/php/create_multistore.php index 030fe642a..7671ac1c5 100755 --- a/install-dev/php/create_multistore.php +++ b/install-dev/php/create_multistore.php @@ -20,8 +20,11 @@ function create_multistore() $shop_domain = Tools::getHttpHost(); $shop_domain_ssl = Tools::getHttpHost(); } + + $_PS_DIRECTORY_ = trim(str_replace(' ', '%20', INSTALLER__PS_BASE_URI), '/'); + $_PS_DIRECTORY_ = ($_PS_DIRECTORY_) ? '/'.$_PS_DIRECTORY_.'/' : '/'; $res &= Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'shop_url` (`id_shop`, `domain`, `domain_ssl`, `physical_uri`, `virtual_uri`, `main`, `active`) - VALUES(1, \''.pSQL($shop_domain).'\', \''.pSQL($shop_domain_ssl).'\',, \'\' \'\', 1, 1)'); + VALUES(1, \''.pSQL($shop_domain).'\', \''.pSQL($shop_domain_ssl).'\', \''.pSQL($_PS_DIRECTORY_).'\', \'\', 1, 1)'); // Stock conversion $sql = 'INSERT INTO `'._DB_PREFIX_.'.stock` (`id_product`, `id_product_attribute`, `id_group_shop`, `id_shop`, `quantity`) diff --git a/install-dev/xml/createDB.php b/install-dev/xml/createDB.php index 6ba81af57..4b22c4b05 100644 --- a/install-dev/xml/createDB.php +++ b/install-dev/xml/createDB.php @@ -63,7 +63,8 @@ foreach ($data_check AS $data) // Writing data in settings file $oldLevel = error_reporting(E_ALL); -$_PS_DIRECTORY_ = str_replace(' ', '%20', INSTALLER__PS_BASE_URI); +$_PS_DIRECTORY_ = trim(str_replace(' ', '%20', INSTALLER__PS_BASE_URI), '/'); +$_PS_DIRECTORY_ = ($_PS_DIRECTORY_) ? '/'.$_PS_DIRECTORY_.'/' : '/'; $datas = array( array('_DB_SERVER_', trim($_GET['server'])), array('_DB_TYPE_', trim($_GET['type'])), @@ -181,7 +182,7 @@ switch (_DB_TYPE_) { die(''."\n"); } } - $db_data_settings .= "\n".'INSERT INTO `PREFIX_shop_url` (`id_shop`, `domain`, `domain_ssl`, `physical_uri`, `virtual_uri`, `main`, `active`) VALUES(1, \''.pSQL(Tools::getHttpHost()).'\', \''.pSQL(Tools::getHttpHost()).'\', \''.pSQL('/'.trim($_PS_DIRECTORY_, '/')).'\', \'\', 1, 1);'; + $db_data_settings .= "\n".'INSERT INTO `PREFIX_shop_url` (`id_shop`, `domain`, `domain_ssl`, `physical_uri`, `virtual_uri`, `main`, `active`) VALUES(1, \''.pSQL(Tools::getHttpHost()).'\', \''.pSQL(Tools::getHttpHost()).'\', \''.pSQL($_PS_DIRECTORY_).'\', \'\', 1, 1);'; $db_data_settings .= "\n".'UPDATE `PREFIX_customer` SET `passwd` = \''.md5(_COOKIE_KEY_.'123456789').'\' WHERE `id_customer` =1;'; $db_data_settings .= "\n".'INSERT INTO `PREFIX_configuration` (name, value, date_add, date_upd) VALUES (\'PS_VERSION_DB\', \'' . INSTALL_VERSION . '\', NOW(), NOW());'; $db_data_settings = str_replace(array($filePrefix, $engineType), array($_GET['tablePrefix'], $_GET['engine']), $db_data_settings);