Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Optimize Categories Box


Jan Zonjee

Recommended Posts

Hi Janz,

 

I just wanted to say thanks for this contribution and to let you know that I installed this just now and it has cut my queries down from 83 to 25! which, as you can imagine has made quite a difference in the page load time :)

 

Thanks

 

Dave

Link to comment
Share on other sites

I just wanted to say thanks for this contribution and to let you know that I installed this just now and it has cut my queries down from 83 to 25! which, as you can imagine has made quite a difference in the page load time :)

Happy to hear about that success Dave. Thanks for the feedback.

Link to comment
Share on other sites

i don't have previous versions of this contribution, but i am reading install_instructions.txt and it seems like it's an upgrade. am i reading incorrectly?

 

"Changes from version 1.1 to 1.2",,, etc, and so on.

Link to comment
Share on other sites

  • 2 weeks later...
i don't have previous versions of this contribution, but i am reading install_instructions.txt and it seems like it's an upgrade. am i reading incorrectly?

 

"Changes from version 1.1 to 1.2",,, etc, and so on.

 

That's the changelog, included in the instructions.

 

I think for fresh installs, you would start from

 

Upload the file CountProductsStore.php found in catalog/includes/classes/ to the equivalent directory in your site.

 

and everything below it.

Link to comment
Share on other sites

  • 2 weeks later...

The install file is a bit hard to follow, I keep getting lost and messing up. Anyone got any instructions that are a bit less mashed into each other?

 

Not been able to see how well it works yet, but I think it will be worth it from what I've heard.

Link to comment
Share on other sites

Can someone show me how admin/includes/functions/general.php is supposed to look, I'm having a tough time following the instructions. Or even if some one could just post saying what code goes where.

Would be much appreciated, ta.

PDS

Link to comment
Share on other sites

I'm having a tough time following the instructions. Or even if some one could just post saying what code goes where.

Wow, you should read a beginners book on PHP because you are asked to replace three functions. All you need to do is comment out the one you need to replace (then you have a backup too) and paste in the changed one.

 

Do you use a PHP editor? If you download one like jEdit and you put your cursor after a brace } then you see it's counter part with a line in the margin.

 

