// small fixes to BO and norm

This commit is contained in:
lLefevre
2011-11-22 09:03:03 +00:00
parent 10308d6410
commit 0449749ec9
4 changed files with 114 additions and 91 deletions
+34 -28
View File
@@ -24,32 +24,38 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*} *}
<fieldset style="width: 400px"> {extends file="helper/view/view.tpl"}
<span style="font-weight: bold; font-size: 14px;">{l s='Name:'}</span>
<div class="clear">&nbsp;</div> {block name="override_tpl"}
<span style="font-weight: bold; font-size: 14px;">{l s='Discount:'}</span> {$group->reduction} {l s='%'}
<div class="clear">&nbsp;</div> <fieldset style="width: 400px">
<span style="font-weight: bold; font-size: 14px;">{l s='Current category discount:'}</span> <span style="font-weight: bold; font-size: 14px;">{l s='Name:'}</span>
{if !$categorieReductions} <div class="clear">&nbsp;</div>
{l s='None'} <span style="font-weight: bold; font-size: 14px;">{l s='Discount:'}</span> {$group->reduction} {l s='%'}
{else} <div class="clear">&nbsp;</div>
<table cellspacing="0" cellpadding="0" class="table" style="margin-top:10px"> <span style="font-weight: bold; font-size: 14px;">{l s='Current category discount:'}</span>
{foreach $categorieReductions key=key item=category } {if !$categorieReductions}
<tr class="alt_row"> {l s='None'}
<td>{$category.path}</td> {else}
<td>{l s='Discount:'} {$category.reduction}{l s='%'}</td> <table cellspacing="0" cellpadding="0" class="table" style="margin-top:10px">
</tr> {foreach $categorieReductions key=key item=category }
{/foreach} <tr class="alt_row">
</table> <td>{$category.path}</td>
{/if} <td>{l s='Discount:'} {$category.reduction}{l s='%'}</td>
<div class="clear">&nbsp;</div> </tr>
<span style="font-weight: bold; font-size: 14px;">{l s='Price display method:'}</span> {/foreach}
{if $group->price_display_method} </table>
{l s='Tax excluded'}
{else}
{l s='Tax included'}
{/if} {/if}
<div class="clear">&nbsp;</div> <div class="clear">&nbsp;</div>
</fieldset> <span style="font-weight: bold; font-size: 14px;">{l s='Price display method:'}</span>
<h2>{l s='Customer members of this group'}</h2> {if $group->price_display_method}
{$customerList} {l s='Tax excluded'}
{else}
{l s='Tax included'}
{/if}
<div class="clear">&nbsp;</div>
</fieldset>
<h2>{l s='Customer members of this group'}</h2>
{$customerList}
{/block}
@@ -1,4 +1,4 @@
*<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
@@ -106,7 +106,6 @@ class AdminCountriesControllerCore extends AdminController
'orderby' => false, 'orderby' => false,
'filter_key' => 'a!active', 'filter_key' => 'a!active',
'width' => 25 'width' => 25
) )
); );
+11 -10
View File
@@ -32,7 +32,7 @@ class AdminCurrenciesControllerCore extends AdminController
public function __construct() public function __construct()
{ {
$this->table = 'currency'; $this->table = 'currency';
$this->className = 'Currency'; $this->className = 'Currency';
$this->lang = false; $this->lang = false;
$this->fieldsDisplay = array( $this->fieldsDisplay = array(
@@ -52,13 +52,13 @@ class AdminCurrenciesControllerCore extends AdminController
'PS_CURRENCY_DEFAULT' => array( 'PS_CURRENCY_DEFAULT' => array(
'title' => $this->l('Default currency:'), 'title' => $this->l('Default currency:'),
'desc' => $this->l('The default currency used in shop') 'desc' => $this->l('The default currency used in shop')
.'<div class=warn"><img src="../img/admin/warn2.png" />'. .'<div class="warn">'.
$this->l('If you change default currency, you will have to manually edit every product price.').'</div>', $this->l('If you change default currency, you will have to manually edit every product price.').'</div>',
'cast' => 'intval', 'cast' => 'intval',
'type' => 'select', 'type' => 'select',
'identifier' => 'id_currency', 'identifier' => 'id_currency',
'list' => Currency::getCurrencies() 'list' => Currency::getCurrencies()
), )
), ),
'submit' => array() 'submit' => array()
), ),
@@ -70,14 +70,14 @@ class AdminCurrenciesControllerCore extends AdminController
'title' => $this->l('Update currency rates'), 'title' => $this->l('Update currency rates'),
'class' => 'button', 'class' => 'button',
'name' => 'SubmitExchangesRates' 'name' => 'SubmitExchangesRates'
), )
), ),
'cron' => array( 'cron' => array(
'title' => $this->l('Currency rates update'), 'title' => $this->l('Currency rates update'),
'image' => '../img/admin/tab-tools.gif', 'image' => '../img/admin/tab-tools.gif',
'info' => $this->l('Place this URL in crontab or call it manually daily').':<br /> 'info' => $this->l('Place this URL in crontab or call it manually daily').':<br />
<b>'.Tools::getShopDomain(true, true).__PS_BASE_URI__.basename(_PS_ADMIN_DIR_).'/cron_currency_rates.php?secure_key='.md5(_COOKIE_KEY_.Configuration::get('PS_SHOP_NAME')).'</b></p>', <b>'.Tools::getShopDomain(true, true).__PS_BASE_URI__.basename(_PS_ADMIN_DIR_).'/cron_currency_rates.php?secure_key='.md5(_COOKIE_KEY_.Configuration::get('PS_SHOP_NAME')).'</b></p>',
), )
); );
parent::__construct(); parent::__construct();
} }
@@ -274,7 +274,8 @@ class AdminCurrenciesControllerCore extends AdminController
if ($object->active && $object->id == Configuration::get('PS_CURRENCY_DEFAULT')) if ($object->active && $object->id == Configuration::get('PS_CURRENCY_DEFAULT'))
$this->_errors[] = $this->l('You can\'t disable the default currency'); $this->_errors[] = $this->l('You can\'t disable the default currency');
else if ($object->toggleStatus()) else if ($object->toggleStatus())
Tools::redirectAdmin(self::$currentIndex.'&conf=5'.((($id_category = (int)Tools::getValue('id_category')) && Tools::getValue('id_product')) ? '&id_category='.$id_category : '').'&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&conf=5'.((($id_category =
(int)Tools::getValue('id_category')) && Tools::getValue('id_product')) ? '&id_category='.$id_category : '').'&token='.$this->token);
else else
$this->_errors[] = Tools::displayError('An error occurred while updating status.'); $this->_errors[] = Tools::displayError('An error occurred while updating status.');
} }
+68 -51
View File
@@ -43,8 +43,11 @@ class AdminGroupsController extends AdminController
WHERE jc.`deleted` != 1 WHERE jc.`deleted` != 1
AND jcg.`id_group` = a.`id_group`) AS nb'; AND jcg.`id_group` = a.`id_group`) AS nb';
$groups_to_keep = array(Configuration::get('PS_UNIDENTIFIED_GROUP'), Configuration::get('PS_GUEST_GROUP'), Configuration::get('PS_CUSTOMER_GROUP')); $groups_to_keep = array(
$this->_listSkipDelete = $groups_to_keep; Configuration::get('PS_UNIDENTIFIED_GROUP'),
Configuration::get('PS_GUEST_GROUP'),
Configuration::get('PS_CUSTOMER_GROUP')
);
$this->fieldsDisplay = array( $this->fieldsDisplay = array(
'id_group' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'id_group' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
@@ -52,10 +55,9 @@ class AdminGroupsController extends AdminController
'reduction' => array('title' => $this->l('Discount'), 'width' => 50, 'align' => 'right'), 'reduction' => array('title' => $this->l('Discount'), 'width' => 50, 'align' => 'right'),
'nb' => array('title' => $this->l('Members'), 'width' => 25, 'align' => 'center'), 'nb' => array('title' => $this->l('Members'), 'width' => 25, 'align' => 'center'),
'date_add' => array('title' => $this->l('Creation date'), 'width' => 60, 'type' => 'date', 'align' => 'right')); 'date_add' => array('title' => $this->l('Creation date'), 'width' => 60, 'type' => 'date', 'align' => 'right'));
//$this->addRowActionSkipList('delete', array(1));
$this->addRowActionSkipList('delete', $groups_to_keep); $this->addRowActionSkipList('delete', $groups_to_keep);
parent::__construct(); parent::__construct();
} }
@@ -89,7 +91,7 @@ class AdminGroupsController extends AdminController
$genders_icon[$gender->id] = '../genders/'.(int)$gender->id.'.jpg'; $genders_icon[$gender->id] = '../genders/'.(int)$gender->id.'.jpg';
$genders[$gender->id] = $gender->name; $genders[$gender->id] = $gender->name;
} }
$customerFieldsDisplay = (array( $customer_fields_display = (array(
'id_customer' => array('title' => $this->l('ID'), 'align' => 'center'), 'id_customer' => array('title' => $this->l('ID'), 'align' => 'center'),
'id_gender' => array('title' => $this->l('Gender'), 'align' => 'center', 'icon' => $genders_icon, 'list' => $genders), 'id_gender' => array('title' => $this->l('Gender'), 'align' => 'center', 'icon' => $genders_icon, 'list' => $genders),
'firstname' => array('title' => $this->l('Name'), 'align' => 'center'), 'firstname' => array('title' => $this->l('Name'), 'align' => 'center'),
@@ -101,7 +103,7 @@ class AdminGroupsController extends AdminController
'active' => array('title' => $this->l('Enabled'),'align' => 'center','active' => 'status','type' => 'bool') 'active' => array('title' => $this->l('Enabled'),'align' => 'center','active' => 'status','type' => 'bool')
)); ));
$customerList = $group->getCustomers(false); $customer_list = $group->getCustomers(false);
$helper = new HelperList(); $helper = new HelperList();
$helper->currentIndex = self::$currentIndex; $helper->currentIndex = self::$currentIndex;
@@ -111,14 +113,14 @@ class AdminGroupsController extends AdminController
$helper->actions = array('edit', 'view'); $helper->actions = array('edit', 'view');
$helper->show_toolbar = false; $helper->show_toolbar = false;
return $helper->generateList($customerList, $customerFieldsDisplay); return $helper->generateList($customer_list, $customer_fields_display);
} }
public function initForm() public function initForm()
{ {
if (!($group = $this->loadObject(true))) if (!($group = $this->loadObject(true)))
return; return;
$this->fields_form = array( $this->fields_form = array(
'legend' => array( 'legend' => array(
'title' => $this->l('Customer group'), 'title' => $this->l('Customer group'),
@@ -151,7 +153,16 @@ class AdminGroupsController extends AdminController
'name' => 'price_display_method', 'name' => 'price_display_method',
'desc' => $this->l('How the prices are displayed on order summary for this customer group (tax included or excluded).'), 'desc' => $this->l('How the prices are displayed on order summary for this customer group (tax included or excluded).'),
'options' => array( 'options' => array(
'query' => array(array('id_method' => PS_TAX_EXC, 'name' => $this->l('Tax excluded'), array('id_method' => PS_TAX_INC, 'name' => $this->l('Tax included')))), 'query' => array(
array(
'id_method' => PS_TAX_EXC,
'name' => $this->l('Tax excluded'),
array(
'id_method' => PS_TAX_INC,
'name' => $this->l('Tax included')
)
)
),
'id' => 'id_method', 'id' => 'id_method',
'name' => 'name' 'name' => 'name'
) )
@@ -171,7 +182,7 @@ class AdminGroupsController extends AdminController
) )
) )
); );
$trads = array( $trads = array(
'Home' => $this->l('Home'), 'Home' => $this->l('Home'),
'selected' => $this->l('selected'), 'selected' => $this->l('selected'),
@@ -181,8 +192,8 @@ class AdminGroupsController extends AdminController
'Uncheck All' => $this->l('Uncheck All'), 'Uncheck All' => $this->l('Uncheck All'),
'search' => $this->l('Search a category') 'search' => $this->l('Search a category')
); );
$this->tpl_form_vars['categoryTreeView'] = Helper::renderAdminCategorieTree($trads, array(), 'id_category', true); $this->tpl_form_vars['categoryTreeView'] = Helper::renderAdminCategorieTree($trads, array(), 'id_category', true);
return parent::initForm(); return parent::initForm();
} }
@@ -190,45 +201,45 @@ class AdminGroupsController extends AdminController
protected function formatCategoryDiscountList($id) protected function formatCategoryDiscountList($id)
{ {
$categorie = GroupReduction::getGroupReductions((int)$id, $this->context->language->id); $categorie = GroupReduction::getGroupReductions((int)$id, $this->context->language->id);
$categorieReductions = array(); $categorie_reductions = array();
$category_reduction = Tools::getValue('category_reduction'); $category_reduction = Tools::getValue('category_reduction');
foreach($categorie as $category) foreach ($categorie as $category)
{ {
if (is_array($category_reduction) AND array_key_exists($category['id_category'], $category_reduction)) if (is_array($category_reduction) && array_key_exists($category['id_category'], $category_reduction))
$category['reduction'] = $category_reduction[$category['id_category']]; $category['reduction'] = $category_reduction[$category['id_category']];
$tmp = array(); $tmp = array();
$tmp['path'] = getPath(self::$currentIndex.'?tab=AdminCatalog', (int)$category['id_category']); $tmp['path'] = getPath(self::$currentIndex.'?tab=AdminCatalog', (int)$category['id_category']);
$tmp['reduction'] = (float)$category['reduction'] * 100; $tmp['reduction'] = (float)$category['reduction'] * 100;
$tmp['id_category'] = (int)$category['id_category']; $tmp['id_category'] = (int)$category['id_category'];
$categorieReductions[(int)$category['id_category']] = $tmp; $categorie_reductions[(int)$category['id_category']] = $tmp;
} }
if (is_array($category_reduction)) if (is_array($category_reduction))
foreach($category_reduction as $key => $val) foreach ($category_reduction as $key => $val)
{ {
if (!array_key_exists($key, $categorieReductions)) if (!array_key_exists($key, $categorie_reductions))
{ {
$tmp = array(); $tmp = array();
$tmp['path'] = getPath(self::$currentIndex.'?tab=AdminCatalog', (int)$key); $tmp['path'] = getPath(self::$currentIndex.'?tab=AdminCatalog', (int)$key);
$tmp['reduction'] = (float)$val * 100; $tmp['reduction'] = (float)$val * 100;
$tmp['id_category'] = (int)$key; $tmp['id_category'] = (int)$key;
$categorieReductions[(int)$category['id_category']] = $tmp; $categorie_reductions[(int)$category['id_category']] = $tmp;
} }
} }
return $categorieReductions; return $categorie_reductions;
} }
public function formatModuleListAuth($id_group) public function formatModuleListAuth($id_group)
{ {
$modules = Module::getModulesInstalled(); $modules = Module::getModulesInstalled();
$authorized_modules = ''; $authorized_modules = '';
$auth_modules = array(); $auth_modules = array();
$unauth_modules = array(); $unauth_modules = array();
if ($id_group) if ($id_group)
$authorized_modules = Module::getAuthorizedModules($id_group); $authorized_modules = Module::getAuthorizedModules($id_group);
@@ -250,22 +261,22 @@ class AdminGroupsController extends AdminController
else else
$auth_modules = $modules; $auth_modules = $modules;
$auth_modules_tmp = array(); $auth_modules_tmp = array();
foreach($auth_modules as $key => $val) foreach ($auth_modules as $key => $val)
$auth_modules_tmp[] = Module::getInstanceById($val['id_module']); $auth_modules_tmp[] = Module::getInstanceById($val['id_module']);
$auth_modules = $auth_modules_tmp; $auth_modules = $auth_modules_tmp;
$unauth_modules_tmp = array(); $unauth_modules_tmp = array();
foreach($unauth_modules as $key => $val) foreach ($unauth_modules as $key => $val)
$unauth_modules_tmp[] = Module::getInstanceById($val['id_module']); $unauth_modules_tmp[] = Module::getInstanceById($val['id_module']);
$unauth_modules = $unauth_modules_tmp; $unauth_modules = $unauth_modules_tmp;
return array('unauth_modules' => $unauth_modules, 'auth_modules' => $auth_modules); return array('unauth_modules' => $unauth_modules, 'auth_modules' => $auth_modules);
} }
public function postProcess() public function postProcess()
{ {
if (Tools::isSubmit('submitAddgroup')) if (Tools::isSubmit('submitAddgroup'))
{ {
if ($this->tabAccess['add'] === '1') if ($this->tabAccess['add'] === '1')
@@ -285,7 +296,7 @@ class AdminGroupsController extends AdminController
else else
parent::postProcess(); parent::postProcess();
} }
protected function validateDiscount($reduction) protected function validateDiscount($reduction)
{ {
if (!Validate::isPrice($reduction) || $reduction > 100 || $reduction < 0) if (!Validate::isPrice($reduction) || $reduction > 100 || $reduction < 0)
@@ -293,12 +304,12 @@ class AdminGroupsController extends AdminController
else else
return true; return true;
} }
public function ajaxProcessAddCategoryReduction() public function ajaxProcessAddCategoryReduction()
{ {
$category_reduction = Tools::getValue('category_reduction'); $category_reduction = Tools::getValue('category_reduction');
$id_category = Tools::getValue('id_category'); //no cast validation is done with Validate::isUnsignedId($id_category) $id_category = Tools::getValue('id_category'); //no cast validation is done with Validate::isUnsignedId($id_category)
$result = array(); $result = array();
if (!Validate::isUnsignedId($id_category)) if (!Validate::isUnsignedId($id_category))
{ {
@@ -319,8 +330,7 @@ class AdminGroupsController extends AdminController
} }
die(Tools::jsonEncode($result)); die(Tools::jsonEncode($result));
} }
/** /**
* Update (or create) restrictions for modules by group * Update (or create) restrictions for modules by group
*/ */
@@ -332,14 +342,14 @@ class AdminGroupsController extends AdminController
$return = true; $return = true;
if ($id_group) if ($id_group)
Group::truncateModulesRestrictions((int)$id_group); Group::truncateModulesRestrictions((int)$id_group);
if (is_array($auth_modules)) if (is_array($auth_modules))
$return &= Group::addModulesRestrictions($id_group, $auth_modules, 1); $return &= Group::addModulesRestrictions($id_group, $auth_modules, 1);
if (is_array($unauth_modules)) if (is_array($unauth_modules))
$return &= Group::addModulesRestrictions($id_group, $unauth_modules, 0); $return &= Group::addModulesRestrictions($id_group, $unauth_modules, 0);
return $return; return $return;
} }
protected function updateCategoryReduction() protected function updateCategoryReduction()
{ {
$category_reduction = Tools::getValue('category_reduction'); $category_reduction = Tools::getValue('category_reduction');
@@ -351,15 +361,22 @@ class AdminGroupsController extends AdminController
$this->_errors[] = Tools::displayError('Discount value is incorrect'); $this->_errors[] = Tools::displayError('Discount value is incorrect');
else else
{ {
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'group_reduction` WHERE `id_group` = '.(int)Tools::getValue('id_group').' AND `id_category` = '.(int)$cat); Db::getInstance()->execute('
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_group` = '.(int)Tools::getValue('id_group')); DELETE FROM `'._DB_PREFIX_.'group_reduction`
$category = new Category((int)($cat)); WHERE `id_group` = '.(int)Tools::getValue('id_group').'
AND `id_category` = '.(int)$cat
);
Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache`
WHERE `id_group` = '.(int)Tools::getValue('id_group')
);
$category = new Category((int)$cat);
$category->addGroupsIfNoExist((int)Tools::getValue('id_group')); $category->addGroupsIfNoExist((int)Tools::getValue('id_group'));
$groupReduction = new GroupReduction(); $group_reduction = new GroupReduction();
$groupReduction->id_group = (int)Tools::getValue('id_group'); $group_reduction->id_group = (int)Tools::getValue('id_group');
$groupReduction->reduction = (float)($reduction/100); $group_reduction->reduction = (float)($reduction / 100);
$groupReduction->id_category = (int)$cat; $group_reduction->id_category = (int)$cat;
if (!$groupReduction->save()) if (!$group_reduction->save())
$this->_errors[] = Tools::displayError('Cannot save group reductions'); $this->_errors[] = Tools::displayError('Cannot save group reductions');
} }
} }