Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit 9376b9f

Browse files
author
aFolletete
committed
[*] BO : improve category listing in product edition and loyalty module
1 parent e758dfd commit 9376b9f

28 files changed

+1250
-52
lines changed

admin-dev/ajax.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,8 @@ function displayJavascriptAlert($s){echo '<script type="text/javascript">alert(\
674674
}
675675

676676
if (Tools::isSubmit('getChildrenCategories') && Tools::getValue('id_category_parent'))
677-
{
678-
/* / sleep(1); */
679-
$children_categories = Category::getChildrenWithNbSelectedSubCatForProduct(Tools::getValue('id_category_parent'), Tools::getValue('id_product', 0), Tools::getValue('post_selected_cat', null), $cookie->id_lang);
677+
{
678+
$children_categories = Category::getChildrenWithNbSelectedSubCat(Tools::getValue('id_category_parent'), Tools::getValue('selectedCat', array()), $cookie->id_lang);
680679
die(Tools::jsonEncode($children_categories));
681680
}
682681

admin-dev/tabs/AdminProducts.php

+39-13
Original file line numberDiff line numberDiff line change
@@ -2718,8 +2718,42 @@ function uploadFile()
27182718
<br /><input type="radio" name="out_of_stock" id="out_of_stock_3" value="2" '.($this->getFieldValue($obj, 'out_of_stock') == 2 ? 'checked="checked"' : '').'/> <label for="out_of_stock_3" class="t" id="label_out_of_stock_3">'.$this->l('Default:').' <i>'.$this->l(((int)(Configuration::get('PS_ORDER_OUT_OF_STOCK')) ? 'Allow orders' : 'Deny orders')).'</i> ('.$this->l('as set in').' <a href="index.php?tab=AdminPPreferences&token='.Tools::getAdminToken('AdminPPreferences'.(int)(Tab::getIdFromClassName('AdminPPreferences')).(int)($cookie->id_employee)).'" onclick="return confirm(\''.$this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false).'\');">'.$this->l('Preferences').'</a>)</label>
27192719
</td>
27202720
</tr>
2721-
<tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:100%;" /></td></tr>
2722-
<tr id="tr_categories"></tr>
2721+
<tr>
2722+
<td colspan="2" style="padding-bottom:5px;">
2723+
<hr style="width:100%;" />
2724+
</td>
2725+
</tr>
2726+
<tr>
2727+
<td class="col-left"><label for="id_category_default" class="t">'.$this->l('Default category:').'</label></td>
2728+
<td>
2729+
<div id="no_default_category" style="color: red;font-weight: bold;display: none;">'.$this->l('Please check a category in order to select the default category.').'</div>
2730+
<script>var post_selected_cat;</script>';
2731+
if (Tools::isSubmit('categoryBox'))
2732+
{
2733+
$postCat = Tools::getValue('categoryBox');
2734+
$selectedCat = Category::getSimpleCategories($this->_defaultFormLanguage, false, true, 'AND c.`id_category` IN ('.(empty($postCat) ? '1' : implode(',', $postCat)).')');
2735+
echo '<script>post_selected_cat = \''.implode(',', $postCat).'\';</script>';
2736+
}
2737+
if ($obj->id)
2738+
$selectedCat = $obj::getProductCategoriesFull($obj->id, $this->_defaultFormLanguage);
2739+
else if(!Tools::isSubmit('categoryBox'))
2740+
$selectedCat[] = array('id_category' => 1, 'name' => $this->l('Home'));
2741+
echo '<select id="id_category_default" name="id_category_default">';
2742+
2743+
foreach($selectedCat as $cat)
2744+
echo '<option value="'.$cat['id_category'].'" '.($obj->id_category_default == $cat['id_category'] ? 'selected' : '').'>'.$cat['name'].'</option>';
2745+
echo '</select>
2746+
</td>
2747+
</tr>
2748+
<tr id="tr_categories">
2749+
<td colspan="2">
2750+
';
2751+
$trads = array();
2752+
foreach(Helper::$translationsKeysForAdminCategorieTree as $key)
2753+
$trads[$key] = $this->l($key);
2754+
echo Helper::renderAdminCategorieTree($trads, 'categoryBox', $selectedCat).'
2755+
</td>
2756+
</tr>
27232757
<tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:100%;" /></td></tr>
27242758
<tr><td colspan="2">
27252759
<span onclick="$(\'#seo\').slideToggle();" style="cursor: pointer"><img src="../img/admin/arrow.gif" alt="'.$this->l('SEO').'" title="'.$this->l('SEO').'" style="float:left; margin-right:5px;"/>'.$this->l('Click here to improve product\'s rank in search engines (SEO)').'</span><br />
@@ -2902,18 +2936,10 @@ function uploadFile()
29022936
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce.inc.js"></script>
29032937
<script type="text/javascript">
29042938
toggleVirtualProduct(getE(\'is_virtual_good\'));
2905-
unitPriceWithTax(\'unit\');';
2939+
unitPriceWithTax(\'unit\');
2940+
</script>';
29062941
$categoryBox = Tools::getValue('categoryBox', array());
2907-
echo '
2908-
$(function() {
2909-
$.ajax({
2910-
type: \'POST\',
2911-
url: \'ajax_category_list.php\',
2912-
data: \''.(sizeof($categoryBox) > 0 ? 'categoryBox='.serialize($categoryBox).'&' : '').'id_product='.$obj->id.'&id_category_default='.($this->getFieldValue($obj, 'id_category_default') ? $this->getFieldValue($obj, 'id_category_default') : Tools::getValue('id_category', 1)).'&id_category='.(int)(Tools::getValue('id_category')).'&token='.$this->token.'\',
2913-
async : true,
2914-
success: function(msg) { $(\'#tr_categories\').replaceWith(msg); }
2915-
});
2916-
});</script>';
2942+
29172943
}
29182944

29192945
function displayFormImages($obj, $token = NULL)

classes/Category.php

+4-22
Original file line numberDiff line numberDiff line change
@@ -599,37 +599,19 @@ public static function getChildren($id_parent, $id_lang, $active = true)
599599
* @param int $id_lang
600600
* @return array
601601
*/
602-
public static function getChildrenWithNbSelectedSubCatForProduct($id_parent, $id_product = 0, $ids_categories = null, $id_lang)
602+
public static function getChildrenWithNbSelectedSubCat($id_parent, $selectedCat, $id_lang)
603603
{
604-
$categories_product_str = '';
605-
if ($id_product)
606-
{
607-
$categories_product = Db::getInstance()->ExecuteS('
608-
SELECT `id_category`
609-
FROM `'._DB_PREFIX_.'category_product`
610-
WHERE `id_product` = '.(int)$id_product);
611-
if (sizeof($categories_product))
612-
foreach ($categories_product as $category_product)
613-
$categories_product_str .= $category_product['id_category'].',';
614-
}
615-
else
616-
{
617-
$categories_product = array();
618-
$categories_product_str = $ids_categories;
619-
}
620-
$categories_product_str = rtrim($categories_product_str, ',');
621-
622604
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
623-
SELECT c.`id_category`, cl.`name`, IF((
605+
SELECT c.`id_category`, c.`level_depth`, cl.`name`, IF((
624606
SELECT COUNT(*)
625607
FROM `'._DB_PREFIX_.'category` c2
626608
WHERE c2.`id_parent` = c.`id_category`
627-
) > 0, 1, 0) AS has_children, '.($categories_product_str ? '(
609+
) > 0, 1, 0) AS has_children, '.($selectedCat ? '(
628610
SELECT count(c3.`id_category`)
629611
FROM `'._DB_PREFIX_.'category` c3
630612
WHERE c3.`nleft` > c.`nleft`
631613
AND c3.`nright` < c.`nright`
632-
AND c3.`id_category` IN ('.$categories_product_str.')
614+
AND c3.`id_category` IN ('.$selectedCat.')
633615
)' : '0').' AS nbSelectedSubCat
634616
FROM `'._DB_PREFIX_.'category` c
635617
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`

classes/Helper.php

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/*
3+
* 2007-2011 PrestaShop
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Open Software License (OSL 3.0)
8+
* that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/osl-3.0.php
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to license@prestashop.com so we can send you a copy immediately.
14+
*
15+
* DISCLAIMER
16+
*
17+
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
18+
* versions in the future. If you wish to customize PrestaShop for your
19+
* needs please refer to http://www.prestashop.com for more information.
20+
*
21+
* @author PrestaShop SA <contact@prestashop.com>
22+
* @copyright 2007-2011 PrestaShop SA
23+
* @version Release: $Revision$
24+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25+
* International Registered Trademark & Property of PrestaShop SA
26+
*/
27+
28+
/*
29+
* TODO : move HTML code in template files
30+
*/
31+
32+
class HelperCore
33+
{
34+
public static $translationsKeysForAdminCategorieTree = array(
35+
'Home', 'selected', 'selecteds', 'Collapse All', 'Expand All', 'Check All', 'Uncheck All'
36+
);
37+
38+
/**
39+
*
40+
* @param type $trads values of translations keys in self::$translationsKeysForAdminCategorieTree
41+
* @param type $input_name name of input
42+
* @param type $selected_cat array of selected categories
43+
* Format
44+
* Array
45+
(
46+
[0] => 1
47+
[1] => 2
48+
)
49+
* OR
50+
Array
51+
(
52+
[1] => Array
53+
(
54+
[id_category] => 1
55+
[name] => Home page
56+
[link_rewrite] => home
57+
)
58+
)
59+
* @return string
60+
*/
61+
public static function renderAdminCategorieTree($trads, $input_name = 'categoryBox', $selected_cat = array())
62+
{
63+
$html = '
64+
<script src="../js/jquery/treeview/jquery.treeview.js" type="text/javascript"></script>
65+
<script src="../js/jquery/treeview/jquery.treeview.async.js" type="text/javascript"></script>
66+
<script src="../js/jquery/treeview/jquery.treeview.edit.js" type="text/javascript"></script>
67+
<script src="../js/admin-categories-tree.js" type="text/javascript"></script>
68+
<script type="text/javascript">
69+
var inputName = "'.$input_name.'";
70+
var selectedCat = "'.implode(',', array_keys($selected_cat)).'";
71+
</script>
72+
<script type="text/javascript">
73+
var selectedLabelSingular = \''.$trads['selected'].'\';
74+
var selectedLabelPlurial = \''.$trads['selecteds'].'\';
75+
var home = \''.$trads['Home'].'\';
76+
</script>
77+
<link type="text/css" rel="stylesheet" href="../css/jquery.treeview.css" />
78+
';
79+
80+
$html .= '
81+
<div style="background-color:#F4E6C9; width:99%;padding:5px 0 5px 5px;">
82+
<a href="#" id="collapse_all" >'.$trads['Collapse All'].'</a>
83+
- <a href="#" id="expand_all" >'.$trads['Expand All'].'</a>
84+
- <a href="#" id="check_all" >'.$trads['Check All'].'</a>
85+
- <a href="#" id="uncheck_all" >'.$trads['Uncheck All'].'</a>
86+
</div>
87+
';
88+
89+
$home_is_selected = false;
90+
foreach($selected_cat as $cat)
91+
{
92+
if (is_array($cat))
93+
{
94+
if ($cat['id_category'] != 1)
95+
$html .= '<input type="hidden" name="'.$input_name.'[]" value="'.$cat['id_category'].'" >';
96+
else
97+
$home_is_selected = true;
98+
}
99+
else
100+
{
101+
if ($cat != 1)
102+
$html .= '<input type="hidden" name="'.$input_name.'[]" value="'.$cat.'" >';
103+
else
104+
$home_is_selected = true;
105+
}
106+
}
107+
$html .= '
108+
<ul id="categories-treeview" class="filetree">
109+
<li id="1" class="hasChildren">
110+
<span class="folder"> <input type="checkbox" name="'.$input_name.'[]" value="1" '.($home_is_selected ? 'checked' : '').' onclick="clickOnCategoryBox($(this));" /> '.$trads['Home'].'</span>
111+
<ul>
112+
<li><span class="placeholder">&nbsp;</span></li>
113+
</ul>
114+
</li>
115+
</ul>';
116+
return $html;
117+
}
118+
}

css/jquery.treeview.css

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.treeview, .treeview ul {
2+
padding: 0;
3+
margin: 0;
4+
list-style: none;
5+
}
6+
7+
.treeview ul {
8+
margin-top: 4px;
9+
}
10+
11+
.treeview .hitarea {
12+
background: url(../img/admin/jquery-treeview/treeview-default.gif) -64px -25px no-repeat;
13+
height: 16px;
14+
width: 16px;
15+
margin-left: -16px;
16+
float: left;
17+
cursor: pointer;
18+
}
19+
/* fix for IE6 */
20+
* html .hitarea {
21+
display: inline;
22+
float:none;
23+
}
24+
25+
.treeview li {
26+
margin: 0;
27+
padding: 3px 0pt 3px 16px;
28+
}
29+
30+
.treeview a.selected {
31+
background-color: #eee;
32+
}
33+
34+
#treecontrol { margin: 1em 0; display: none; }
35+
36+
.treeview .hover { color: gray; cursor: pointer; }
37+
38+
.treeview li { background: url(../img/admin/jquery-treeview/treeview-default-line.gif) 0 0 no-repeat; }
39+
.treeview li.collapsable, .treeview li.expandable { background-position: 0 -176px; }
40+
41+
.treeview .expandable-hitarea { background-position: -80px -3px; }
42+
43+
.treeview li.last { background-position: 0 -1766px }
44+
.treeview li.lastCollapsable, .treeview li.lastExpandable { background-image: url(../img/admin/jquery-treeview/treeview-default.gif); }
45+
.treeview li.lastCollapsable { background-position: 0 -111px }
46+
.treeview li.lastExpandable { background-position: -32px -67px }
47+
48+
.treeview div.lastCollapsable-hitarea, .treeview div.lastExpandable-hitarea { background-position: 0; }
49+
50+
.treeview-red li { background-image: url(../img/admin/jquery-treeview/treeview-red-line.gif); }
51+
.treeview-red .hitarea, .treeview-red li.lastCollapsable, .treeview-red li.lastExpandable { background-image: url(../img/admin/jquery-treeview/treeview-red.gif); }
52+
53+
.treeview-black li { background-image: url(../img/admin/jquery-treeview/treeview-black-line.gif); }
54+
.treeview-black .hitarea, .treeview-black li.lastCollapsable, .treeview-black li.lastExpandable { background-image: url(../img/admin/jquery-treeview/treeview-black.gif); }
55+
56+
.treeview-gray li { background-image: url(../img/admin/jquery-treeview/treeview-gray-line.gif); }
57+
.treeview-gray .hitarea, .treeview-gray li.lastCollapsable, .treeview-gray li.lastExpandable { background-image: url(../img/admin/jquery-treeview/treeview-gray.gif); }
58+
59+
.treeview-famfamfam li { background-image: url(../img/admin/jquery-treeview/treeview-famfamfam-line.gif); }
60+
.treeview-famfamfam .hitarea, .treeview-famfamfam li.lastCollapsable, .treeview-famfamfam li.lastExpandable { background-image: url(../img/admin/jquery-treeview/treeview-famfamfam.gif); }
61+
62+
.treeview .placeholder {
63+
background: url(../img/admin/jquery-treeview/ajax-loader.gif) 0 0 no-repeat;
64+
height: 16px;
65+
width: 16px;
66+
display: block;
67+
}
68+
69+
.filetree li { padding: 3px 0 2px 16px; }
70+
.filetree span.folder, .filetree span.file { padding: 1px 0 1px 16px; display: block; }
71+
.filetree span.folder { background: url(../img/admin/jquery-treeview/folder.gif) 0 0 no-repeat; }
72+
.filetree li.expandable span.folder { background: url(../img/admin/jquery-treeview/folder-closed.gif) 0 0 no-repeat; }
73+
.filetree span.file { background: url(../img/admin/jquery-treeview/file.gif) 0 0 no-repeat; }
847 Bytes
Loading

img/admin/jquery-treeview/file.gif

110 Bytes
Loading
105 Bytes
Loading

img/admin/jquery-treeview/folder.gif

106 Bytes
Loading

img/admin/jquery-treeview/minus.gif

837 Bytes
Loading

img/admin/jquery-treeview/plus.gif

841 Bytes
Loading
Loading
1.19 KB
Loading
Loading
1.19 KB
Loading
Loading
1.25 KB
Loading
1.83 KB
Loading
1.2 KB
Loading
1.83 KB
Loading
1.2 KB
Loading

0 commit comments

Comments
 (0)