Skip to content

Commit

Permalink
update store category tree to display number of products in category …
Browse files Browse the repository at this point in the history
…and flag improper category selection
  • Loading branch information
dleffler committed Jan 13, 2018
1 parent e7d008b commit 2f60b12
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 28 deletions.
44 changes: 22 additions & 22 deletions framework/core/assets/less/tree.less
Expand Up @@ -10,7 +10,7 @@
padding:0;
}

.ygtvspacer { height: 10px; width: 18px; }
.ygtvspacer { height: 13px!important; width: 13px!important; }
.ygtvcheck0 { background: url(../../../../external/yui/2in3/dist/2.9.0/build/assets/skins/sam/check0.gif) 0 0 no-repeat; width:16px; height:22px; cursor:pointer }
.ygtvcheck1 { background: url(../../../../external/yui/2in3/dist/2.9.0/build/assets/skins/sam/check1.gif) 0 0 no-repeat; width:16px; height:22px; cursor:pointer }
.ygtvcheck2 { background: url(../../../../external/yui/2in3/dist/2.9.0/build/assets/skins/sam/check2.gif) 0 0 no-repeat; width:16px; height:22px; cursor:pointer }
Expand All @@ -23,38 +23,38 @@
}

#dropindicator{
width:18px;
width:18px;
height:15px;
float:left;
margin:1px 5px 0 1px;
}
#dropindicator.dropattop{
background-image:url(../images/exp1icons.png);
background-image:url(../images/exp1icons.png);
background-repeat:no-repeat;
background-position:0 -643px;
background-position:0 -643px;
}

#dropindicator.dropatbottom{
background-image:url(../images/exp1icons.png);
background-image:url(../images/exp1icons.png);
background-repeat:no-repeat;
background-position:0 -665px;
background-position:0 -665px;
}
#dropindicator.putinbetween{
background-image:url(../images/exp1icons.png);
background-image:url(../images/exp1icons.png);
background-repeat:no-repeat;
background-position:0 -685px;
background-position:0 -685px;
}

#dropindicator.addtome{
background-image:url(../images/exp1icons.png);
background-image:url(../images/exp1icons.png);
background-repeat:no-repeat;
background-position:0 -703px;
background-position:0 -703px;
}

#dropindicator.nodrop{
background-image:url(../images/exp1icons.png);
background-image:url(../images/exp1icons.png);
background-repeat:no-repeat;
background-position:0 -722px;
background-position:0 -722px;
}

.dragtable:hover {
Expand Down Expand Up @@ -92,9 +92,9 @@
font-family:"Trebuchet MS","Verdana";
margin:0px;
border-bottom:1px dotted #888;
background-image:url(../images/exp1icons.png);
background-image:url(../images/exp1icons.png);
background-repeat:no-repeat;
background-position: 0px -548px;
background-position: 0px -548px;
}

#treecontext.yuimenu.show-scrollbars {
Expand Down Expand Up @@ -275,15 +275,15 @@ version: 2.5.1
.ygtvblankdepthcell { width:18px; height:22px; }

/* the style of the div around each node */
.ygtvitem { }
.ygtvitem { }

/* the style of the div around each node's collection of children */
.ygtvchildren {
.ygtvchildren {
*zoom: 1;
}
}

