//Added bulk action in AdminShopUrlController and fixed norms
This commit is contained in:
@@ -23,55 +23,57 @@
|
|||||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*}
|
*}
|
||||||
<script type="text/javascript">
|
|
||||||
//<![CDATA[
|
|
||||||
function fillShopUrl()
|
|
||||||
{
|
|
||||||
var domain = $('#domain').val();
|
|
||||||
var physical = $('#physical_uri').val();
|
|
||||||
var virtual = $('#virtual_uri').val();
|
|
||||||
url = ((domain) ? domain : '???');
|
|
||||||
if (physical)
|
|
||||||
url += '/'+physical;
|
|
||||||
if (virtual)
|
|
||||||
url += '/'+virtual;
|
|
||||||
url = url.replace(/\/+/g, "/");
|
|
||||||
$('#final_url').val('http://'+url);
|
|
||||||
};
|
|
||||||
|
|
||||||
var shopUrl = {$tab_form['jsShopUrl']};
|
|
||||||
|
|
||||||
function checkMainUrlInfo(shopID)
|
|
||||||
{
|
|
||||||
if (!shopID)
|
|
||||||
shopID = $('#id_shop').val();
|
|
||||||
|
|
||||||
if (!shopUrl[shopID])
|
|
||||||
{
|
|
||||||
$('#main_off').attr('disabled', true);
|
|
||||||
$('#main_on').attr('checked', true);
|
|
||||||
$('#mainUrlInfo').css('display', 'block');
|
|
||||||
$('#mainUrlInfoExplain').css('display', 'none');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$('#main_off').attr('disabled', false);
|
|
||||||
$('#mainUrlInfo').css('display', 'none');
|
|
||||||
$('#mainUrlInfoExplain').css('display', 'block');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$().ready(function()
|
|
||||||
{
|
|
||||||
fillShopUrl();
|
|
||||||
checkMainUrlInfo();
|
|
||||||
$('#domain, #physical_uri, #virtual_uri').keyup(fillShopUrl);
|
|
||||||
});
|
|
||||||
|
|
||||||
//]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{if isset($tab_form)}
|
{if isset($tab_form)}
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
//<![CDATA[
|
||||||
|
function fillShopUrl()
|
||||||
|
{
|
||||||
|
var domain = $('#domain').val();
|
||||||
|
var physical = $('#physical_uri').val();
|
||||||
|
var virtual = $('#virtual_uri').val();
|
||||||
|
url = ((domain) ? domain : '???');
|
||||||
|
if (physical)
|
||||||
|
url += '/'+physical;
|
||||||
|
if (virtual)
|
||||||
|
url += '/'+virtual;
|
||||||
|
url = url.replace(/\/+/g, "/");
|
||||||
|
$('#final_url').val('http://'+url);
|
||||||
|
};
|
||||||
|
|
||||||
|
var shopUrl = {$tab_form['jsShopUrl']};
|
||||||
|
|
||||||
|
function checkMainUrlInfo(shopID)
|
||||||
|
{
|
||||||
|
if (!shopID)
|
||||||
|
shopID = $('#id_shop').val();
|
||||||
|
|
||||||
|
if (!shopUrl[shopID])
|
||||||
|
{
|
||||||
|
$('#main_off').attr('disabled', true);
|
||||||
|
$('#main_on').attr('checked', true);
|
||||||
|
$('#mainUrlInfo').css('display', 'block');
|
||||||
|
$('#mainUrlInfoExplain').css('display', 'none');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$('#main_off').attr('disabled', false);
|
||||||
|
$('#mainUrlInfo').css('display', 'none');
|
||||||
|
$('#mainUrlInfoExplain').css('display', 'block');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$().ready(function()
|
||||||
|
{
|
||||||
|
fillShopUrl();
|
||||||
|
checkMainUrlInfo();
|
||||||
|
$('#domain, #physical_uri, #virtual_uri').keyup(fillShopUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
//]]>
|
||||||
|
</script>
|
||||||
|
|
||||||
<form action="{$tab_form['current']}&submitAdd{$tab_form['table']}=1&token={$tab_form['token']}" method="post">
|
<form action="{$tab_form['current']}&submitAdd{$tab_form['table']}=1&token={$tab_form['token']}" method="post">
|
||||||
{if $tab_form['id']}<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />{/if}
|
{if $tab_form['id']}<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />{/if}
|
||||||
<fieldset><legend>{l s ='Shop Url'}</legend>
|
<fieldset><legend>{l s ='Shop Url'}</legend>
|
||||||
@@ -112,9 +114,9 @@
|
|||||||
<label>{l s ='Main URL:'}</label>
|
<label>{l s ='Main URL:'}</label>
|
||||||
<div class="margin-form">
|
<div class="margin-form">
|
||||||
<input type="radio" name="main" id="main_on" value="1" {if $tab_form['main']} checked="checked"{/if}/>
|
<input type="radio" name="main" id="main_on" value="1" {if $tab_form['main']} checked="checked"{/if}/>
|
||||||
<label class="t" for="main_on"> <img src="../img/admin/enabled.gif" alt="{l s ='Enabled'}" title="{l s ='Enabled'}" /></label>
|
<label class="t" for="main_on"><img src="../img/admin/enabled.gif" alt="{l s ='Enabled'}" title="{l s ='Enabled'}" /></label>
|
||||||
<input type="radio" name="main" id="main_off" value="0" {if !$tab_form['main']} checked="checked"{/if} />
|
<input type="radio" name="main" id="main_off" value="0" {if !$tab_form['main']} checked="checked"{/if} />
|
||||||
<label class="t" for="main_off"> <img src="../img/admin/disabled.gif" alt="{l s ='Disabled'}" title="{l s ='Disabled'}" /></label>
|
<label class="t" for="main_off"><img src="../img/admin/disabled.gif" alt="{l s ='Disabled'}" title="{l s ='Disabled'}" /></label>
|
||||||
<p>{l s ='If you set this url as main url for selected shop, all urls set to this shop will be redirected to this url (you can only have one main url per shop).'}</p>
|
<p>{l s ='If you set this url as main url for selected shop, all urls set to this shop will be redirected to this url (you can only have one main url per shop).'}</p>
|
||||||
<p id="mainUrlInfo">{l s ='Since the selected shop has no main url, you have to set this url as main'}</p>
|
<p id="mainUrlInfo">{l s ='Since the selected shop has no main url, you have to set this url as main'}</p>
|
||||||
<p id="mainUrlInfoExplain">{l s ='The selected shop has already a main url, if you set this one as main url, the older one will be set as normal url'}</p>
|
<p id="mainUrlInfoExplain">{l s ='The selected shop has already a main url, if you set this one as main url, the older one will be set as normal url'}</p>
|
||||||
@@ -133,5 +135,7 @@
|
|||||||
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{$content}
|
{$content}
|
||||||
+11
-12
@@ -34,10 +34,9 @@ class ShopUrlCore extends ObjectModel
|
|||||||
public $virtual_uri;
|
public $virtual_uri;
|
||||||
public $main;
|
public $main;
|
||||||
public $active;
|
public $active;
|
||||||
|
|
||||||
private static $main_domain = NULL;
|
private static $main_domain = null;
|
||||||
private static $main_domain_ssl = NULL;
|
private static $main_domain_ssl = null;
|
||||||
|
|
||||||
|
|
||||||
protected $fieldsRequired = array('domain', 'id_shop');
|
protected $fieldsRequired = array('domain', 'id_shop');
|
||||||
protected $fieldsSize = array('domain' => 255, 'physical_uri' => 64, 'virtual_uri' => 64);
|
protected $fieldsSize = array('domain' => 255, 'physical_uri' => 64, 'virtual_uri' => 64);
|
||||||
@@ -69,16 +68,16 @@ class ShopUrlCore extends ObjectModel
|
|||||||
$fields['active'] = (int)$this->active;
|
$fields['active'] = (int)$this->active;
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getURL($ssl = false)
|
public function getURL($ssl = false)
|
||||||
{
|
{
|
||||||
if (!$this->id)
|
if (!$this->id)
|
||||||
return ;
|
return;
|
||||||
|
|
||||||
$url = ($ssl) ? 'https://'.$this->domain_ssl : 'http://'.$this->domain;
|
$url = ($ssl) ? 'https://'.$this->domain_ssl : 'http://'.$this->domain;
|
||||||
return $url.$this->physical_uri.$this->virtual_uri;
|
return $url.$this->physical_uri.$this->virtual_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getShopUrls($id_shop = false)
|
public static function getShopUrls($id_shop = false)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT *
|
$sql = 'SELECT *
|
||||||
@@ -87,7 +86,7 @@ class ShopUrlCore extends ObjectModel
|
|||||||
'.($id_shop ? ' AND id_shop = '.(int)$id_shop : '');
|
'.($id_shop ? ' AND id_shop = '.(int)$id_shop : '');
|
||||||
return Db::getInstance()->ExecuteS($sql);
|
return Db::getInstance()->ExecuteS($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMain()
|
public function setMain()
|
||||||
{
|
{
|
||||||
$res = Db::getInstance()->autoExecute(_DB_PREFIX_.'shop_url', array('main' => 0), 'UPDATE', 'id_shop = '.(int)$this->id_shop);
|
$res = Db::getInstance()->autoExecute(_DB_PREFIX_.'shop_url', array('main' => 0), 'UPDATE', 'id_shop = '.(int)$this->id_shop);
|
||||||
@@ -96,7 +95,7 @@ class ShopUrlCore extends ObjectModel
|
|||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canAddThisUrl($domain, $domain_ssl, $physical_uri, $virtual_uri)
|
public function canAddThisUrl($domain, $domain_ssl, $physical_uri, $virtual_uri)
|
||||||
{
|
{
|
||||||
$physical_uri = trim($physical_uri, '/');
|
$physical_uri = trim($physical_uri, '/');
|
||||||
@@ -104,7 +103,7 @@ class ShopUrlCore extends ObjectModel
|
|||||||
$physical_uri = preg_replace('#/+#', '/', '/'.$physical_uri.'/');
|
$physical_uri = preg_replace('#/+#', '/', '/'.$physical_uri.'/');
|
||||||
else
|
else
|
||||||
$this->physical_uri = '/';
|
$this->physical_uri = '/';
|
||||||
|
|
||||||
$virtual_uri = trim($virtual_uri, '/');
|
$virtual_uri = trim($virtual_uri, '/');
|
||||||
if ($virtual_uri)
|
if ($virtual_uri)
|
||||||
$virtual_uri = preg_replace('#/+#', '/', trim($virtual_uri, '/')).'/';
|
$virtual_uri = preg_replace('#/+#', '/', trim($virtual_uri, '/')).'/';
|
||||||
@@ -117,7 +116,7 @@ class ShopUrlCore extends ObjectModel
|
|||||||
.($this->id ? ' AND id_shop_url != '.(int)$this->id : '');
|
.($this->id ? ' AND id_shop_url != '.(int)$this->id : '');
|
||||||
return Db::getInstance()->getValue($sql);
|
return Db::getInstance()->getValue($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getMainShopDomain()
|
public static function getMainShopDomain()
|
||||||
{
|
{
|
||||||
if (!self::$main_domain)
|
if (!self::$main_domain)
|
||||||
@@ -126,7 +125,7 @@ class ShopUrlCore extends ObjectModel
|
|||||||
WHERE main=1 AND id_shop = '.Context::getContext()->shop->getID(true));
|
WHERE main=1 AND id_shop = '.Context::getContext()->shop->getID(true));
|
||||||
return self::$main_domain;
|
return self::$main_domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getMainShopDomainSSL()
|
public static function getMainShopDomainSSL()
|
||||||
{
|
{
|
||||||
if (!self::$main_domain)
|
if (!self::$main_domain)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class AdminShopUrlControllerCore extends AdminController
|
|||||||
$this->edit = true;
|
$this->edit = true;
|
||||||
$this->delete = true;
|
$this->delete = true;
|
||||||
$this->requiredDatabase = true;
|
$this->requiredDatabase = true;
|
||||||
|
$this->_listSkipDelete = array(1);
|
||||||
|
|
||||||
$this->context = Context::getContext();
|
$this->context = Context::getContext();
|
||||||
|
|
||||||
@@ -43,7 +44,8 @@ class AdminShopUrlControllerCore extends AdminController
|
|||||||
|
|
||||||
$this->_select = 's.name AS shop_name, CONCAT(a.physical_uri, a.virtual_uri) AS uri';
|
$this->_select = 's.name AS shop_name, CONCAT(a.physical_uri, a.virtual_uri) AS uri';
|
||||||
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'shop` s ON (s.id_shop = a.id_shop)';
|
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'shop` s ON (s.id_shop = a.id_shop)';
|
||||||
$this->_listSkipDelete = array(1);
|
|
||||||
|
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
|
||||||
|
|
||||||
$this->fieldsDisplay = array(
|
$this->fieldsDisplay = array(
|
||||||
'id_shop_url' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
'id_shop_url' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||||
@@ -62,6 +64,7 @@ class AdminShopUrlControllerCore extends AdminController
|
|||||||
|
|
||||||
public function postProcess()
|
public function postProcess()
|
||||||
{
|
{
|
||||||
|
info($this->action);
|
||||||
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
|
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
|
||||||
if (Tools::isSubmit('submitAdd'.$this->table))
|
if (Tools::isSubmit('submitAdd'.$this->table))
|
||||||
{
|
{
|
||||||
@@ -74,10 +77,10 @@ class AdminShopUrlControllerCore extends AdminController
|
|||||||
|
|
||||||
if (($object->main || Tools::getValue('main')) && !Tools::getValue('active'))
|
if (($object->main || Tools::getValue('main')) && !Tools::getValue('active'))
|
||||||
$this->_errors[] = Tools::displayError('You can\'t disable a main url');
|
$this->_errors[] = Tools::displayError('You can\'t disable a main url');
|
||||||
|
|
||||||
if ($object->canAddThisUrl(Tools::getValue('domain'), Tools::getValue('domain_ssl'), Tools::getValue('physical_uri'), Tools::getValue('virtual_uri')))
|
if ($object->canAddThisUrl(Tools::getValue('domain'), Tools::getValue('domain_ssl'), Tools::getValue('physical_uri'), Tools::getValue('virtual_uri')))
|
||||||
$this->_errors[] = Tools::displayError('A shop url that use this domain and uri already exists');
|
$this->_errors[] = Tools::displayError('A shop url that use this domain and uri already exists');
|
||||||
|
|
||||||
parent::postProcess();
|
parent::postProcess();
|
||||||
Tools::generateHtaccess(dirname(__FILE__).'/../../.htaccess', Configuration::get('PS_REWRITING_SETTINGS'), Configuration::get('PS_HTACCESS_CACHE_CONTROL'), '');
|
Tools::generateHtaccess(dirname(__FILE__).'/../../.htaccess', Configuration::get('PS_REWRITING_SETTINGS'), Configuration::get('PS_HTACCESS_CACHE_CONTROL'), '');
|
||||||
}
|
}
|
||||||
@@ -104,48 +107,52 @@ class AdminShopUrlControllerCore extends AdminController
|
|||||||
return parent::postProcess();
|
return parent::postProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function afterUpdate($object)
|
|
||||||
{
|
|
||||||
if (Tools::getValue('main'))
|
|
||||||
$object->setMain();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function displayForm($isMainTab = true)
|
public function displayForm($isMainTab = true)
|
||||||
{
|
{
|
||||||
$this->content = parent::displayForm($isMainTab);
|
$this->content = parent::displayForm($isMainTab);
|
||||||
|
|
||||||
if (!($obj = $this->loadObject(true)))
|
if (!($obj = $this->loadObject(true)))
|
||||||
return;
|
return;
|
||||||
$currentShop = Shop::initialize();
|
$current_shop = Shop::initialize();
|
||||||
|
|
||||||
$listShopWithUrl = array();
|
$list_shop_with_url = array();
|
||||||
foreach (Shop::getShops(false, null, true) as $id)
|
foreach (Shop::getShops(false, null, true) as $id)
|
||||||
$listShopWithUrl[$id] = (bool)count(ShopUrl::getShopUrls($id));
|
$list_shop_with_url[$id] = (bool)count(ShopUrl::getShopUrls($id));
|
||||||
$jsShopUrl = Tools::jsonEncode($listShopWithUrl);
|
|
||||||
|
|
||||||
$domain = Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'domain') : $currentShop->domain;
|
$js_shop_url = Tools::jsonEncode($list_shop_with_url);
|
||||||
$domain_ssl = Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'domain_ssl') : $currentShop->domain_ssl;
|
|
||||||
$physical_uri = Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'physical_uri') : $currentShop->physical_uri;
|
|
||||||
|
|
||||||
$this->context->smarty->assign('tab_form', array('current' => self::$currentIndex,
|
$domain = Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'domain') : $current_shop->domain;
|
||||||
'table' => $this->table,
|
$domain_ssl = Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'domain_ssl') : $current_shop->domain_ssl;
|
||||||
'token' => $this->token,
|
$physical_uri = Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'physical_uri') : $current_shop->physical_uri;
|
||||||
'id' => $obj->id,
|
|
||||||
'domain' => $domain,
|
$this->context->smarty->assign('tab_form', array(
|
||||||
'domain_ssl' => $domain_ssl,
|
'current' => self::$currentIndex,
|
||||||
'physical_uri' => $physical_uri,
|
'table' => $this->table,
|
||||||
'virtual_uri' => $this->getFieldValue($obj, 'virtual_uri'),
|
'token' => $this->token,
|
||||||
'getTree' => Shop::getTree(),
|
'id' => $obj->id,
|
||||||
'id_shop' => $obj->id_shop,
|
'domain' => $domain,
|
||||||
'main' => $this->getFieldValue($obj, 'main') ? true : false,
|
'domain_ssl' => $domain_ssl,
|
||||||
'active' => $this->getFieldValue($obj, 'active') ? true : false,
|
'physical_uri' => $physical_uri,
|
||||||
'jsShopUrl' => $jsShopUrl));
|
'virtual_uri' => $this->getFieldValue($obj, 'virtual_uri'),
|
||||||
|
'getTree' => Shop::getTree(),
|
||||||
|
'id_shop' => $obj->id_shop,
|
||||||
|
'main' => $this->getFieldValue($obj, 'main') ? true : false,
|
||||||
|
'active' => $this->getFieldValue($obj, 'active') ? true : false,
|
||||||
|
'jsShopUrl' => $js_shop_url
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterUpdate($object)
|
||||||
|
{
|
||||||
|
if (Tools::getValue('main'))
|
||||||
|
$object->setMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initContent()
|
public function initContent()
|
||||||
{
|
{
|
||||||
if ($this->display != 'edit')
|
if ($this->display != 'edit')
|
||||||
$this->display = 'list';
|
$this->display = 'list';
|
||||||
|
|
||||||
parent::initContent();
|
parent::initContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user