From 5cae5358fa50241510fcfd41a362c5785f293409 Mon Sep 17 00:00:00 2001 From: lLefevre Date: Tue, 13 Sep 2011 13:17:32 +0000 Subject: [PATCH] [*] BO : Add reduction groups in the categories, and bug fix: reduction that is not an integer or a percentage (TD001 - TD002 - TD003) git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8536 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/tabs/AdminCustomers.php | 2 +- admin-dev/tabs/AdminGroups.php | 20 +++++++++++++++----- classes/Category.php | 12 ++++++++++++ css/admin.css | 10 ++++++++++ translations/fr/admin.php | 3 ++- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/admin-dev/tabs/AdminCustomers.php b/admin-dev/tabs/AdminCustomers.php index 8894e9a78..1c8783c5b 100644 --- a/admin-dev/tabs/AdminCustomers.php +++ b/admin-dev/tabs/AdminCustomers.php @@ -798,7 +798,7 @@ class AdminCustomers extends AdminTab echo ''; echo ' -

'.$this->l('Apply non-cumulative rules (e.g., price, display method, reduction)').'

+
'.$this->l('The group will be as applied by default.').'
'; diff --git a/admin-dev/tabs/AdminGroups.php b/admin-dev/tabs/AdminGroups.php index 70b27773e..9b72edc2e 100644 --- a/admin-dev/tabs/AdminGroups.php +++ b/admin-dev/tabs/AdminGroups.php @@ -93,7 +93,9 @@ class AdminGroups extends AdminTab
'; if ($groupReductions) { - echo ' + + echo ' +
@@ -141,6 +143,7 @@ class AdminGroups extends AdminTab
'.$this->l('New group discount').' +
'.$this->l('Beware the reduction applied to a category does not stack with the overall reduction but replaces. The group is automatically added to the category.').'
* + *
 