/* the style of the text label in ygTextNode */
.ygtvlabel, .ygtvlabel:link, .ygtvlabel:visited, .ygtvlabel:hover {
.ygtvlabel, .ygtvlabel:link, .ygtvlabel:visited, .ygtvlabel:hover {
margin-left:2px;
text-decoration: none;
font-size:12px;
Expand All @@ -293,10 +293,10 @@ version: 2.5.1
margin-left: 0;
}

.ygtvspacer {
height: 22px;
width: 12px;
}
//.ygtvspacer {
// height: 22px;
// width: 12px;
//}

//#catModal .ygtvtable tr td {
// background:inherit;
Expand Down
11 changes: 9 additions & 2 deletions framework/core/forms/controls/jquery/tagtreecontrol.php
Expand Up @@ -116,7 +116,7 @@ function toHTML($label, $name) {
foreach ($icon as $key=>$icn) {
$text = expTheme::buttonIcon($key, 'large');
$icon[$key] = $text->prefix . $text->class . ' ' . $text->size;
if (bs3())
if (bs3() || bs4())
$icon[$key] .= ' fa-fw';
elseif (bs2())
$icon[$key] .= ' icon-fixed-width';
Expand All @@ -134,6 +134,13 @@ function toHTML($label, $name) {
$this->tags[$i]->value = false;
$this->tags[$i]->state->selected = false;
}
if ($this->checkable && isset($this->tags[$i]->subcount) && $this->tags[$i]->subcount) {
if (!$this->tags[$i]->value) {
$this->tags[$i]->state->disabled = true;
} else {
$this->tags[$i]->text = '<span style="color:red;"><strong>' . $this->tags[$i]->text . '&nbsp;(<em>' . gt('Improper Category, please deselect') . '</em>)</strong></span>';
}
}
$this->tags[$i]->draggable = $this->draggable;
$this->tags[$i]->checkable = $this->checkable;
}
Expand Down Expand Up @@ -224,7 +231,7 @@ function toHTML($label, $name) {
'keep_selected_style' : false,
'three_state' : false,
// 'whole_node' : false,
'cascade' : 'undetermined'
'cascade' : 'false'
},
'plugins' : [" . ($this->draggable?"'dnd'":"") . "," . ($this->menu?"'contextmenu'":"") . "," . ($this->checkable?"'checkbox'":"") . "]
}).on('move_node.jstree', function (e, data) {
Expand Down
3 changes: 3 additions & 0 deletions framework/core/forms/controls/tagtreecontrol.php
Expand Up @@ -111,6 +111,9 @@ function toHTML($label, $name) {
foreach ($this->tags as $i=> $val) {
if (!empty($this->values) && in_array($val->id, $this->values)) {
$this->tags[$i]->value = true;
if ($this->checkable && isset($this->tags[$i]->subcount) && $this->tags[$i]->subcount) {
$this->tags[$i]->title = '<span style="color:red;" class="context"><strong class="context">' . $this->tags[$i]->text . '&nbsp;(<em class="context">' . gt('Improper Category, please deselect') . '</em>)</strong></span>';
}
} else {
$this->tags[$i]->value = false;
}
Expand Down
5 changes: 4 additions & 1 deletion framework/modules/ecommerce/controllers/storeController.php
Expand Up @@ -590,10 +590,13 @@ function manage() {
));
}

/**
* Display those products assigned to a NON-end level category
* therefore they can't really be displayed
*/
function showallImpropercategorized() {
expHistory::set('viewable', $this->params);

//FIXME not sure this is the correct sql, not sure what we are trying to pull out
$sql = 'SELECT DISTINCT(p.id),p.product_type FROM ' . DB_TABLE_PREFIX . '_product p ';
$sql .= 'JOIN ' . DB_TABLE_PREFIX . '_product_storeCategories psc ON p.id = psc.product_id ';
$sql .= 'JOIN '.DB_TABLE_PREFIX.'_storeCategories sc ON psc.storecategories_id = sc.parent_id ';
Expand Down
83 changes: 80 additions & 3 deletions framework/modules/ecommerce/models/storeCategory.php
Expand Up @@ -42,6 +42,30 @@ public function __construct($params=null, $get_assoc=true, $get_attached=true) {
}
}

/**
* Get count of sub-categories in this category
*
* @param null $id
* @return int
*/
public function getSubCatCount($id = null) {
global $db;

if ($id === null)
$id = $this->id;
if (empty($id)) {
return 0;
} else {
// $children = $db->selectNestedNodeChildren($this->table, $id);
return $db->countObjects($this->table,'parent_id=' . $id);
}
}

/**
* Return all sub-categories in this category
*
* @return array
*/
public function getEcomSubcategories() {
global $db;

Expand All @@ -64,6 +88,56 @@ public function getEcomSubcategories() {
return $children;
}

/**
* Return all products assigned to this category
*
* @param null $id
* @return array
*/
public function getAllProductsInThisCategory($id = null) {
global $user, $db;

if ($id === null)
$id = $this->id;
//if(!empty($order)) $order = " ORDER BY " . $order;
$order = " ORDER BY p.title ASC";

$sql_start = 'SELECT DISTINCT p.* FROM ' . DB_TABLE_PREFIX . '_product p ';
$sql = 'JOIN ' . DB_TABLE_PREFIX . '_product_storeCategories sc ON p.id = sc.product_id ';
$sql .= 'WHERE ';
if (!($user->is_admin || $user->is_acting_admin))
$sql .= '(p.active_type=0 OR p.active_type=1) AND ';
$sql .= 'sc.storecategories_id = ' . $id;
$sql = $sql_start . $sql . $order;
//echo $sql;
return $db->selectObjectsBySql($sql);
}

/**
* Return number of products assigned to this category
*
* @param null $id
* @return int
*/
public function countProductsInThisCategory($id = null) {
global $user, $db;

if ($id === null)
$id = $this->id;
//if(!empty($order)) $order = " ORDER BY " . $order;
$order = " ORDER BY p.title ASC";

$sql_start = 'SELECT count(DISTINCT p.id) as c FROM ' . DB_TABLE_PREFIX . '_product p ';
$sql = 'JOIN ' . DB_TABLE_PREFIX . '_product_storeCategories sc ON p.id = sc.product_id ';
$sql .= 'WHERE ';
if (!($user->is_admin || $user->is_acting_admin))
$sql .= '(p.active_type=0 OR p.active_type=1) AND ';
$sql .= 'sc.storecategories_id = ' . $id;
$sql = $sql_start . $sql . $order;
//echo $sql;
return $db->countObjectsBySql($sql);
}

/**
* Return an image object
*
Expand Down Expand Up @@ -123,12 +197,15 @@ public function getFullTree() {
$tree_copy[$key]->rgt = $node->rgt;
$tree_copy[$key]->lft = $node->lft;

$tree_copy[$key]->count = $this->countProductsInThisCategory($node->id); // number of products in category
$tree_copy[$key]->subcount = $this->getSubCatCount($node->id); // determine is this is a usable category

if (!empty($node->expFile[0]->id)) { // add thumbnail
$tree_copy[$key]->text = '<img class="filepic" src="' . PATH_RELATIVE . 'thumb.php?id=' . $node->expFile[0]->id . '&amp;w=18&amp;h=18&amp;zc=1" height="18" width="18">&#160;' . $node->title;
$tree_copy[$key]->text = '<img class="filepic" src="' . PATH_RELATIVE . 'thumb.php?id=' . $node->expFile[0]->id . '&amp;w=18&amp;h=18&amp;zc=1" height="18" width="18">&#160;' . $node->title . ' (' . $tree_copy[$key]->count . ')';
$tree_copy[$key]->title = $tree_copy[$key]->text;
} else {
$tree_copy[$key]->text = $node->title;
$tree_copy[$key]->title = $node->title;
$tree_copy[$key]->text = $node->title . ' (' . $tree_copy[$key]->count . ')';
$tree_copy[$key]->title = $tree_copy[$key]->text;
}
}
return $tree_copy;
Expand Down

0 comments on commit 2f60b12

Please sign in to comment.