Joomla Templates and Joomla Extensions by JoomlaVision.Com

osCommerce - polska strona wsparcia

Naszą witrynę przegląda teraz 39 gości 

Get Adobe Flash Player

Oceń ten artykuł
(0 głosów)
Wersja skepu osCommerce: Merchant rc2.2, Proffesional 1.0.3
Dostępne wersje językowe: Polska

Powiązane artykuły (wg słów kluczowych)

W standardowej wersji sklepu osCommerce podczas wyświetlania liczebności kategorii wykonywanych jest dużo zapytań do bazy danych (zależnie od ilości kategorii i produktów). Niniejsza porada pokazuje, jak zoptymalizować nasz sklep.

W pliku includes/functions/general.php odszukaj funkcję:

testKod: php
  1. function tep_count_products_in_category($category_id, $include_inactive = false) {
  2. $products_count = 0;
  3. if ($include_inactive == true) {
  4. $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category_id . "'");
  5. } else {
  6. $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$category_id . "'");
  7. }
  8. $products = tep_db_fetch_array($products_query);
  9. $products_count += $products['total'];
  10.  
  11. $child_categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'");
  12. if (tep_db_num_rows($child_categories_query)) {
  13. while ($child_categories = tep_db_fetch_array($child_categories_query)) {
  14. $products_count += tep_count_products_in_category($child_categories['categories_id'], $include_inactive);
  15. }
  16. }
  17.  
  18. return $products_count;
  19. }

i zamień ją na funkcję:

testKod: php
  1. function tep_count_products_in_category($category_id, $include_inactive = false) {
  2.  
  3. if ($include_inactive) {
  4. $subindex = 'all';
  5. $active_clause = '';
  6. } else {
  7. $subindex = 'active_only';
  8. $active_clause = "and p.products_status = '1'";
  9. }
  10. if (!isset($GLOBALS['products_in_category'][$subindex])) {
  11. $query = tep_db_query("
  12. select   categories_id as category, parent_id,
  13. 0 as num_products, 0 as total
  14. from     " . TABLE_CATEGORIES . " c
  15. ");
  16. while ($row = tep_db_fetch_array($query)) {
  17. $GLOBALS['products_in_category'][$subindex][$row['category']] = $row;
  18. }
  19. $query = tep_db_query("
  20. select   count(*) as num_products,
  21. p2c.categories_id as category
  22. from     " . TABLE_PRODUCTS . " p,
  23. " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
  24. where    p.products_id = p2c.products_id
  25. $active_clause
  26. group by category
  27. ");
  28. while ($row = tep_db_fetch_array($query)) {
  29. $GLOBALS['products_in_category'][$subindex][$row['category']]['num_products'] = $row['num_products'];
  30. }
  31.  
  32. foreach ($GLOBALS['products_in_category'][$subindex] as $row) {
  33. $cat = $row['category'];
  34. $num = $row['num_products'];
  35. do {
  36. if (!isset($GLOBALS['products_in_category'][$subindex][$cat])) {
  37. $GLOBALS['products_in_category'][$subindex][$cat] = array();
  38. }
  39. $GLOBALS['products_in_category'][$subindex][$cat]['total'] += $num;
  40. $cat = $GLOBALS['products_in_category'][$subindex][$cat]['parent_id'];
  41. } while ($cat > 0);
  42. }
  43. }
  44. $pic =& $GLOBALS['products_in_category'][$subindex];
  45.  
  46. if (isset($pic[$category_id]) && isset($pic[$category_id]['total'])) {
  47. return($pic[$category_id]['total']);
  48. } else {
  49. return 0;
  50. }
  51. }

Dodaj swój komentarz

Make sure you enter the (*) required information where indicated.
Basic HTML code is allowed.

Logowanie

Nasze sondy

Czy podoba ci się nowa odsłona strony?
 
Money.pl - wiadomości, notowania, giełda, kursy walut
NBP 2012-05-22
USD 3,3811 -0,34%
EUR 4,3205 -0,27%
CHF 3,5973 -0,27%
GBP 5,3419 -0,44%
Money.pl - Kliknij po więcej
23 maja 2012
Źródło: MeteoGroup