@@ -306,12 +309,17 @@ class AdminGroups extends AdminTab $groupReduction = new GroupReduction(); if (!$id_category = Tools::getValue('id_category') OR !Validate::isUnsignedId($id_category)) $this->_errors[] = Tools::displayError('Wrong category ID'); - elseif (!$reduction = Tools::getValue('reduction') OR !Validate::isPrice($reduction)) + elseif (!$reduction = Tools::getValue('reductionByCategory') OR !Validate::isPrice($reduction)) $this->_errors[] = Tools::displayError('Invalid reduction (must be a percentage)'); - elseif (GroupReduction::doesExist((int)($obj->id), $id_category)) + elseif (Tools::getValue('reductionByCategory') > 100 OR Tools::getValue('reductionByCategory') < 0) + $this->_errors[] = Tools::displayError('Reduction value is incorrect'); + elseif (GroupReduction::doesExist((int)($obj->id), $id_category)){ $this->_errors[] = Tools::displayError('A reduction already exists for this category.'); + } else { + $category = new Category((int)$id_category); + $category->addGroupsIfNoExist(Tools::getValue('id_group')); $groupReduction->id_category = (int)($id_category); $groupReduction->id_group = (int)($obj->id); $groupReduction->reduction = (float)($reduction) / 100; @@ -338,7 +346,9 @@ class AdminGroups extends AdminTab { foreach ($id_group_reductions AS $key => $id_group_reduction) if (!Validate::isUnsignedId($id_group_reductions[$key]) OR !Validate::isPrice($reductions[$key])) - $this->_errors[] = Tools::displayError(); + $this->_errors[] = Tools::displayError('Invalid reduction (must be a percentage)'); + elseif ($reductions[$key] > 100 OR $reductions[$key] < 0) + $this->_errors[] = Tools::displayError('Reduction value is incorrect'); else { $groupReduction = new GroupReduction((int)($id_group_reductions[$key])); diff --git a/classes/Category.php b/classes/Category.php index 1ba579849..fb6e23512 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -849,6 +849,18 @@ class CategoryCore extends ObjectModel $groups[] = $group['id_group']; return $groups; } + + public function addGroupsIfNoExist($id_group) + { + $groups = $this->getGroups(); + p($groups); + foreach($groups as $group){ + if($group != $id_group) + return false; + else + $this->addGroups(array((int)($id_group))); + } + } /** * checkAccess return true if id_customer is in a group allowed to see this category. diff --git a/css/admin.css b/css/admin.css index 71b7804e6..d0ed3bedf 100644 --- a/css/admin.css +++ b/css/admin.css @@ -762,6 +762,16 @@ div.hint { position: relative; } +.hintGroup{ + position: relative; + margin-top: 10px; + margin-bottom: 10px; + border: 1px solid #50B0EC; + padding: 8px 6px 8px 40px; + color: #383838; + background: #DDE9F7 url(../img/admin/help2.png) no-repeat 6px 5px; +} + /* The pointer image is added by using another span */ .hint .hint-pointer { diff --git a/translations/fr/admin.php b/translations/fr/admin.php index 414adfd0e..aa3b0fada 100644 --- a/translations/fr/admin.php +++ b/translations/fr/admin.php @@ -727,7 +727,7 @@ $_LANGADM['AdminCustomers8d218b952c9ef571cd270aaef8f849d1'] = 'Autoriser ou non $_LANGADM['AdminCustomerscca344269d726c206f3d3894c85cae5a'] = 'Client abonné à la newsletter'; $_LANGADM['AdminCustomers5ed5ce582affef97f07fa474c6751302'] = 'Client acceptant de recevoir des publicités'; $_LANGADM['AdminCustomers8d177b48ffca1fb18c3bfd1e8c0eb645'] = 'Groupe par défaut:'; -$_LANGADM['AdminCustomers7aea94ad2dc662cb934bc6746775fd3f'] = 'Le groupe à partir du quelle s\'appliquent les règles non cumulatives (par exemple, la méthode d\'affichage des prix, réduction)'; +$_LANGADM['AdminCustomersbf935f3541fafe3c2a68d2c52b0856b5'] = 'Le groupe par défaut est le groupe qui appliquera les règles non cumulatives (par exemple, la méthode d\'affichage des prix, réduction)'; $_LANGADM['AdminCustomers8783bc7ae2b9e8d93a2bc15150aaefa8'] = 'Groupes :'; $_LANGADM['AdminCustomersc6155aaecccf794cd2a00fcc35898022'] = 'Nom du groupe'; $_LANGADM['AdminCustomers3cf21846659529ae741430ff2ddf287f'] = 'Cochez tous les groupes auxquels appartient le membre'; @@ -1020,6 +1020,7 @@ $_LANGADM['AdminGroups817b35caca2afa11b6c1efc428315470'] = 'Groupe de boutiques $_LANGADM['AdminGroups38fb7d24e0d60a048f540ecb18e13376'] = 'Enregistrer'; $_LANGADM['AdminGroups19f823c6453c2b1ffd09cb715214813d'] = 'Champs requis'; $_LANGADM['AdminGroupsc53a3dc4f27d93e065c2c5be5a78b74f'] = 'Nouvelle réduction de groupe'; +$_LANGADM['AdminGroupsf3301519f560b65be8d8e67336df5b07'] = 'Attention, la réduction appliqué à une catégorie ne se cumule pas avec la réduction global mais la remplace. Le groupe est automatiquement ajoutée à la catégorie.'; $_LANGADM['AdminGroups56a8a9eb05f9014da51a4f9b57322ac7'] = 'Catégorie :'; $_LANGADM['AdminGroups60c4a9a7f56f6b9669f84977ebd0f93d'] = 'Seuls les produits qui ont cette catégorie par défaut seront ajoutés'; $_LANGADM['AdminGroups567183b8b1122180690be51cc6df2b74'] = 'Réduction (en %) :';
'.$this->l('Category').' '.$this->l('Value').'