// Fix on shops + remove id_group_shop from stock + fix stock

This commit is contained in:
rMalie
2011-08-11 09:38:24 +00:00
parent 9886cabbfc
commit 59c4f5489d
16 changed files with 110 additions and 109 deletions
+7 -1
View File
@@ -162,6 +162,12 @@ abstract class AdminTabCore
* @var array
*/
public $optionsList = array();
/**
* @since 1.5.0
* @var Context
*/
public $context;
protected $_languages = NULL;
protected $_defaultFormLanguage = NULL;
@@ -1848,7 +1854,7 @@ abstract class AdminTabCore
}
// Display title
echo '<div style="clear: both; padding-top:15px;" id="conf_id_'.$key.'">';
echo '<div style="clear: both; padding-top:15px;" id="conf_id_'.$key.'" '.(($isInvisible) ? 'class="isInvisible"' : '').'>';
if ($field['title'])
{
echo '<label class="conf_title">';
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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;
}
+6 -7
View File
@@ -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];
+23 -39
View File
@@ -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
*
+1 -1
View File
@@ -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");
}
}