Opened 4 years ago
Closed 4 years ago
#2063 closed Bug/Fehler (fixed)
Boxen last_viewed und login nicht performant und schlüssig implementiert
| Reported by: | noRiddle | Owned by: | Gerhard Waldemair |
|---|---|---|---|
| Priority: | normal | Milestone: | modified-shop-2.0.7.0 |
| Component: | Template | Version: | 2.0.6.0 |
| Keywords: | Cc: | ||
| Blocked By: | Blocking: |
Description
In der index.html des Templates wird für beide im Betreff genannten Boxen die klassische Abfrage gemacht:
{if isset($box_LAST_VIEWED)}
oder
{if isset($box_LOGIN)}{$box_LOGIN}{/if}
Beides greift eigtl. nicht weil die Variablen immer gesetzt sind.
Das ist ungünstig wegen der Performance, weil u.U. Code ausgeführt wird der nicht ausgführt zu werden braucht und außerdem lassen sich die Boxen nicht an anderer Stelle als per Default vorgesehen konditional einbauen (z.B. in einem Dropdown-Menu bei schmalen Bildchirmen).
Das liegt an den zugehörigen PHP-Dateien in /source/boxes/.
Für die last_viewed.php schlage ich deshalb dies vor:
<?php
// include smarty
include(DIR_FS_BOXES_INC . 'smarty_default.php');
// reset cache id
$cache_id = '';
if (isset($_SESSION['tracking']['products_history']) && count($_SESSION['tracking']['products_history']) > 0) {
$random_last_viewed = xtc_rand(0, (count($_SESSION['tracking']['products_history']) - 1));
// set cache id
$cache_id = md5($_SESSION['language'].$_SESSION['customers_status']['customers_status'].$_SESSION['tracking']['products_history'][$random_last_viewed]);
if (!$box_smarty->is_cached(CURRENT_TEMPLATE.'/boxes/box_last_viewed.html', $cache_id) || !$cache) {
$random_query = "SELECT p.products_id,
p.products_price,
p.products_tax_class_id,
p.products_image,
p.products_vpe,
p.products_vpe_status,
p.products_vpe_value,
pd.products_name,
p2c.categories_id,
cd.categories_name
FROM " . TABLE_PRODUCTS . " p
JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd
ON p.products_id = pd.products_id
AND pd.language_id = '".(int)$_SESSION['languages_id']."'
AND trim(pd.products_name) != ''
JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
ON p.products_id = p2c.products_id
JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd
ON cd.categories_id = p2c.categories_id
AND cd.language_id = '".(int)$_SESSION['languages_id']."'
WHERE p.products_status = '1'
AND p.products_id = '".(int)$_SESSION['tracking']['products_history'][$random_last_viewed]."'
".PRODUCTS_CONDITIONS_P;
$random_query = xtDBquery($random_query);
if (xtc_db_num_rows($random_query, true) > 0) {
$random_product = xtc_db_fetch_array($random_query, true);
$box_smarty->assign('box_content', $product->buildDataArray($random_product));
$box_smarty->assign('MY_PERSONAL_PAGE', xtc_href_link(FILENAME_ACCOUNT));
$box_smarty->assign('CATEGORY_LINK', xtc_href_link(FILENAME_DEFAULT, xtc_category_link($random_product['categories_id'], $random_product['categories_name'])));
$box_smarty->assign('CATEGORY_NAME', $random_product['categories_name']);
}
}
//}
if (!$cache) {
$box_last_viewed = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_last_viewed.html');
} else {
$box_last_viewed = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_last_viewed.html', $cache_id);
}
} //include last lines in if-clause, 06-2021, noRiddle
if(isset($box_last_viewed)) {
$smarty->assign('box_LAST_VIEWED', $box_last_viewed);
} //define box conditionally, 06-2021, noRiddle
?>
und für die login.php dies:
<?php
// include smarty
include(DIR_FS_BOXES_INC . 'smarty_default.php');
if (!isset($_SESSION['customer_id'])) { //condition around whole code, 06-2021, noRiddle
// set cache id
$cache_id = md5($_SESSION['language'].((isset($_SESSION['customer_id'])) ? $_SESSION['customer_id'] : '0'));
if (!$box_smarty->is_cached(CURRENT_TEMPLATE.'/boxes/box_login.html', $cache_id) || !$cache) {
//if (!isset($_SESSION['customer_id'])) {
// include needed functions
require_once (DIR_FS_INC.'xtc_draw_password_field.inc.php');
$box_smarty->assign('FORM_ACTION', xtc_draw_form('loginbox', xtc_href_link(FILENAME_LOGIN, 'action=process', 'SSL'), 'post', 'class="box-login"'));
$box_smarty->assign('FIELD_EMAIL', xtc_draw_input_field('email_address', '', 'maxlength="50"'));
$box_smarty->assign('FIELD_PWD', xtc_draw_password_field('password', '', 'maxlength="30"'));
$box_smarty->assign('BUTTON', xtc_image_submit('button_login_small.gif', IMAGE_BUTTON_LOGIN));
$box_smarty->assign('BUTTON2', '<a href="'.xtc_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL').'">'.xtc_image_button('button_new_cust.gif', IMAGE_BUTTON_NEW_CUST).'</a>'); //new button, 03-2020, noRiddle
$box_smarty->assign('LINK_LOST_PASSWORD', xtc_href_link(FILENAME_PASSWORD_DOUBLE_OPT, '', 'SSL'));
$box_smarty->assign('FORM_END', '</form>');
//}
}
if (!$cache) {
$box_loginbox = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_login.html');
} else {
$box_loginbox = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_login.html', $cache_id);
}
} //condition around whole code, 06-2021, noRiddle
if(isset($box_loginbox)) {
$smarty->assign('box_LOGIN', $box_loginbox);
} //define box conditionally, 06-2021, noRiddle
?>
Damit greifen die isset()-Konditionen in der index.html und überall sonst wo man sie benutzen möchte wirklich.
Ich habe die Priorität mal auf hoch gesetzt weil es einfach zu lösen ist.
Gruß,
noRiddle
Attachments (0)
Change History (6)
comment:1 by , 4 years ago
comment:2 by , 4 years ago
*NACHTRAG*
Habe versehentlich eine ältere Template-Version als Vorlage benutzt.
Deshalb hier noch eine kurze zusätzliche Erklärung:
last_viewed:
Die Definition der Box sollte innerhalb der Kondition stehen
if (isset($_SESSION['tracking']['products_history']) && count($_SESSION['tracking']['products_history']) > 0) {
}
login:
Die Definition der Box sollte innerhalb der Kondition stehen
if (!isset($_SESSION['customer_id'])) {
}
Gruß,
noRiddle
comment:3 by , 4 years ago
@GTB
Habe deinen Kommentar erst jetzt gesehen. Während man schreibt sieht man nicht wenn ein anderer etwas postet.
Ja, wie ich schrieb, hatte mich vertan und eine ältere Template-Version als Beispiel genommen.
In der 2.0.6.0 ist das Problem jedoch dasselbe.
Gruß,
noRiddle
comment:4 by , 4 years ago
Damit du es einfacher hast hier die korrigierten 2.0.6.0-Versionen:
last_viewed:
<?php
/* -----------------------------------------------------------------------------------------
$Id: last_viewed.php 12294 2019-10-23 09:15:59Z GTB $
modified eCommerce Shopsoftware
http://www.modified-shop.org
Copyright (c) 2009 - 2013 [www.modified-shop.org]
-----------------------------------------------------------------------------------------
based on:
(c) 2003 XT-Commerce - www.xt-commerce.com
Released under the GNU General Public License
---------------------------------------------------------------------------------------*/
// include smarty
include(DIR_FS_BOXES_INC . 'smarty_default.php');
// reset cache id
$cache_id = '';
if (isset($_SESSION['tracking']['products_history']) && count($_SESSION['tracking']['products_history']) > 0) {
$random_last_viewed = xtc_rand(0, (count($_SESSION['tracking']['products_history']) - 1));
// set cache id
$cache_id = md5($_SESSION['currency'].$_SESSION['language'].$_SESSION['customers_status']['customers_status'].$_SESSION['tracking']['products_history'][$random_last_viewed]);
if (!$box_smarty->is_cached(CURRENT_TEMPLATE.'/boxes/box_last_viewed.html', $cache_id) || !$cache) {
$random_query = "SELECT ".$product->default_select.",
p2c.categories_id,
cd.categories_name
FROM " . TABLE_PRODUCTS . " p
JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd
ON p.products_id = pd.products_id
AND pd.language_id = '".(int)$_SESSION['languages_id']."'
AND trim(pd.products_name) != ''
JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
ON p.products_id = p2c.products_id
JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd
ON cd.categories_id = p2c.categories_id
AND cd.language_id = '".(int)$_SESSION['languages_id']."'
WHERE p.products_status = '1'
AND p.products_id = '".(int)$_SESSION['tracking']['products_history'][$random_last_viewed]."'
".PRODUCTS_CONDITIONS_P;
$random_query = xtDBquery($random_query);
if (xtc_db_num_rows($random_query, true) > 0) {
$random_product = xtc_db_fetch_array($random_query, true);
$box_smarty->assign('box_content', $product->buildDataArray($random_product));
$box_smarty->assign('MY_PERSONAL_PAGE', xtc_href_link(FILENAME_ACCOUNT));
$box_smarty->assign('CATEGORY_LINK', xtc_href_link(FILENAME_DEFAULT, xtc_category_link($random_product['categories_id'], $random_product['categories_name'])));
$box_smarty->assign('CATEGORY_NAME', $random_product['categories_name']);
}
}
if (!$cache) {
$box_last_viewed = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_last_viewed.html');
} else {
$box_last_viewed = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_last_viewed.html', $cache_id);
}
}
if(isset($box_last_viewed)) {
$smarty->assign('box_LAST_VIEWED', $box_last_viewed);
}
?>
login:
<?php
/* -----------------------------------------------------------------------------------------
$Id: loginbox.php 11146 2018-05-29 15:49:08Z GTB $
modified eCommerce Shopsoftware
http://www.modified-shop.org
Copyright (c) 2009 - 2013 [www.modified-shop.org]
-----------------------------------------------------------------------------------------
based on:
(c) 2000-2001 The Exchange Project (earlier name of osCommerce)
(c) 2002-2003 osCommerce(search.php,v 1.22 2003/02/10); www.oscommerce.com
(c) 2003 nextcommerce (search.php,v 1.9 2003/08/17); www.nextcommerce.org
(c) 2006 XT-Commerce - TPC Loginbox V1 - Aubrey Kilian <aubrey@mycon.co.za>
-----------------------------------------------------------------------------------------
Released under the GNU General Public License
---------------------------------------------------------------------------------------*/
// include smarty
include(DIR_FS_BOXES_INC . 'smarty_default.php');
if (!isset($_SESSION['customer_id'])) {
// include needed functions
require_once (DIR_FS_INC.'xtc_draw_password_field.inc.php');
$box_smarty->assign('FORM_ACTION', xtc_draw_form('loginbox', xtc_href_link(FILENAME_LOGIN, 'action=process', 'SSL'), 'post', 'class="box-login"'));
$box_smarty->assign('FIELD_EMAIL', xtc_draw_input_field('email_address', '', 'maxlength="50"'));
$box_smarty->assign('FIELD_PWD', xtc_draw_password_field('password'));
$box_smarty->assign('BUTTON', xtc_image_submit('button_login_small.gif', IMAGE_BUTTON_LOGIN));
$box_smarty->assign('LINK_LOST_PASSWORD', xtc_href_link(FILENAME_PASSWORD_DOUBLE_OPT, '', 'SSL'));
$box_smarty->assign('FORM_END', '</form>');
$box_smarty->caching = 0;
$box_loginbox = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_login.html');
$smarty->assign('box_LOGIN', $box_loginbox);
}
?>
comment:5 by , 4 years ago
| Milestone: | → modified-shop-2.0.6.1 |
|---|---|
| Priority: | hoch → normal |

schau dir bitte zuerst mal die Dateien aus der aktuellen 2.0.6.0 an.