function convert_categories_result($categories_values, $action = 'index') { $categories_id = $categories_values->fields['categories_id']; // link_to_categories $parm = array('category_id' => $categories_id); $link = easy_admin_products_html::href_link("categories", $parm); if ($action == 'search') { $categories_values->fields['link_to_categories'] = easy_admin_products_model::get_category($categories_id, $link); } else { $categories_values->fields['link_to_categories'] = '<a href="' . $link . '">' . zen_output_string_protected($categories_values->fields['categories_name']) . '</a>'; // subcategories_count $subcategories_counts = self::get_subcategories_counts(); $categories_values->fields['subcategories_count'] = (int) $subcategories_counts[$categories_id]; } // link_to_products $parm = array('category_id' => $categories_id); $categories_values->fields['link_to_products'] = easy_admin_products_html::href_link("", $parm); // link_to_status $parm = array('action' => 'setflag', 'cID' => $categories_id, 'flag' => $categories_values->fields['categories_status'] == '1' ? 0 : 1); $parm = self::add_current_parm($parm); $categories_values->fields['link_to_status'] = easy_admin_products_html::href_link("categories", $parm); $categories_values->fields['is_link'] = zen_get_products_to_categories($categories_id, true, 'products_active') == 'true'; return $categories_values->fields; }
// show counts $total_products = zen_get_products_to_categories($categories->fields['categories_id'], true); $total_products_on = zen_get_products_to_categories($categories->fields['categories_id'], false); echo $total_products_on . TEXT_PRODUCTS_STATUS_ON_OF . $total_products . TEXT_PRODUCTS_STATUS_ACTIVE; } ?> </td> <td class="dataTableContent" width="50" align="left"> <?php if ($categories->fields['categories_status'] == '1') { echo '<a href="' . zen_href_link(FILENAME_CATEGORIES, 'action=setflag_categories&flag=0&cID=' . $categories->fields['categories_id'] . '&cPath=' . $cPath . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '') . (isset($_GET['search']) && !empty($_GET['search']) ? '&search=' . $_GET['search'] : '')) . '">' . zen_image(DIR_WS_IMAGES . 'icon_green_on.gif', IMAGE_ICON_STATUS_ON) . '</a>'; } else { echo '<a href="' . zen_href_link(FILENAME_CATEGORIES, 'action=setflag_categories&flag=1&cID=' . $categories->fields['categories_id'] . '&cPath=' . $cPath . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '') . (isset($_GET['search']) && !empty($_GET['search']) ? '&search=' . $_GET['search'] : '')) . '">' . zen_image(DIR_WS_IMAGES . 'icon_red_on.gif', IMAGE_ICON_STATUS_OFF) . '</a>'; } if (zen_get_products_to_categories($categories->fields['categories_id'], true, 'products_active') == 'true') { echo ' ' . zen_image(DIR_WS_IMAGES . 'icon_yellow_on.gif', IMAGE_ICON_LINKED); } ?> </td> <td class="dataTableContent" align="right"><?php echo $categories->fields['sort_order']; ?> </td> <td class="dataTableContent" align="right"> <?php echo '<a href="' . zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories->fields['categories_id'] . '&action=edit_category' . (isset($_GET['search']) && !empty($_GET['search']) ? '&search=' . $_GET['search'] : '')) . '">' . zen_image(DIR_WS_IMAGES . 'icon_edit.gif', ICON_EDIT) . '</a>'; ?> <?php echo '<a href="' . zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $categories->fields['categories_id'] . '&action=delete_category') . '">' . zen_image(DIR_WS_IMAGES . 'icon_delete.gif', ICON_DELETE) . '</a>'; ?>
/** * Return the number of products in a category * TABLES: products, products_to_categories, categories * syntax for count: zen_get_products_to_categories($categories->fields['categories_id'], true) * syntax for linked products: zen_get_products_to_categories($categories->fields['categories_id'], true, 'products_active') */ function zen_get_products_to_categories($category_id, $include_inactive = false, $counts_what = 'products') { global $db; $products_count = $cat_products_count = 0; $products_linked = ''; if ($include_inactive == true) { switch ($counts_what) { case 'products': $cat_products_query = "select count(*) as total\n from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n where p.products_id = p2c.products_id\n and p2c.categories_id = '" . (int) $category_id . "'"; break; case 'products_active': $cat_products_query = "select p.products_id\n from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n where p.products_id = p2c.products_id\n and p2c.categories_id = '" . (int) $category_id . "'"; break; } } else { switch ($counts_what) { case 'products': $cat_products_query = "select count(*) as total\n from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n where p.products_id = p2c.products_id\n and p.products_status = 1\n and p2c.categories_id = '" . (int) $category_id . "'"; break; case 'products_active': $cat_products_query = "select p.products_id\n from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n where p.products_id = p2c.products_id\n and p.products_status = 1\n and p2c.categories_id = '" . (int) $category_id . "'"; break; } } $cat_products = $db->Execute($cat_products_query); switch ($counts_what) { case 'products': if (!$cat_products->EOF) { $cat_products_count += $cat_products->fields['total']; } break; case 'products_active': while (!$cat_products->EOF) { if (zen_get_product_is_linked($cat_products->fields['products_id']) == 'true') { return $products_linked = 'true'; } $cat_products->MoveNext(); } break; } $cat_child_categories_query = "select categories_id\n from " . TABLE_CATEGORIES . "\n where parent_id = '" . (int) $category_id . "'"; $cat_child_categories = $db->Execute($cat_child_categories_query); if ($cat_child_categories->RecordCount() > 0) { while (!$cat_child_categories->EOF) { switch ($counts_what) { case 'products': $cat_products_count += zen_get_products_to_categories($cat_child_categories->fields['categories_id'], $include_inactive); break; case 'products_active': if (zen_get_products_to_categories($cat_child_categories->fields['categories_id'], true, 'products_active') == 'true') { return $products_linked = 'true'; } break; } $cat_child_categories->MoveNext(); } } switch ($counts_what) { case 'products': return $cat_products_count; break; case 'products_active': return $products_linked; break; } }
$gBitSmarty->assign('currentCategoryId', $current_category_id); $gBitSmarty->assign('catMenu', zen_draw_pull_down_menu('cPath', zen_get_category_tree(), $current_category_id, 'onChange="this.form.submit();"')); $catListHash = $_REQUEST; if (isset($_GET['search'])) { $prodListHash['search'] = $_GET['search']; $catListHash['search'] = $_GET['search']; } else { $catListHash['parent_id'] = $current_category_id; } $catCount = 0; if ($catList = CommerceCategory::getList($catListHash)) { $catCount = count($catList); if ($gCommerceSystem->isConfigActive('SHOW_COUNTS_ADMIN')) { foreach (array_keys($catList) as $catId) { $catList[$catId]['total_products'] = zen_get_products_to_categories($catId, true); $catList[$catId]['total_products_on'] = zen_get_products_to_categories($catId, false); } } $gBitSmarty->assign('catList', $catList); $gBitSmarty->assign('catListHash', $catListHash); } $gBitSmarty->assign('catCount', $catCount); $product = new CommerceProduct(); $offset = new splitPageResults($_GET['page'], MAX_DISPLAY_RESULTS_CATEGORIES, $products_query_raw, $products_query_numrows); $prodListHash = $_REQUEST; $prodListHash['all_status'] = 1; $prodListHash['category_id'] = $current_category_id; if ($prodList = $product->getList($prodListHash)) { $gBitSmarty->assign_by_ref('prodList', $prodList); $gBitSmarty->assign_by_ref('prodListHash', $prodListHash); $gBitSmarty->assign('prodCount', count($prodList));
function zen_get_products_to_categories($category_id, $include_inactive = false, $counts_what = 'products') { global $gBitDb; $products_count = 0; $cat_products_count = 0; if ($include_inactive == true) { switch ($counts_what) { case 'products': $cat_products_query = "SELECT count(*) as `total`\n\t\t\t\t\t\t\t\t\t\t\t\t\t FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE p.`products_id` = p2c.`products_id`\n\t\t\t\t\t\t\t\t\t\t\t\t\t and p2c.`categories_id` = '" . (int) $category_id . "'"; break; case 'products_active': $cat_products_query = "SELECT p.`products_id`\n\t\t\t\t\t\t\t\t\t\t\t\t\t FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE p.`products_id` = p2c.`products_id`\n\t\t\t\t\t\t\t\t\t\t\t\t\t and p2c.`categories_id` = '" . (int) $category_id . "'"; break; } } else { switch ($counts_what) { case 'products': $cat_products_query = "SELECT count(*) as `total`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE p.`products_id` = p2c.`products_id`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t and p.`products_status` = '1'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t and p2c.`categories_id` = '" . (int) $category_id . "'"; break; case 'products_active': $cat_products_query = "SELECT p.`products_id`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE p.`products_id` = p2c.`products_id`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t and p.`products_status` = '1'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t and p2c.`categories_id` = '" . (int) $category_id . "'"; break; } } $cat_products = $gBitDb->Execute($cat_products_query); switch ($counts_what) { case 'products': $cat_products_count += $cat_products->fields['total']; break; case 'products_active': while (!$cat_products->EOF) { if (zen_get_product_is_linked($cat_products->fields['products_id']) == 'true') { return 'true'; } $cat_products->MoveNext(); } break; } $cat_child_categories_query = "SELECT `categories_id`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM " . TABLE_CATEGORIES . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE `parent_id` = '" . (int) $category_id . "'"; $cat_child_categories = $gBitDb->Execute($cat_child_categories_query); if ($cat_child_categories->RecordCount() > 0) { while (!$cat_child_categories->EOF) { switch ($counts_what) { case 'products': $cat_products_count += zen_get_products_to_categories($cat_child_categories->fields['categories_id'], $include_inactive); break; case 'products_active': if (zen_get_products_to_categories($cat_child_categories->fields['categories_id'], true, 'products_active') == 'true') { return 'true'; } break; } $cat_child_categories->MoveNext(); } } switch ($counts_what) { case 'products': return $cat_products_count; break; case 'products_active': return 'true'; break; } }