Zen Cart Logo

Hiding Categories

Views: 8,408

Results 21 to 27 of 27
23 Nov 2010, 10:19 PM
#21
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Hiding Categories

Ditched the above this code does it

$result = mysql_query( 'SELECT categories_id FROM products_to_categories
WHERE products_id IN (SELECT products_id FROM products WHERE products_status = 1)
UNION
SELECT categories.parent_id FROM categories
WHERE categories.categories_id In (SELECT categories_id FROM products_to_categories)
UNION
SELECT parent_id FROM categories
WHERE categories_id IN( SELECT categories.parent_id FROM categories WHERE categories.categories_id In (SELECT categories_id FROM products_to_categories))
UNION
SELECT parent_id FROM categories
WHERE categories_id IN (SELECT parent_id FROM categories
WHERE categories_id IN( SELECT categories.parent_id FROM categories WHERE categories.categories_id In (SELECT categories_id FROM products_to_categories)))
UNION
SELECT parent_id FROM categories
WHERE categories_id IN (
SELECT parent_id FROM categories
WHERE categories_id IN (SELECT parent_id FROM categories
WHERE categories_id IN( SELECT categories.parent_id FROM categories WHERE categories.categories_id In (SELECT categories_id FROM products_to_categories))))
ORDER BY categories_id' );

$query="update " . TABLE_CATEGORIES . " set categories_status ='0'";
mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo $row['categories_id'];
$query="update " . TABLE_CATEGORIES . " set categories_status ='1' where categories_id = '".$row['categories_id']."'";
mysql_query($query) or die(mysql_error());
echo '<br>';
}

24 Jan 2011, 1:43 AM
#22
marknew avatar

marknew

Zen Follower

Join Date:
Oct 2005
Posts:
274
Plugin Contributions:
0

Re: Hiding Categories

Where does this code go? Does it replace the code or get added into functions_categories.php? Line number?

thanks!

24 Jan 2011, 2:12 AM
#23
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Hiding Categories

marknew,

Read post #20

24 Jan 2011, 5:48 PM
#24
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Hiding Categories

Hi the code works (nothing to do with post 20) - I just created a new php file in the admin for this and usually run it after easy populate. Just included the globals at top of php file (application top)

  • you may want to remove the echo statement if you use it else where...
24 Jan 2011, 10:54 PM
#25
marknew avatar

marknew

Zen Follower

Join Date:
Oct 2005
Posts:
274
Plugin Contributions:
0

Re: Hiding Categories

Thanks WebMC,

I'm not running easy populate, I'm just trying to hide the empty categories, sorry if I'm on the wrong track here.
I'm no programmer that's for sure.

So does the code from your post #21 only apply to easy populate or can i use it to hide empty categories automatically? If so could you spell it out for me? what file, what line etc. As i say I'm no programmer, just a designer hacking around!

Cheers.

24 Jan 2011, 10:59 PM
#26
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Hiding Categories

<?PHP require('includes/application_top.php'); global $db; ini_set ("display_errors", "1"); error_reporting(E_ALL); ini_set("memory_limit","80M"); $result = mysql_query( 'SELECT categories_id FROM products_to_categories WHERE products_id IN (SELECT products_id FROM products WHERE products_status = 1) UNION SELECT categories.parent_id FROM categories WHERE categories.categories_id In (SELECT categories_id FROM products_to_categories) UNION SELECT parent_id FROM categories WHERE categories_id IN( SELECT categories.parent_id FROM categories WHERE categories.categories_id In (SELECT categories_id FROM products_to_categories)) UNION SELECT parent_id FROM categories WHERE categories_id IN (SELECT parent_id FROM categories WHERE categories_id IN( SELECT categories.parent_id FROM categories WHERE categories.categories_id In (SELECT categories_id FROM products_to_categories))) UNION SELECT parent_id FROM categories WHERE categories_id IN ( SELECT parent_id FROM categories WHERE categories_id IN (SELECT parent_id FROM categories WHERE categories_id IN( SELECT categories.parent_id FROM categories WHERE categories.categories_id In (SELECT categories_id FROM products_to_categories)))) ORDER BY categories_id' ); $query="update " . TABLE_CATEGORIES . " set categories_status ='0'"; mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['categories_id']; $query="update " . TABLE_CATEGORIES . " set categories_status ='1' where categories_id = '".$row['categories_id']."'"; mysql_query($query) or die(mysql_error()); echo '<br>'; } ?>

just put that in a php file and run it when you need to - I have mine in admin folder. You could probably build a function with it - I personally wouldnt put it into a template file because it might be resource intensive. This is all I have done and wasnt planning on taking it any further. To run it just put hyperlink to file obviously.

If you have shell access you could put it in a cron job if need be

26 Jan 2011, 6:28 AM
#27
marknew avatar

marknew

Zen Follower

Join Date:
Oct 2005
Posts:
274
Plugin Contributions:
0

Re: Hiding Categories

OK thanks, I'll give it a try.