// Added AdminGroupShopController

This commit is contained in:
lLefevre
2011-10-05 08:18:44 +00:00
parent d311b3c976
commit 07681b5571
3 changed files with 248 additions and 191 deletions
-191
View File
@@ -1,191 +0,0 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 1.4 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminGroupShop extends AdminTab
{
public function __construct()
{
$this->table = 'group_shop';
$this->className = 'GroupShop';
$this->edit = true;
$this->delete = false;
$this->deleted = false;
$this->fieldsDisplay = array(
'id_group_shop' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('County'), 'width' => 130, 'filter_key' => 'b!name'),
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'active'),
);
parent::__construct();
}
public function postProcess()
{
if (Tools::isSubmit('delete'.$this->table) OR Tools::isSubmit('status') OR Tools::isSubmit('status'.$this->table))
{
$object = $this->loadObject();
if (GroupShop::getTotalGroupShops() == 1)
$this->_errors[] = Tools::displayError('You cannot delete or disable the last groupshop.');
else if ($object->haveShops())
$this->_errors[] = Tools::displayError('You cannot delete or disable a groupshop which have this shops using it.');
if (sizeof($this->_errors))
return false;
}
return parent::postProcess();
}
public function afterAdd($newGroupShop)
{
if (Tools::getValue('useImportData') && ($importData = Tools::getValue('importData')) && is_array($importData))
$newGroupShop->copyGroupShopData(Tools::getValue('importFromShop'), $importData);
}
public function afterUpdate($newGroupShop)
{
if (Tools::getValue('useImportData') && ($importData = Tools::getValue('importData')) && is_array($importData))
$newGroupShop->copyGroupShopData(Tools::getValue('importFromShop'), $importData);
}
public function displayForm($isMainTab = true)
{
parent::displayForm($isMainTab);
if (!($obj = $this->loadObject(true)))
return;
if (Shop::getTotalShops() > 1 AND $obj->id)
$disabled = 'disabled="disabled"';
else
$disabled = '';
echo <<<EOF
<script type="text/javascript">
//<![CDATA[
$().ready(function()
{
$('input[name=share_order]').attr('disabled', true);
$('input[name=share_customer], input[name=share_stock]').click(function()
{
var disabled = ($('input[name=share_customer]').attr('checked') && $('input[name=share_stock]').attr('checked')) ? false : true;
$('input[name=share_order]').attr('disabled', disabled);
if (disabled)
$('#share_order_off').attr('checked', true);
});
});
//]]>
</script>
EOF;
echo '
<form action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post">
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
<fieldset><legend>'.$this->l('GroupShop').'</legend><div class="hint" name="help_box" style="display:block;">'.$this->l('You can\'t edit GroupShop when you have more than one Shop').'</div><br />
<label for="name">'.$this->l('GroupShop name').'</label>
<div class="margin-form">
<input type="text" name="name" id="name" value="'.$this->getFieldValue($obj, 'name').'" />
</div>
<label for="share_customer">'.$this->l('Share customers').'</label>
<div class="margin-form">
<input type="radio" name="share_customer" '.$disabled.' id="share_customer_on" value="1" '.($this->getFieldValue($obj, 'share_customer') ? 'checked="checked" ' : '').'/>
<label class="t" for="share_customer_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
<input type="radio" name="share_customer" '.$disabled.' id="share_customer_off" value="0" '.(!$this->getFieldValue($obj, 'share_customer') ? 'checked="checked" ' : '').'/>
<label class="t" for="ashare_customer_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p>'.$this->l('Share customers between shops of this group').'</p>
</div>
<label for="share_stock">'.$this->l('Share stock').'</label>
<div class="margin-form">
<input type="radio" name="share_stock" '.$disabled.' id="share_stock_on" value="1" '.($this->getFieldValue($obj, 'share_stock') ? 'checked="checked" ' : '').'/>
<label class="t" for="share_stock_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
<input type="radio" name="share_stock" '.$disabled.' id="share_stock_off" value="0" '.(!$this->getFieldValue($obj, 'share_stock') ? 'checked="checked" ' : '').'/>
<label class="t" for="share_stock_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p>'.$this->l('Sare stock between shops of this group').'</p>
</div>
<label for="share_order">'.$this->l('Share orders').'</label>
<div class="margin-form">
<input type="radio" name="share_order" '.$disabled.' id="share_order_on" value="1" '.($this->getFieldValue($obj, 'share_order') ? 'checked="checked" ' : '').'/>
<label class="t" for="share_order_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
<input type="radio" name="share_order" '.$disabled.' id="share_order_off" value="0" '.(!$this->getFieldValue($obj, 'share_order') ? 'checked="checked" ' : '').'/>
<label class="t" for="share_order_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p>'.$this->l('Share orders and carts between shops of this group (you can share orders only if you share customers and stock)').'</p>
</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>
<input type="radio" name="active" id="active_off" value="0" '.(!$this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p>'.$this->l('Enable or disable shop').'</p>
</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><br />';
$importData = array(
'attribute_group' => $this->l('Attribute groups'),
'attribute' => $this->l('Attributes'),
//'customer_group' => $this->l('Customer groups'),
'feature' => $this->l('Features'),
'group' => $this->l('Groups'),
'manufacturer' => $this->l('Manufacturers'),
'supplier' => $this->l('Suppliers'),
'tax_rules_group' => $this->l('Tax rules groups'),
'zone' => $this->l('Zones'),
);
$checked = (Tools::getValue('addgroup_shop') !== false) ? true : false;
$defaultGroup = Shop::getInstance(Configuration::get('PS_SHOP_DEFAULT'))->getGroupID();
echo '<fieldset><legend>'.$this->l('Import data from another group shop').'</legend>';
echo '<label>'.$this->l('Import data from another group shop').'</label>';
echo '<div class="margin-form">';
echo '<input type="checkbox" value="1" '.(($checked) ? 'checked="checked"' : '').' name="useImportData" onclick="$(\'#importList\').slideToggle(\'slow\')" /> ';
echo $this->l('Duplicate data from group shop');
echo ' <select name="importFromShop">';
foreach (Shop::getTree() as $gID => $gData)
echo '<option value="'.(int)$gID.'" '.($gID == $defaultGroup ? 'selected="selected"' : '').'">'.$gData['name'].'</option>';
echo '</select>';
echo '<div id="importList" style="'.((!$checked) ? 'display: none' : '').'"><ul>';
foreach ($importData as $table => $lang)
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><div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>';
echo '</fieldset>';
echo '</form>';
}
protected function displayAddButton()
{
echo '<br /><a href="'.self::$currentIndex.'&add'.$this->table.'&token='.$this->token.'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add new group shop').'</a><br /><br />';
}
}
@@ -0,0 +1,113 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 8897 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{if isset($tab_form)}
<script type="text/javascript">
$().ready(function()
{
$('input[name=share_order]').attr('disabled', true);
$('input[name=share_customer], input[name=share_stock]').click(function()
{
var disabled = ($('input[name=share_customer]').attr('checked') && $('input[name=share_stock]').attr('checked')) ? false : true;
$('input[name=share_order]').attr('disabled', disabled);
if (disabled)
$('#share_order_off').attr('checked', true);
});
});
</script>
<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_{$tab_form['table']}" value="{$tab_form['id']}" />{/if}
<fieldset>
<legend>{l s ='GroupShop'}</legend>
<div class="hint" name="help_box" style="display:block;">{l s ='You can\'t edit GroupShop when you have more than one Shop'}</div><br />
<label for="name">{l s ='GroupShop name'}</label>
<div class="margin-form">
<input type="text" name="name" id="name" value="{$tab_form['name']}" />
</div>
<label for="share_customer">{l s ='Share customers'}</label>
<div class="margin-form">
<input type="radio" name="share_customer" {$tab_form['disabled']} id="share_customer_on" value="1" {if $tab_form['share_customer']} checked="checked"{/if}/>
<label class="t" for="share_customer_on"> <img src="../img/admin/enabled.gif" alt="{l s ='Enabled'}" title="{l s ='Enabled'}" /></label>
<input type="radio" name="share_customer" {$tab_form['disabled']} id="share_customer_off" value="0" {if !$tab_form['share_customer']} checked="checked"{/if}/>
<label class="t" for="ashare_customer_off"> <img src="../img/admin/disabled.gif" alt="{l s ='Disabled'}" title="{l s ='Disabled'}" /></label>
<p>{l s ='Share customers between shops of this group'}</p>
</div>
<label for="share_stock">{l s ='Share stock'}</label>
<div class="margin-form">
<input type="radio" name="share_stock" {$tab_form['disabled']} id="share_stock_on" value="1" {if $tab_form['share_stock']} checked="checked"{/if}/>
<label class="t" for="share_stock_on"> <img src="../img/admin/enabled.gif" alt="{l s ='Enabled'}" title="{l s ='Enabled'}" /></label>
<input type="radio" name="share_stock" {$tab_form['disabled']} id="share_stock_off" value="0" {if !$tab_form['share_stock']} checked="checked"{/if} />
<label class="t" for="share_stock_off"> <img src="../img/admin/disabled.gif" alt="{l s ='Disabled'}" title="{l s ='Disabled'}" /></label>
<p>{l s ='Sare stock between shops of this group'}</p>
</div>
<label for="share_order">{l s ='Share orders'}</label>
<div class="margin-form">
<input type="radio" name="share_order" {$tab_form['disabled']} id="share_order_on" value="1" {if $tab_form['share_order']} checked="checked"{/if}/>
<label class="t" for="share_order_on"> <img src="../img/admin/enabled.gif" alt="{l s ='Enabled'}" title="{l s ='Enabled'}" /></label>
<input type="radio" name="share_order" {$tab_form['disabled']} id="share_order_off" value="0" {if !$tab_form['share_order']} checked="checked"{/if}/>
<label class="t" for="share_order_off"> <img src="../img/admin/disabled.gif" alt="{l s ='Disabled'}" title="{l s ='Disabled'}" /></label>
<p>{l s ='Share orders and carts between shops of this group (you can share orders only if you share customers and stock)'}</p>
</div>
<label>{l s ='Status:'} </label>
<div class="margin-form">
<input type="radio" name="active" id="active_on" value="1" {if $tab_form['active']} checked="checked"{/if}/>
<label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="{l s ='Enabled'}" title="{l s ='Enabled'}" /></label>
<input type="radio" name="active" id="active_off" value="0" {if !$tab_form['active']} checked="checked"{/if}/>
<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="{l s ='Disabled'}" title="{l s ='Disabled'}" /></label>
<p>{l s ='Enable or disable shop'}</p>
</div>
<div class="margin-form">
<input type="submit" value="{l s =' Save '}" name="submitAdd{$tab_form['table']}" class="button" />
</div>
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
</fieldset><br />
<fieldset><legend>{l s ='Import data from another group shop'}</legend>
<label>{l s ='Import data from another group shop'}</label>
<div class="margin-form">
<input type="checkbox" value="1" {if $tab_form['checked']} checked="checked"{/if} name="useImportData" onclick="$('#importList').slideToggle('slow')" />
{l s ='Duplicate data from group shop'}
<select name="importFromShop">
{foreach $tab_form['getTree'] as $gID => $gData}
<option value="{$gID}" {if $gID == $tab_form['defaultGroup']} selected="selected"{/if}">{$gData['name']}</option>
{/foreach}
</select>
<div id="importList" style="{if !$tab_form['checked']}display: none{/if}"><ul>
{foreach $tab_form['importData'] as $table => $lang}
<li><label><input type="checkbox" name="importData[{$table}]" checked="checked" /> {$lang}</label></li>
{/foreach}
</ul></div>
<p>{l s ='Use this option to associate data (products, modules, etc.) the same way as the selected shop'}</p>
</div><div class="margin-form">
<input type="submit" value="{l s =' Save '}" name="submitAdd{$tab_form['table']}" class="button" />
</div>
</fieldset>
</form>
{/if}
{$content}
@@ -0,0 +1,135 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 8971 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminGroupShopControllerCore extends AdminController
{
public function __construct()
{
$this->table = 'group_shop';
$this->className = 'GroupShop';
$this->lang = false;
$this->edit = true;
$this->delete = false;
$this->requiredDatabase = true;
$this->context = Context::getContext();
if (!Tools::getValue('realedit'))
$this->deleted = false;
$this->fieldsDisplay = array(
'id_group_shop' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('County'), 'width' => 130, 'filter_key' => 'b!name'),
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'active'),
);
$this->template = 'adminGroupShop.tpl';
parent::__construct();
}
public function postProcess()
{
if (Tools::isSubmit('delete'.$this->table) OR Tools::isSubmit('status') OR Tools::isSubmit('status'.$this->table))
{
$object = $this->loadObject();
if (GroupShop::getTotalGroupShops() == 1)
$this->_errors[] = Tools::displayError('You cannot delete or disable the last groupshop.');
else if ($object->haveShops())
$this->_errors[] = Tools::displayError('You cannot delete or disable a groupshop which have this shops using it.');
if (sizeof($this->_errors))
return false;
}
return parent::postProcess();
}
public function afterAdd($newGroupShop)
{
if (Tools::getValue('useImportData') && ($importData = Tools::getValue('importData')) && is_array($importData))
$newGroupShop->copyGroupShopData(Tools::getValue('importFromShop'), $importData);
}
public function afterUpdate($newGroupShop)
{
if (Tools::getValue('useImportData') && ($importData = Tools::getValue('importData')) && is_array($importData))
$newGroupShop->copyGroupShopData(Tools::getValue('importFromShop'), $importData);
}
public function displayForm($isMainTab = true)
{
parent::displayForm($isMainTab);
if (!($obj = $this->loadObject(true)))
return;
if (Shop::getTotalShops() > 1 AND $obj->id)
$disabled = 'disabled="disabled"';
else
$disabled = '';
$importData = array(
'attribute_group' => $this->l('Attribute groups'),
'attribute' => $this->l('Attributes'),
//'customer_group' => $this->l('Customer groups'),
'feature' => $this->l('Features'),
'group' => $this->l('Groups'),
'manufacturer' => $this->l('Manufacturers'),
'supplier' => $this->l('Suppliers'),
'tax_rules_group' => $this->l('Tax rules groups'),
'zone' => $this->l('Zones'),
);
$this->context->smarty->assign('tab_form', array(
'current' => self::$currentIndex,
'table' => $this->table,
'token' => $this->token,
'id' => $obj->id,
'name' => $this->getFieldValue($obj, 'name'),
'disabled' => $disabled,
'share_customer' => $this->getFieldValue($obj, 'share_customer') ? true : false,
'share_stock' => $this->getFieldValue($obj, 'share_stock') ? true : false,
'share_order' => $this->getFieldValue($obj, 'share_order') ? true : false,
'active' => $this->getFieldValue($obj, 'active') ? true : false,
'importData' => $importData,
'getTree' => Shop::getTree(),
'checked' => (Tools::getValue('addgroup_shop') !== false) ? true : false,
'defaultGroup' => Shop::getInstance(Configuration::get('PS_SHOP_DEFAULT'))->getGroupID()
));
}
public function initContent()
{
if ($this->display != 'edit')
$this->display = 'list';
parent::initContent();
}
}