';
+ echo '
';
if ($field['title'])
{
echo '';
diff --git a/classes/Attribute.php b/classes/Attribute.php
index e34dd3669..1b873289e 100644
--- a/classes/Attribute.php
+++ b/classes/Attribute.php
@@ -126,7 +126,7 @@ class AttributeCore extends ObjectModel
$sql = 'SELECT quantity
FROM '._DB_PREFIX_.'stock
WHERE id_product_attribute = '.(int)$id_product_attribute
- .$shop->sqlSharedStock();
+ .$shop->sqlRestriction(Shop::SHARE_STOCK);
$result = (int)Db::getInstance()->getValue($sql);
return ($result AND $qty <= $result);
diff --git a/classes/Link.php b/classes/Link.php
index 3614a08a9..18c0f8ca3 100644
--- a/classes/Link.php
+++ b/classes/Link.php
@@ -311,7 +311,7 @@ class LinkCore
$uri_path = Dispatcher::getInstance()->createUrl($controller);
$url = ($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true);
$url .= __PS_BASE_URI__.$this->getLangLink($id_lang).ltrim($uri_path, '/');
- $url .= ($request ? (($this->allow ? '?' : '&').trim($request)) : '');
+ $url .= ($request ? ((strpos($url, '?') === false ? '?' : '&').trim($request)) : '');
return $url;
}
diff --git a/classes/Product.php b/classes/Product.php
index 0aa47e3d7..ff38ddc2f 100644
--- a/classes/Product.php
+++ b/classes/Product.php
@@ -2012,7 +2012,7 @@ class ProductCore extends ObjectModel
else if (is_string($productAttribute))
$sql .= ' AND stock.id_product_attribute = IFNULL('.pSQL($productAttribute).'.id_product_attribute, 0)';
}
- $sql .= $shop->sqlSharedStock('stock') . ' ';
+ $sql .= $shop->sqlRestriction(Shop::SHARE_STOCK, 'stock') . ' ';
return $sql;
}
@@ -2070,8 +2070,7 @@ class ProductCore extends ObjectModel
Db::getInstance()->autoExecute(_DB_PREFIX_.'stock', array(
'id_product' => $this->id,
'id_product_attribute' => $id_product_attribute,
- 'id_shop' => $shop->getID(),
- 'id_group_shop' => $shop->getGroupID(),
+ 'id_shop' => $shop->getID(true),
'quantity' => $quantity,
), 'INSERT');
}
@@ -2088,12 +2087,11 @@ class ProductCore extends ObjectModel
Db::getInstance()->autoExecute(_DB_PREFIX_.'stock', array(
'id_product' => $this->id,
'id_product_attribute' => 0,
- 'id_shop' => $shop->getID(),
- 'id_group_shop' => $shop->getGroupID(),
+ 'id_shop' => $shop->getID(true),
'quantity' => $quantity,
), 'INSERT');
- self::$cacheStock[$this->id][$id_product_attribute] = null;
+ self::$cacheStock[$shop->getID(true)][$this->id][$id_product_attribute] = null;
}
/**
@@ -2111,13 +2109,14 @@ class ProductCore extends ObjectModel
if (!$context)
$context = Context::getContext();
+ $id_shop = $shop->getID(true);
if (!isset(self::$cacheStock[$this->id][$id_product_attribute]))
{
$sql = 'SELECT quantity
FROM '._DB_PREFIX_.'stock
WHERE id_product = '.$this->id.'
AND id_product_attribute = '.(int)$id_product_attribute
- .$context->shop->sqlSharedStock();
+ .$context->shop->sqlRestriction(Shop::SHARE_STOCK);
self::$cacheStock[$this->id][$id_product_attribute] = (int)Db::getInstance()->getValue($sql);
}
return self::$cacheStock[$this->id][$id_product_attribute];
diff --git a/classes/Shop.php b/classes/Shop.php
index be9e3203c..2a28d680d 100644
--- a/classes/Shop.php
+++ b/classes/Shop.php
@@ -105,6 +105,7 @@ class ShopCore extends ObjectModel
*/
const SHARE_CUSTOMER = 'share_customer';
const SHARE_ORDER = 'share_order';
+ const SHARE_STOCK = 'share_stock';
public function getFields()
{
@@ -181,32 +182,32 @@ class ShopCore extends ObjectModel
$excluded_uris[] = $directory;
// Find current shop from URL
- $sql = 'SELECT s.id_shop, CONCAT(su.physical_uri, su.virtual_uri) AS uri
- FROM '._DB_PREFIX_.'shop_url su
- LEFT JOIN '._DB_PREFIX_.'shop s ON (s.id_shop = su.id_shop)
- WHERE su.domain=\''.pSQL(Tools::getHttpHost()).'\'
- AND s.active = 1
- AND s.deleted = 0
- ORDER BY LENGTH(uri) DESC';
-
- $id_shop = '';
- if ($results = Db::getInstance()->executeS($sql))
- foreach ($results as $row)
- {
- if (preg_match('#^'.preg_quote($row['uri'], '#').'#', $_SERVER['REQUEST_URI']))
+ if (!$id_shop = Tools::getValue('id_shop'))
+ {
+ $sql = 'SELECT s.id_shop, CONCAT(su.physical_uri, su.virtual_uri) AS uri
+ FROM '._DB_PREFIX_.'shop_url su
+ LEFT JOIN '._DB_PREFIX_.'shop s ON (s.id_shop = su.id_shop)
+ WHERE su.domain = \''.pSQL(Tools::getHttpHost()).'\'
+ AND s.active = 1
+ AND s.deleted = 0
+ ORDER BY LENGTH(uri) DESC';
+
+ $id_shop = '';
+ if ($results = Db::getInstance()->executeS($sql))
+ foreach ($results as $row)
{
- $id_shop = $row['id_shop'];
- break;
+ if (preg_match('#^'.preg_quote($row['uri'], '#').'#', $_SERVER['REQUEST_URI']))
+ {
+ $id_shop = $row['id_shop'];
+ break;
+ }
}
- }
-
- if (!$id_shop)
- die('Shop not found ... redirect me please !');
+ }
// Get instance of found shop
$shop = new Shop($id_shop);
if (!Validate::isLoadedObject($shop))
- die(Tools::displayError());
+ $shop = new Shop(1);
return $shop;
}
@@ -471,12 +472,12 @@ class ShopCore extends ObjectModel
* If the shop group has the option $type activated, get all shops ID of this group, else get current shop ID
*
* @param int $shopID
- * @param int $type Shop::SHARE_CUSTOMER or Shop::SHARE_ORDER
+ * @param int $type Shop::SHARE_CUSTOMER | Shop::SHARE_ORDER | Shop::SHARE_STOCK
* @return array
*/
public static function getSharedShops($shopID, $type)
{
- if (!in_array($type, array(Shop::SHARE_CUSTOMER, Shop::SHARE_ORDER)))
+ if (!in_array($type, array(Shop::SHARE_CUSTOMER, Shop::SHARE_ORDER, Shop::SHARE_STOCK)))
die('Wrong argument ($type) in Shop::getSharedShops() method');
Shop::cacheShops();
@@ -626,23 +627,6 @@ class ShopCore extends ObjectModel
return $restriction;
}
- public function sqlSharedStock($alias = null)
- {
- if ($alias)
- $alias .= '.';
-
- $shopID = $this->getID();
- $shopGroupID = $this->getGroupID();
- if (!$shopID)
- return ($shopGroupID) ? ' AND '.$alias.'id_group_shop = '.(int)$shopGroupID : '';
-
- Shop::cacheShops();
- foreach (self::$shops as $groupID => $groupData)
- if (array_key_exists($shopID, $groupData['shops']) && $groupData['share_stock'])
- return ' AND '.$alias.'id_group_shop = '.$groupID;
- return ' AND '.$alias.'id_shop = '.$shopID;
- }
-
/**
* Add an SQL JOIN in query between a table and its associated table in multishop
*
diff --git a/classes/Tools.php b/classes/Tools.php
index 9e740d54b..61e62e56a 100644
--- a/classes/Tools.php
+++ b/classes/Tools.php
@@ -1591,7 +1591,7 @@ class ToolsCore
if ($uri['virtual'])
{
fwrite($writeFd, 'RewriteCond %{HTTP_HOST} ^'.$domain.'$'."\n");
- fwrite($writeFd, "RewriteRule ^".ltrim($uri['virtual'], '/')."(.*) ".$uri['physical']."/$1 [L]\n\n");
+ fwrite($writeFd, "RewriteRule ^".ltrim($uri['virtual'], '/')."(.*) ".$uri['physical']."$1 [L]\n\n");
}
}
diff --git a/install-dev/sql/db.sql b/install-dev/sql/db.sql
index a1b44d67c..dc16f1877 100644
--- a/install-dev/sql/db.sql
+++ b/install-dev/sql/db.sql
@@ -1767,14 +1767,14 @@ CREATE TABLE `PREFIX_stock` (
`id_stock` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_product` INT( 11 ) UNSIGNED NOT NULL,
`id_product_attribute` INT( 11 ) UNSIGNED NOT NULL,
-`id_group_shop` INT( 11 ) UNSIGNED NOT NULL,
`id_shop` INT(11) UNSIGNED NOT NULL,
`quantity` INT(11) NOT NULL,
PRIMARY KEY (`id_stock`),
KEY `id_product` (`id_product`),
- KEY `id_product_attribute` (`id_product_attribute`),
+ KEY `id_product_attribute` (`id_product_attribute`),
KEY `id_group_shop` (`id_group_shop`),
- KEY `id_shop` (`id_shop`)
+ KEY `id_shop` (`id_shop`),
+ UNIQUE KEY `product_stock` (`id_product` ,`id_product_attribute` ,`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_country_shop` (
diff --git a/install-dev/sql/db_settings_extends.sql b/install-dev/sql/db_settings_extends.sql
index 06a132097..bf2639579 100644
--- a/install-dev/sql/db_settings_extends.sql
+++ b/install-dev/sql/db_settings_extends.sql
@@ -1127,34 +1127,34 @@ INSERT INTO `PREFIX_store` (`id_store`, `id_country`, `id_state`, `name`, `addre
INSERT INTO `PREFIX_store_shop` (`id_store`, `id_shop`) (SELECT `id_store`, 1 FROM `PREFIX_store`);
-INSERT INTO `PREFIX_stock` (`id_stock`, `id_product`, `id_product_attribute`, `id_group_shop`, `id_shop`, `quantity`) VALUES
-(1, 1, 25, 1, 1, 150),
-(2, 1, 26, 1, 1, 120),
-(3, 1, 27, 1, 1, 230),
-(4, 1, 28, 1, 1, 150),
-(5, 1, 29, 1, 1, 120),
-(6, 1, 30, 1, 1, 230),
-(7, 1, 31, 1, 1, 150),
-(8, 1, 32, 1, 1, 120),
-(9, 1, 33, 1, 1, 230),
-(10, 1, 34, 1, 1, 150),
-(11, 1, 35, 1, 1, 120),
-(12, 1, 36, 1, 1, 230),
-(13, 1, 39, 1, 1, 150),
-(14, 1, 40, 1, 1, 120),
-(15, 1, 41, 1, 1, 230),
-(16, 1, 42, 1, 1, 150),
-(17, 2, 7, 1, 1, 120),
-(18, 2, 8, 1, 1, 230),
-(19, 2, 9, 1, 1, 150),
-(20, 2, 10, 1, 1, 120),
-(21, 5, 12, 1, 1, 230),
-(22, 5, 13, 1, 1, 150),
-(23, 5, 14, 1, 1, 120),
-(24, 5, 15, 1, 1, 230),
-(25, 6, 0, 1, 1, 230),
-(26, 7, 19, 1, 1, 150),
-(27, 7, 22, 1, 1, 120),
-(28, 7, 23, 1, 1, 230),
-(29, 8, 0, 1, 1, 230),
-(30, 9, 0, 1, 1, 150);
\ No newline at end of file
+INSERT INTO `PREFIX_stock` (`id_stock`, `id_product`, `id_product_attribute`, `id_shop`, `quantity`) VALUES
+(1, 1, 25, 1, 150),
+(2, 1, 26, 1, 120),
+(3, 1, 27, 1, 230),
+(4, 1, 28, 1, 150),
+(5, 1, 29, 1, 120),
+(6, 1, 30, 1, 230),
+(7, 1, 31, 1, 150),
+(8, 1, 31, 1, 120),
+(9, 1, 33, 1, 230),
+(10, 1, 34, 1, 150),
+(11, 1, 35, 1, 120),
+(12, 1, 36, 1, 230),
+(13, 1, 39, 1, 150),
+(14, 1, 40, 1, 120),
+(15, 1, 41, 1, 230),
+(16, 1, 42, 1, 150),
+(17, 2, 7, 1, 120),
+(18, 2, 8, 1, 230),
+(19, 2, 9, 1, 150),
+(20, 2, 10, 1, 120),
+(21, 5, 12, 1, 230),
+(22, 5, 13, 1, 150),
+(23, 5, 14, 1, 120),
+(24, 5, 15, 1, 230),
+(25, 6, 0, 1, 230),
+(26, 7, 19, 1, 150),
+(27, 7, 22, 1, 120),
+(28, 7, 23, 1, 230),
+(29, 8, 0, 1, 230),
+(30, 9, 0, 1, 150);
\ No newline at end of file
diff --git a/install-dev/sql/upgrade/1.5.0.0.sql b/install-dev/sql/upgrade/1.5.0.0.sql
index 153b93200..b8934fdad 100755
--- a/install-dev/sql/upgrade/1.5.0.0.sql
+++ b/install-dev/sql/upgrade/1.5.0.0.sql
@@ -65,18 +65,18 @@ CREATE TABLE `PREFIX_stock` (
`id_stock` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_product` INT( 11 ) UNSIGNED NOT NULL,
`id_product_attribute` INT( 11 ) UNSIGNED NOT NULL,
-`id_group_shop` INT( 11 ) UNSIGNED NOT NULL,
`id_shop` INT(11) UNSIGNED NOT NULL,
`quantity` INT(11) NOT NULL,
PRIMARY KEY (`id_stock`),
KEY `id_product` (`id_product`),
- KEY `id_product_attribute` (`id_product_attribute`),
+ KEY `id_product_attribute` (`id_product_attribute`),
KEY `id_group_shop` (`id_group_shop`),
- KEY `id_shop` (`id_shop`)
+ KEY `id_shop` (`id_shop`),
+ UNIQUE KEY `product_stock` (`id_product` ,`id_product_attribute` ,`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
-INSERT INTO `PREFIX_stock` (id_product, id_group_shop, id_shop) (SELECT p.id_product, 1, 1 FROM PREFIX_product p LEFT JOIN PREFIX_product_attribute pa ON (p.id_product = pa.id_product) WHERE pa.id_product_attribute IS NULL);
-INSERT INTO `PREFIX_stock` (id_product, id_product_attribute, id_group_shop, id_shop) (SELECT id_product, id_product_attribute, 1, 1 FROM PREFIX_product_attribute);
+INSERT INTO `PREFIX_stock` (id_product, id_shop) (SELECT p.id_product, 1 FROM PREFIX_product p LEFT JOIN PREFIX_product_attribute pa ON (p.id_product = pa.id_product) WHERE pa.id_product_attribute IS NULL);
+INSERT INTO `PREFIX_stock` (id_product, id_product_attribute, id_shop) (SELECT id_product, id_product_attribute, 1 FROM PREFIX_product_attribute);
CREATE TABLE `PREFIX_country_shop` (
`id_country` INT( 11 ) UNSIGNED NOT NULL,
diff --git a/js/admin.js b/js/admin.js
index 7fbd96c61..8bf510091 100644
--- a/js/admin.js
+++ b/js/admin.js
@@ -839,10 +839,15 @@ $(document).ready(function()
function checkMultishopDefaultValue(obj, key)
{
- $('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select').attr('disabled', $(obj).attr('checked'));
- $('#conf_id_'+key+' .preference_default_multishop input').attr('disabled', false);
- if ($(obj).attr('checked'))
+ if ($(obj).attr('checked') || $('#'+key).hasClass('isInvisible'))
+ {
+ $('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select').attr('disabled', true);
$('#conf_id_'+key+' label.conf_title').addClass('isDisabled');
+ }
else
+ {
+ $('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select').attr('disabled', false);
$('#conf_id_'+key+' label.conf_title').removeClass('isDisabled');
+ }
+ $('#conf_id_'+key+' .preference_default_multishop input').attr('disabled', false);
}
\ No newline at end of file
diff --git a/modules/mailalerts/mailalerts.php b/modules/mailalerts/mailalerts.php
index 3d1c968af..5850032af 100644
--- a/modules/mailalerts/mailalerts.php
+++ b/modules/mailalerts/mailalerts.php
@@ -329,7 +329,7 @@ class MailAlerts extends Module
$sql = 'SELECT id_product, quantity
FROM '._DB_PREFIX_.'stock
WHERE id_product_attribute = '.(int)$params['id_product_attribute']
- .Context::getContext()->sqlSharedStock();
+ .Context::getContext()->shop->sqlRestriction(Shop::SHARE_STOCK);
$result = Db::getInstance()->getRow($sql);
if ($this->_customer_qty AND $result['quantity'] > 0)