Joomla Templates and Joomla Extensions by JoomlaVision.Com

osCommerce - polska strona wsparcia

Naszą witrynę przegląda teraz 43 gości i 1 użytkownik 
  • rkendorfbeth

Get Adobe Flash Player

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. }

Dodatkowe informacje

  • Wersja skepu osCommerce Merchant rc2.2, Proffesional 1.0.3
  • Dostępne wersje językowe Polska
Opublikowane w Tips & tricks
poniedziałek, 17 października 2011 20:15

Aktualizacja sklepu osCommerce pod mysql5

Jeżeli błąd o treści 1054 - Unknown column 'p.products_id' in 'on clause' pojawia się na liście produktów lub w wynikach wyszukiwania koniecznie zastosuj się do poniższej porady.

Zmiany dotyczą dwóch plików: index.php i advanced_search_result.php z katalogu głównego sklepu.

W pierwszym z nich odszukujemy:

testKod: php
  1. // show the products of a specified manufacturer
  2. if (isset($HTTP_GET_VARS['manufacturers_id'])) {
  3. if (isset($HTTP_GET_VARS['filter_id']) && tep_not_null($HTTP_GET_VARS['filter_id'])) {
  4. // We are asked to show only a specific category
  5. $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "'";
  6. } else {
  7. // We show them all
  8. $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'";
  9. }
  10. } else {
  11. // show the products in a given categorie
  12. if (isset($HTTP_GET_VARS['filter_id']) && tep_not_null($HTTP_GET_VARS['filter_id'])) {
  13. // We are asked to show only specific catgeory
  14. $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
  15. } else {
  16. // We show them all
  17. $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
  18. }
  19. }

i zamieniamy na:

testKod: php
  1. // show the products of a specified manufacturer
  2. if (isset($HTTP_GET_VARS['manufacturers_id'])) {
  3. if (isset($HTTP_GET_VARS['filter_id']) && tep_not_null($HTTP_GET_VARS['filter_id'])) {
  4. // We are asked to show only a specific category
  5. $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "'";
  6. } else {
  7. // We show them all
  8. $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'";
  9. }
  10. } else {
  11. // show the products in a given categorie
  12. if (isset($HTTP_GET_VARS['filter_id']) && tep_not_null($HTTP_GET_VARS['filter_id'])) {
  13. // We are asked to show only specific catgeory
  14. $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
  15. } else {
  16. // We show them all
  17. $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from ((" . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p) left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
  18. }
  19. }

W drugim pliku odszukujemy kod:

testKod: php
  1. $from_str = "from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m using(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c";

i zamieniamy na:

testKod: php
  1. $from_str = "from ((" . TABLE_PRODUCTS . " p) left join " . TABLE_MANUFACTURERS . " m using(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c";

Jeżeli problem występuje na niewymienionej stronie należy wprowadzić zmiany zamykając zbiór tabel w nawiasy przed użyciem polecenia left join, czyli:

testKod: php
  1. select * from (tabela1) left join tabela 2 on tabela1.products_id = tabela2.products_id

Jeżeli stosujemy zapytanie z większą ilością poleceń left join należy to zrobić tak:

testKod: php
  1. select * from ((tabela1) left join tabela 2 on tabela1.products_id = tabela2.products_id) left join tabela3 on tabela3.status = tabela2.status)

Dodatkowe informacje

  • Wersja skepu osCommerce Merchant rc2.2, Proffesional 1.0.3
  • Dostępne wersje językowe Polska

Logowanie

Money.pl - wiadomości, notowania, giełda, kursy walut
NBP 2012-05-18
USD 3,4431 +0,69%
EUR 4,3683 +0,44%
CHF 3,6371 +0,44%
GBP 5,4356 +0,03%
Money.pl - Kliknij po więcej
20 maja 2012
Źródło: MeteoGroup