﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking
2063	Boxen last_viewed und login nicht performant und schlüssig implementiert	noRiddle	Gerhard Waldemair	"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


"	Bug/Fehler	closed	normal	modified-shop-2.0.7.0	Template	2.0.6.0	fixed				
