// Multishop interface reworked
This commit is contained in:
@@ -957,7 +957,7 @@ abstract class AdminTabCore
|
||||
|
||||
/* Check required fields */
|
||||
foreach ($fields as $field => $values)
|
||||
if (isset($values['required']) && $values['required'] && !isset($_POST['configUseDefault'][$field]))
|
||||
if (isset($values['required']) && $values['required'] && !empty($_POST['multishopOverrideOption'][$field]))
|
||||
if (isset($values['type']) && $values['type'] == 'textLang')
|
||||
{
|
||||
foreach ($languages as $language)
|
||||
@@ -985,14 +985,14 @@ abstract class AdminTabCore
|
||||
if (!Tools::getValue($field) && isset($values['default']))
|
||||
$_POST[$field] = $values['default'];
|
||||
|
||||
if (1||!count($this->_errors))
|
||||
if (!count($this->_errors))
|
||||
{
|
||||
foreach ($fields as $key => $options)
|
||||
{
|
||||
if (isset($options['visibility']) && $options['visibility'] > Shop::getContext())
|
||||
continue;
|
||||
|
||||
if (Shop::isFeatureActive() && isset($_POST['configUseDefault'][$key]))
|
||||
if (Shop::isFeatureActive() && empty($_POST['multishopOverrideOption'][$key]))
|
||||
{
|
||||
Configuration::deleteFromContext($key);
|
||||
continue;
|
||||
@@ -1891,7 +1891,7 @@ abstract class AdminTabCore
|
||||
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && !$isInvisible)
|
||||
echo '<div class="preference_default_multishop">
|
||||
<label>
|
||||
<input type="checkbox" name="configUseDefault['.$key.']" value="1" '.(($isDisabled) ? 'checked="checked"' : '').' onclick="checkMultishopDefaultValue(this, \''.$key.'\')" /> '.$this->l('Use default value').'
|
||||
<input type="checkbox" name="multishopOverrideOption['.$key.']" value="1" '.(($isDisabled) ? 'checked="checked"' : '').' onclick="checkMultishopDefaultValue(this, \''.$key.'\')" /> '.$this->l('Use default value').'
|
||||
</label>
|
||||
</div>';
|
||||
|
||||
|
||||
@@ -346,6 +346,19 @@ class CollectionCore implements Iterator, ArrayAccess, Countable
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the first result
|
||||
*
|
||||
* @return ObjectModel
|
||||
*/
|
||||
public function getFirst()
|
||||
{
|
||||
$this->getAll();
|
||||
if (!count($this))
|
||||
return false;
|
||||
return $this[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get results array
|
||||
*
|
||||
|
||||
+3
-1
@@ -89,6 +89,7 @@ class TabCore extends ObjectModel
|
||||
$class_name = Tab::getClassNameById($this->id_parent);
|
||||
if (isset($retro[$class_name]))
|
||||
$this->id_parent = Tab::getIdFromClassName($retro[$class_name]);
|
||||
self::$_cache_tabs = array();
|
||||
|
||||
// Set good position for new tab
|
||||
$this->position = Tab::getNewLastPosition($this->id_parent);
|
||||
@@ -220,7 +221,7 @@ class TabCore extends ObjectModel
|
||||
*
|
||||
* @return array tabs
|
||||
*/
|
||||
static $_cache_tabs = array();
|
||||
protected static $_cache_tabs = array();
|
||||
public static function getTabs($id_lang, $id_parent = null)
|
||||
{
|
||||
if (!isset(self::$_cache_tabs[$id_lang]))
|
||||
@@ -479,6 +480,7 @@ class TabCore extends ObjectModel
|
||||
if ($current_tab->id_parent != $this->id_parent)
|
||||
$this->position = Tab::getNewLastPosition($this->id_parent);
|
||||
|
||||
self::$_cache_tabs = array();
|
||||
return parent::update($null_values);
|
||||
}
|
||||
|
||||
|
||||
@@ -866,7 +866,7 @@ class AdminControllerCore extends Controller
|
||||
continue;
|
||||
|
||||
// Check if field is required
|
||||
if (isset($values['required']) && $values['required'] && !isset($_POST['configUseDefault'][$field]))
|
||||
if (isset($values['required']) && $values['required'] && !empty($_POST['multishopOverrideOption'][$field]))
|
||||
if (isset($values['type']) && $values['type'] == 'textLang')
|
||||
{
|
||||
foreach ($languages as $language)
|
||||
@@ -897,10 +897,10 @@ class AdminControllerCore extends Controller
|
||||
{
|
||||
foreach ($fields as $key => $options)
|
||||
{
|
||||
if (Shop::isFeatureActive() && isset($options['visibility']) && ($options['visibility'] > Shop::getContext()))
|
||||
if (Shop::isFeatureActive() && isset($options['visibility']) && $options['visibility'] > Shop::getContext())
|
||||
continue;
|
||||
|
||||
if (Shop::isFeatureActive() && isset($_POST['configUseDefault'][$key]))
|
||||
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && empty($_POST['multishopOverrideOption'][$key]))
|
||||
{
|
||||
Configuration::deleteFromContext($key);
|
||||
continue;
|
||||
@@ -941,11 +941,11 @@ class AdminControllerCore extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->errors))
|
||||
$this->confirmations[] = $this->_conf[6];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* assign default action in toolbar_btn smarty var, if they are not set.
|
||||
* uses override to specifically add, modify or remove items
|
||||
|
||||
+22
-27
@@ -198,6 +198,7 @@ class ShopCore extends ObjectModel
|
||||
/**
|
||||
* Detect dependency with customer or orders
|
||||
*
|
||||
* @param int $id_shop
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasDependency($id_shop)
|
||||
@@ -224,17 +225,6 @@ class ShopCore extends ObjectModel
|
||||
return $has_dependency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new instance of a shop
|
||||
*
|
||||
* @param int $id shop ID
|
||||
* @return Shop
|
||||
*/
|
||||
public static function getInstance($id)
|
||||
{
|
||||
return new Shop($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the shop from current domain / uri and get an instance of this shop
|
||||
* if INSTALL_VERSION is defined, will return an empty shop object
|
||||
@@ -533,6 +523,25 @@ class ShopCore extends ObjectModel
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection of shops
|
||||
*
|
||||
* @param bool $active
|
||||
* @param int $id_shop_group
|
||||
* @return Collection
|
||||
*/
|
||||
public static function getShopsCollection($active = true, $id_shop_group = null)
|
||||
{
|
||||
$shops = new Collection('Shop');
|
||||
if ($active)
|
||||
$shops->where('active', '=', 1);
|
||||
|
||||
if ($id_shop_group)
|
||||
$shops->where('id_shop_group', '=', $id_shop_group);
|
||||
|
||||
return $shops;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return some informations cached for one shop
|
||||
*
|
||||
@@ -749,15 +758,11 @@ class ShopCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool Return true if there is more than one shop
|
||||
* @return bool Return true if multishop feature is activated
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
static $total = null;
|
||||
|
||||
if (is_null($total))
|
||||
$total = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'shop');
|
||||
return ($total > 1) ? true : false;
|
||||
return Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE');
|
||||
}
|
||||
|
||||
public function copyShopData($old_id, $tables_import = false, $deleted = false)
|
||||
@@ -813,16 +818,6 @@ class ShopCore extends ObjectModel
|
||||
), $m['id_module']);
|
||||
}
|
||||
|
||||
public function checkIfShopExist($id)
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM`'._DB_PREFIX_.'shop` WHERE `id_shop` = '.(int)$id);
|
||||
}
|
||||
|
||||
public function checkIfShopGroupExist($id)
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM`'._DB_PREFIX_.'shop_group` WHERE `id_shop_group` = '.(int)$id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 1.5.0 Use shop->id
|
||||
*/
|
||||
|
||||
@@ -108,4 +108,42 @@ class ShopGroupCore extends ObjectModel
|
||||
WHERE name = \''.pSQL($name).'\'';
|
||||
return (int)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect dependency with customer or orders
|
||||
*
|
||||
* @param int $id_shop_group
|
||||
* @param string $check all|customer|order
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasDependency($id_shop_group, $check = 'all')
|
||||
{
|
||||
$list_shops = Shop::getShops(false, $id_shop_group, true);
|
||||
if (!$list_shops)
|
||||
return false;
|
||||
|
||||
if ($check == 'all' || $check == 'customer')
|
||||
{
|
||||
$total_customer = (int)Db::getInstance()->getValue('
|
||||
SELECT count(*)
|
||||
FROM `'._DB_PREFIX_.'customer`
|
||||
WHERE `id_shop` IN ('.implode(', ', $list_shops).')'
|
||||
);
|
||||
if ($total_customer)
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($check == 'all' || $check == 'order')
|
||||
{
|
||||
$total_order = (int)Db::getInstance()->getValue('
|
||||
SELECT count(*)
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
WHERE `id_shop` IN ('.implode(', ', $list_shops).')'
|
||||
);
|
||||
if ($total_order)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,41 +164,4 @@ class ShopUrlCore extends ObjectModel
|
||||
}
|
||||
return self::$main_domain_ssl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param string $virtual_uri
|
||||
* @param int $id_shop_tested
|
||||
* @return bool
|
||||
*/
|
||||
public static function virtualUriExists($virtual_uri, $id_shop_tested)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
$virtual_uri = trim($virtual_uri);
|
||||
if (substr($virtual_uri, -1) != '/')
|
||||
$virtual_uri .= '/';
|
||||
return (bool) Db::getInstance()->getValue('
|
||||
SELECT `virtual_uri`
|
||||
FROM `'._DB_PREFIX_.'shop_url`
|
||||
WHERE `id_shop` != '.(int)$id_shop_tested.'
|
||||
AND `virtual_uri` = "'.pSQL($virtual_uri).'"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param string $domain
|
||||
* @param string $physical_uri
|
||||
* @param string $virtual_uri
|
||||
* @param int $id_shop_tested
|
||||
* @return bool
|
||||
*/
|
||||
public static function urlExists($domain, $physical_uri, $virtual_uri, $id_shop_tested)
|
||||
{
|
||||
$url = $domain.$physical_uri.$virtual_uri;
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'shop_url`
|
||||
WHERE `id_shop` != '.(int)$id_shop_tested.'
|
||||
AND CONCAT(`domain`, `physical_uri`, `virtual_uri`) ="'.pSQL($url).'"');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user