From b37c0dc2973eec83d92ed8a250f3bd5dd0033e0e Mon Sep 17 00:00:00 2001 From: rGaillard Date: Thu, 21 Jun 2012 16:11:30 +0000 Subject: [PATCH] // 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 --- classes/Cookie.php | 25 ++++++++++++++++++++----- classes/shop/Shop.php | 18 ++++++++++++++++++ classes/stock/StockAvailable.php | 6 ++++-- config/config.inc.php | 3 +-- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/classes/Cookie.php b/classes/Cookie.php index f2fb4ab8f..ca7cc602e 100644 --- a/classes/Cookie.php +++ b/classes/Cookie.php @@ -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; } diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index 92010de20..f2e0babd7 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -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 diff --git a/classes/stock/StockAvailable.php b/classes/stock/StockAvailable.php index e784b2570..f86995c04 100644 --- a/classes/stock/StockAvailable.php +++ b/classes/stock/StockAvailable.php @@ -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; } diff --git a/config/config.inc.php b/config/config.inc.php index 92aa1bbfa..98a318f4c 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -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;