// Move theme choice from AdminTheme page to Shop page

This commit is contained in:
rMalie
2011-08-02 13:47:34 +00:00
parent 7506710b75
commit 5c849dfa6d
7 changed files with 84 additions and 80 deletions
+42 -33
View File
@@ -43,11 +43,12 @@ class AdminShop extends AdminTab
$this->_group = 'GROUP BY a.id_shop';
$this->fieldsDisplay = array(
'id_shop' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Shop'), 'width' => 130, 'filter_key' => 'b!name'),
'group_shop_name' => array('title' => $this->l('Group Shop'), 'width' => 70),
'category_name' => array('title' => $this->l('Category Root'), 'width' => 70),
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'active'));
'id_shop' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Shop'), 'width' => 130, 'filter_key' => 'b!name'),
'group_shop_name' => array('title' => $this->l('Group Shop'), 'width' => 70),
'category_name' => array('title' => $this->l('Category Root'), 'width' => 70),
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'active'),
);
$this->optionTitle = $this->l('Shops options');
$this->_fieldsOptions = array('PS_SHOP_DEFAULT' => array('title' => $this->l('Default shop:'), 'desc' => $this->l('The default shop'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'id_shop', 'list' => Shop::getShops(), 'visibility' => Shop::CONTEXT_ALL));
@@ -58,10 +59,7 @@ class AdminShop extends AdminTab
public function afterAdd($newShop)
{
if (Tools::getValue('useImportData') && ($importData = Tools::getValue('importData')) && is_array($importData))
{
$shop = new Shop((int)$newShop->id);
$shop->copyShopData((int)Tools::getValue('importFromShop'), $importData);
}
$newShop->copyShopData((int)Tools::getValue('importFromShop'), $importData);
}
public function postProcess()
@@ -84,10 +82,10 @@ class AdminShop extends AdminTab
if (!($obj = $this->loadObject(true)))
return;
if (Shop::getTotalShops() > 1 AND $obj->id)
$disabled = '';
if (Shop::getTotalShops() > 1 && $obj->id)
$disabled = 'disabled="disabled"';
else
$disabled = '';
echo '
<form action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post">
@@ -114,17 +112,8 @@ class AdminShop extends AdminTab
echo '
</select>
</div>';
echo '<label for="id_theme">'.$this->l('Theme').'</label>
<div class="margin-form">
<select id="id_theme" name="id_theme">';
foreach (Theme::getThemes() AS $theme)
echo '<option value="'.$theme['id_theme'].'" '.($theme['id_theme'] == $obj->id_theme ? 'selected="selected"' : '' ).'>'.$theme['name'].'</option>';
echo '
</select>
</div>';
echo '
<label>'.$this->l('Status:').' </label>
</div>
<label>'.$this->l('Status:').' </label>
<div class="margin-form">
<input type="radio" name="active" id="active_on" value="1" '.($this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
@@ -133,6 +122,27 @@ class AdminShop extends AdminTab
<p>'.$this->l('Enable or disable shop').'</p>
</div>';
// Theme list
echo '<label for="id_theme">'.$this->l('Theme').'</label>
<div class="margin-form">';
foreach (Theme::getThemes() as $i => $theme)
{
$checked = ((!$obj->id && $i == 0) || $obj->id_theme == $theme['id_theme']) ? true : false;
echo '<div class="select_theme '.(($checked) ? 'select_theme_choice' : '').'" onclick="$(this).find(\'input\').attr(\'checked\', true); $(\'.select_theme\').removeClass(\'select_theme_choice\'); $(this).toggleClass(\'select_theme_choice\');">';
echo ucfirst($theme['name']).'<br />';
echo '<img src="../themes/'.$theme['name'].'/preview.jpg" alt="'.$theme['name'].'" /><br />';
echo '<input type="radio" name="id_theme" value="'.$theme['id_theme'].'" '.(($checked) ? 'checked="checked"' : '').' />';
echo '</div>';
}
echo '</div><div class="clear"></div>';
echo '<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
</fieldset><br /><br />';
if (Tools::getValue('addshop') !== false)
{
$importData = array(
@@ -161,10 +171,11 @@ class AdminShop extends AdminTab
'zone' => $this->l('Zones'),
);
echo '<label>'.$this->l('Import data:').'</label>';
echo '<fieldset><legend>'.$this->l('Import data from another shop').'</legend>';
echo '<label>'.$this->l('Import data from another shop').'</label>';
echo '<div class="margin-form">';
echo '<input type="checkbox" value="1" checked="checked" name="useImportData" onclick="$(\'#importList\').slideToggle(\'slow\')" /> ';
echo $this->l('Duplicate data from');
echo $this->l('Duplicate data from shop');
echo ' <select name="importFromShop">';
foreach (Shop::getTree() as $gID => $gData)
{
@@ -179,15 +190,13 @@ class AdminShop extends AdminTab
echo '<li><label><input type="checkbox" name="importData['.$table.']" checked="checked" /> '.$lang.'</label></li>';
echo '</ul></div>';
echo '<p>'.$this->l('Use this option to associate data (products, modules, etc.) the same way as the selected shop').'</p>';
echo '</div>';
}
echo ' <div class="margin-form">
echo '</div><div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
</fieldset>
</form>';
</div>';
echo '</fieldset>';
}
echo '</form>';
}
protected function displayAddButton()
-20
View File
@@ -104,9 +104,6 @@ class AdminThemes extends AdminPreferences
'PS_STORES_ICON' => array('title' => $this->l('Store icon:'), 'desc' => $this->l('Will appear on the store locator (inside Google Maps)').'<br />'.$this->l('Suggested size: 30x30, Transparent GIF'), 'type' => 'file', 'thumb' => array('file' => _PS_IMG_.'logo_stores-'.(int)$id_shop.'.gif?date='.time(), 'pos' => 'before')),
'PS_NAVIGATION_PIPE' => array('title' => $this->l('Navigation pipe:'), 'desc' => $this->l('Used for navigation path inside categories/product'), 'cast' => 'strval', 'type' => 'text', 'size' => 20),
);
$this->_fieldsTheme = array(
'PS_THEME' => array('title' => $this->l('Theme'), 'validation' => 'isGenericName', 'type' => 'image', 'list' => $this->_getThemesList(), 'max' => 3)
);
parent::__construct();
}
@@ -123,8 +120,6 @@ class AdminThemes extends AdminPreferences
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
$this->_displayForm('appearance', $this->_fieldsAppearance, $this->l('Appearance'), 'width3', 'appearance');
echo '<br /><br />';
$this->_displayForm('themes', $this->_fieldsTheme, $this->l('Themes'), 'width3', 'themes');
echo '<br /><br />';
if (@ini_get('allow_url_fopen') AND @fsockopen('addons.prestashop.com', 80, $errno, $errst, 3))
echo '<script type="text/javascript">
$.post("'.dirname(self::$currentIndex).'/ajax.php",{page:"themes"},function(a){getE("prestastore-content").innerHTML="<legend><img src=\"../img/admin/prestastore.gif\" class=\"middle\" /> '.$this->l('Live from PrestaShop Addons!').'</legend>"+a;});
@@ -133,21 +128,6 @@ class AdminThemes extends AdminPreferences
else
echo '<a href="http://addons.prestashop.com/3-prestashop-themes">'.$this->l('Find new themes on PrestaShop Addons!').'</a>';
}
/**
* Return an array with themes and thumbnails
*
* @return array
*/
private function _getThemesList()
{
$dir = opendir(_PS_ALL_THEMES_DIR_);
while ($folder = readdir($dir))
if ($folder != '.' AND $folder != '..' AND file_exists(_PS_ALL_THEMES_DIR_.'/'.$folder.'/preview.jpg'))
$themes[$folder]['name'] = $folder;
closedir($dir);
return isset($themes) ? $themes : array();
}
/** This function checks if the theme designer has thunk to make his theme compatible 1.4,
* and noticed it on the $theme_dir/config.xml file. If not, some new functionnalities has
+2 -2
View File
@@ -74,14 +74,14 @@ class DispatcherCore
/**
* If true, use routes to build URL (mod rewrite must be activated)
*
* @var $useRoutes bool
* @var bool
*/
protected $useRoutes = false;
/**
* List of loaded routes
*
* @var $routes array
* @var array
*/
protected $routes = array();
+18 -21
View File
@@ -46,6 +46,7 @@ class ShopCore extends ObjectModel
*/
protected $group;
protected $fieldsRequired = array('id_theme', 'id_category', 'id_group_shop', 'name');
protected $fieldsSize = array('name' => 64);
protected $fieldsValidate = array(
'active' => 'isBool',
@@ -179,28 +180,24 @@ class ShopCore extends ObjectModel
if (is_dir($dirname.'/../'.$directory) AND (!preg_match ('/^\./', $directory)))
$excluded_uris[] = $directory;
// Parse request_uri
if (!$id_shop = Tools::getValue('id_shop'))
{
// 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';
if ($results = Db::getInstance()->executeS($sql))
foreach ($results as $row)
if (preg_match('#^'.preg_quote($row['uri'], '#').'#', $_SERVER['REQUEST_URI']))
{
$id_shop = $row['id_shop'];
break;
}
// 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';
if ($results = Db::getInstance()->executeS($sql))
foreach ($results as $row)
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 !');
}
if (!$id_shop)
die('Shop not found ... redirect me please !');
// Get instance of found shop
$shop = new Shop($id_shop);
+4 -3
View File
@@ -29,7 +29,6 @@ class ThemeCore extends ObjectModel
{
public $name;
protected $fieldsSize = array('name' => 64);
protected $fieldsValidate = array('name' => 'isGenericName');
protected $table = 'theme';
@@ -44,7 +43,9 @@ class ThemeCore extends ObjectModel
public static function getThemes()
{
return Db::getInstance()->ExecuteS('SELECT *
FROM '._DB_PREFIX_.'theme');
$sql = 'SELECT *
FROM '._DB_PREFIX_.'theme
ORDER BY name';
return Db::getInstance()->ExecuteS($sql);
}
}
+17
View File
@@ -1576,4 +1576,21 @@ a.action_module_delete {
color: #CB1C00;
text-decoration: underline;
margin-right: 30px;
}
.select_theme{
text-align: center;
width: 220px;
height: 235px;
float: left;
margin-bottom: 20px;
cursor: pointer;
border: 1px solid #FFFFF0;
color: #000000;
font-weight: bold;
}
.select_theme_choice{
background-color: #FAEEC2;
border: 1px dotted #000000;
}
@@ -539,7 +539,7 @@ class ThemeInstallator extends Module
$msg .= '<br /><b>'.$this->l('Images have been correctly updated in database').'</b><br />';
$theme = new Theme();
$theme->name = pSQL($this->xml['name']);
$theme->name = (string)$this->xml['name'];
$theme->add();
$this->_msg .= parent::displayConfirmation($msg);
$this->_html .= '