So the brace at the end of the line that starts with function like:

  function tep_products_in_category_count($categories_id, $include_deactivated = false) {

will lead you to the one at the end of the function. Add the end of comment after that brace (*/) and put a beginning of multi line comment before the word function:

/*   function tep_products_in_category_count($categories_id, $include_deactivated = false) {

Then the "old" function is commented out and you copy and paste the new one. Before or after the commented out function, your call.

Link to comment
Share on other sites

I'm not saying that I don't know how to edit PHP I just can't see in the instructions which bit is code and which bit is instructions. Some simple line breaks to seperate would mean that I don't have to ask stupid questions that make me look like a retard is all I'm saying.

Sorry if I sound rude, I do appreciate your help.

Link to comment
Share on other sites

I'm not saying that I don't know how to edit PHP I just can't see in the instructions which bit is code and which bit is instructions. Some simple line breaks to seperate would mean that I don't have to ask stupid questions that make me look like a retard is all I'm saying.

Sorry if I sound rude, I do appreciate your help.

 

Try opening the file in WordPad instead of Notepad. That should do the trick.

Link to comment
Share on other sites

thank you Nick2.

 

I got to installing it and so far appears to be working. cart functions properly, etc.

 

however, on my index.php page i did some customizing a while back to hide categories that have offline products. leaving this query unchanged in catelog/index.php:

  $category_depth = 'top';
 if (isset($cPath) && tep_not_null($cPath)) {
$categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
$cateqories_products = tep_db_fetch_array($categories_products_query);
if ($cateqories_products['total'] > 0) {
  $category_depth = 'products'; // display products
} else {
  $category_parent_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'");
  $category_parent = tep_db_fetch_array($category_parent_query);
  if ($category_parent['total'] > 0) {
	$category_depth = 'nested'; // navigate through the categories
  } else {
	$category_depth = 'products'; // category has no products, but display the 'no products' message
  }
}
 }

will it affect performance?

 

 

for reference, here is my version of the function (edited):

$category_depth = 'top';
if (isset($cPath) && tep_not_null($cPath)) {
  $categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
  $cateqories_products = tep_db_fetch_array($categories_products_query);
  if ($cateqories_products['total'] > 0) {
	$category_depth = 'products'; // display products
  } else {
	$category_parent_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'");
	$category_parent = tep_db_fetch_array($category_parent_query);
	if ($category_parent['total'] > 0) {
	  $category_depth = 'nested'; // navigate through the categories
	} else {
	  $category_depth = 'products'; // category has no products, but display the 'no products' message
	}

	$level1_cat = false;

	$level1_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "' and parent_id = '0'");

	$level1 = tep_db_fetch_array($level1_query);

	if ($level1['total'] > 0) {

	  $level1_cat = true; 

	}
  }
}

 

all of the other changes have been made and so far seem to be working properly.

Edited by eww
Link to comment
Share on other sites

thank you Nick2.

 

I got to installing it and so far appears to be working. cart functions properly, etc.

 

however, on my index.php page i did some customizing a while back to hide categories that have offline products. leaving this query unchanged in catelog/index.php:

 

will it affect performance?

Not much, that change was done to save a single query. It is not much, but if the info is available I thought it would be a waste not to save that query. The bulk of the queries are in the categories box itself though (and can be quite a bit if you have a lot of categories.)

 

for reference, here is my version of the function (edited):

You could save two queries there, but only if you show the number of products in categories (after the ->). Not a big deal.

Link to comment
Share on other sites

  • 2 weeks later...

As far as I was aware, this was working great.

Now I've discovered a problem in the admin section.

 

The following bit of code is giving me a bit of trouble. My categories/products page in catalogue isn't coming up at all, not even a header and the column, and I've traced it to this bit here, now I'm not sure what it's doing so I can't go about editing it as I've no idea what it does.

// include CountProductsStore object for use on the admin side
 require_once(DIR_FS_CATALOG . DIR_WS_FUNCTIONS . 'cache.php');
 require(DIR_FS_CATALOG. DIR_WS_CLASSES . 'CountProductsStore.php');
 $countproducts = new CountProductsStore();

Line 34-37, 93-96, 147-150, 175-178, 199-202, 220-223, 290-293, 332-335

 

Any chance of someone telling me roughly what it does and perhaps point me in the direction of a solution.

Cheers.

 

EDIT: I think I've narrowed the suspects down to the last line of the above. I commented it out and the categories page comes up. Do the numbers correspond to lines in CountProductsStore.php and they need looking at, or do they correspond to something else like the categories page, which may be edited and the line numbers need changing to reflect the edits I've made?

EDT2: The line numbers almost match up to if (USE_CACHE == 'true') ... code, as if they might have corresponded before I added the above code, can anyone confirm that they should match up, or am I clutching at straws?

Edited by powerdrive
Link to comment
Share on other sites

As far as I was aware, this was working great.

Now I've discovered a problem in the admin section.

 

The following bit of code is giving me a bit of trouble. My categories/products page in catalogue isn't coming up at all, not even a header and the column, and I've traced it to this bit here, now I'm not sure what it's doing so I can't go about editing it as I've no idea what it does.

// include CountProductsStore object for use on the admin side
 require_once(DIR_FS_CATALOG . DIR_WS_FUNCTIONS . 'cache.php');
 require(DIR_FS_CATALOG. DIR_WS_CLASSES . 'CountProductsStore.php');
 $countproducts = new CountProductsStore();

Line 34-37, 93-96, 147-150, 175-178, 199-202, 220-223, 290-293, 332-335

 

Any chance of someone telling me roughly what it does and perhaps point me in the direction of a solution.

It took me a long time to figure out what could possible go wrong here, but now it dawns on me. You added that line with numbers in your code?

 

It is part of the next set of instructions that tell you (rougly) to find the 8 times a piece of code comes up:

Line 34-37, 93-96, 147-150, 175-178, 199-202, 220-223, 290-293, 332-335

**AFTER** the 8 occurences of:

	  if (USE_CACHE == 'true') {
		tep_reset_cache_block('categories');
		tep_reset_cache_block('also_purchased');
	  }

**ADD**

	if (USE_PRODUCTS_COUNT_CACHE == 'true') {
		tep_reset_cache_block('products_count');
	}

So yes, commenting out that line you added should solve the problem.

Link to comment
Share on other sites

Happy to hear about that success Dave. Thanks for the feedback.

 

I just made the changes in CATALGO side alone.

 

it gives error as :

Parse error: parse error, unexpected '}' in /homepages/d*****/htdocs/*****hop/includes/functions/general.php on line 251

Link to comment
Share on other sites

So you made an error adding the code. Try again.

 

thanks ! it works good now.

 

but the LOADING time - i dont find any change.

it is the same as we had earlier before installing the contribution.

 

Iam using STS2.2 with Header tags and SEO urls.

 

 

 

see below the reference site : http://www.365ink.co.uk/

 

the above uses the same type of products and caetgories but loads very fast.

 

categories and subcategories count : 11500

Link to comment
Share on other sites

  • 3 weeks later...

Hi

 

Does anyone know how to change the columns per row without replace the product_listing.php with product_listing_col.php ?

 

I've just modified all but I have a problem with the listing file, missing the details button and whatever

 

I just want to konw how to fix this issue.

 

I'm almost there but I don't know what is the point in here :D

 

here is the code from product_listing.php

 

 ';
  $column ++;
  if ($column >= 4) {
	$rows ++;
	$column = 0;
	echo '

 

I modified the if ($column >= 4) { using the number 4 but this is working just on the first row, I have 2 rows, first one it's showing 4 products but the second one it's showing only 2 :angry:

 

any help will be appreciate

Edited by d_paulo
Link to comment
Share on other sites

Hi

 

Does anyone know how to change the columns per row without replace the product_listing.php with product_listing_col.php ?

 

I've just modified all but I have a problem with the listing file, missing the details button and whatever

 

I just want to konw how to fix this issue.

 

I'm almost there but I don't know what is the point in here :D

 

here is the code from product_listing.php

 

 ';
  $column ++;
  if ($column >= 4) {
	$rows ++;
	$column = 0;
	echo '

 

I modified the if ($column >= 4) { using the number 4 but this is working just on the first row, I have 2 rows, first one it's showing 4 products but the second one it's showing only 2 :angry:

 

any help will be appreciate

 

 

 

 

 

:thumbsup: I've just fix it, it was my foult. The option exist in the admin panel

Edited by d_paulo
Link to comment
Share on other sites

  • 1 year later...

Hi Jan,

 

Thank you for your great contribution.

 

Unfortunately, I have a problem.

If a category includes subcategories and the products to display only subcategories.

The products list is not visible.

 

In the file index.php condition:

} elseif ($category_depth == 'products' || isset($HTTP_GET_VARS['manufacturers_id'])) {

is not fulfilled.

 

In the file CountProductsStore.php likely to be responsible for the function countChildCategories.

 

Unfortunately, I do not know how to solve.

 

Currently moved products into subcategories, but this is not a perfect solution :-(

 

Thanks

Peter

 

PS: sorry for my english

Regards

hADeSik

Link to comment
Share on other sites

If a category includes subcategories and the products to display only subcategories.

The products list is not visible.

I'm not sure I understand you correctly. You are saying that if a category contains both products and subcategories, the products are not shown, only the subcategories?

Link to comment
Share on other sites

Yes.

in admin panel products in category:

Software
 |___Action
 | |___Unreal Tournament
 |___Simulation
 | |___SWAT 3: Close Quarters Battle
 |___Strategy
 | |___Disciples: Sacred Lands
 | |___The Wheel Of Time
 |___Beloved
 |___Courage Under Fire
 |___Red Corner

oryginal oscomerce installation:

categoryorg.th.png

optimized oscommerce:

categoriesoptimize.th.png

Regards

hADeSik

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...