// Cookies subdomain & bug fix on stocks
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@16110 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+20
-5
@@ -59,7 +59,7 @@ class CookieCore
|
||||
* @param $name Cookie name before encrypting
|
||||
* @param $path
|
||||
*/
|
||||
public function __construct($name, $path = '', $expire = null)
|
||||
public function __construct($name, $path = '', $expire = null, $shared_urls = null)
|
||||
{
|
||||
$this->_content = array();
|
||||
$this->_expire = isset($expire) ? (int)($expire) : (time() + 1728000);
|
||||
@@ -71,7 +71,7 @@ class CookieCore
|
||||
$this->_path = str_replace('%7E', '~', $this->_path);
|
||||
$this->_key = _COOKIE_KEY_;
|
||||
$this->_iv = _COOKIE_IV_;
|
||||
$this->_domain = $this->getDomain();
|
||||
$this->_domain = $this->getDomain($shared_urls);
|
||||
if (Configuration::get('PS_CIPHER_ALGORITHM'))
|
||||
$this->_cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_);
|
||||
else
|
||||
@@ -79,7 +79,7 @@ class CookieCore
|
||||
$this->update();
|
||||
}
|
||||
|
||||
protected function getDomain()
|
||||
protected function getDomain($shared_urls = null)
|
||||
{
|
||||
$r = '!(?:(\w+)://)?(?:(\w+)\:(\w+)@)?([^/:]+)?(?:\:(\d*))?([^#?]+)?(?:\?([^#]+))?(?:#(.+$))?!i';
|
||||
preg_match ($r, Tools::getHttpHost(false, false), $out);
|
||||
@@ -89,8 +89,23 @@ class CookieCore
|
||||
return false;
|
||||
if (!strstr(Tools::getHttpHost(false, false), '.'))
|
||||
return false;
|
||||
$domain = $out[4];
|
||||
|
||||
|
||||
$domain = false;
|
||||
if ($shared_urls !== null)
|
||||
{
|
||||
foreach ($shared_urls as $shared_url)
|
||||
{
|
||||
if ($shared_url == $out[4])
|
||||
continue;
|
||||
if (preg_match('/^(?:.*\.)?([^.]*(?:.{2,3})?\..{2,3})$/Ui', $shared_url, $res))
|
||||
{
|
||||
$domain = '.'.$res[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$domain)
|
||||
$domain = $out[4];
|
||||
return $domain;
|
||||
}
|
||||
|
||||
|
||||
@@ -583,6 +583,24 @@ class ShopCore extends ObjectModel
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getUrlsSharedCart()
|
||||
{
|
||||
if (!$this->getGroup()->share_order)
|
||||
return false;
|
||||
|
||||
$query = new DbQuery();
|
||||
$query->select('domain');
|
||||
$query->from('shop_url');
|
||||
$query->where('main = 1');
|
||||
$query->where('active = 1');
|
||||
$query .= $this->addSqlRestriction(Shop::SHARE_ORDER);
|
||||
$domains = array();
|
||||
foreach (Db::getInstance()->executeS($query) as $row)
|
||||
$domains[] = $row['domain'];
|
||||
|
||||
return $domains;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection of shops
|
||||
|
||||
@@ -343,15 +343,17 @@ class StockAvailableCore extends ObjectModel
|
||||
if ($this->id_product_attribute == 0)
|
||||
return true;
|
||||
|
||||
$id_shop = (Shop::getContext() != Shop::CONTEXT_GROUP ? $this->id_shop : null);
|
||||
|
||||
$total_quantity = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT SUM(quantity) as quantity
|
||||
FROM '._DB_PREFIX_.'stock_available
|
||||
WHERE id_product = '.(int)$this->id_product.'
|
||||
AND id_product_attribute <> 0 '.
|
||||
StockAvailable::addSqlShopRestriction(null, $this->id_shop)
|
||||
StockAvailable::addSqlShopRestriction(null, $id_shop)
|
||||
);
|
||||
|
||||
$this->setQuantity($this->id_product, 0, $total_quantity, $this->id_shop);
|
||||
$this->setQuantity($this->id_product, 0, $total_quantity, $id_shop);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -116,10 +116,9 @@ if (defined('_PS_ADMIN_DIR_'))
|
||||
else
|
||||
{
|
||||
if (Context::getContext()->shop->getGroup()->share_order)
|
||||
$cookie = new Cookie('ps-sg'.Context::getContext()->shop->getGroup()->id, '', $cookieLifetime);
|
||||
$cookie = new Cookie('ps-sg'.Context::getContext()->shop->getGroup()->id, '', $cookieLifetime, Context::getContext()->shop->getUrlsSharedCart());
|
||||
else
|
||||
$cookie = new Cookie('ps-s'.Context::getContext()->shop->id, '', $cookieLifetime);
|
||||
|
||||
}
|
||||
|
||||
Context::getContext()->cookie = $cookie;
|
||||
|
||||
Reference in New Issue
Block a user