Results 1 to 8 of 8
  1. #1

    help question Howto Add class=selected to curent product image in sidebox when on product info page

    Hello again.

    Im using a litle moded prolist sidebox wich displays all products of curent category when you are on product info page.
    However I want to add class=selected to the curent product image in the prolist sidebox when on cirent product product info page.

    example page

    the prolist sidebox is in the left sidebar, and there are several images of products from the same category. I want to add class="selected" to the image witch ID is the same as the curent product info ID

    here is the code in prolist.php located in my modules/sidebox page

    PHP Code:
    <?php
    if (($current_page_base == 'product_info') and ((in_array($cPath,explode(",",'133,122'))) or strpos($cPath'134_') === 0)){
        require(
    $template->get_template_dir('tpl_prolist.php',DIR_WS_TEMPLATE$current_page_base,'sideboxes') . '/tpl_prolist.php');
        
    $title .= '&darr; Върни се към &darr;<br/><a href="' zen_href_link(FILENAME_DEFAULT'cPath=' $_GET['cPath'], 'NONSSL') . '" title="' .zen_get_categories_name((int)$current_category_id). '" >' zen_get_categories_name((int)$current_category_id) .  '</a><br/>';
        
    $title_link false;

        require(
    $template->get_template_dir($column_box_defaultDIR_WS_TEMPLATE$current_page_base,'common') . '/' $column_box_default);}
        
        elseif (
    $_GET["main_page"]=="product_info"){
        require(
    $template->get_template_dir('tpl_prolist.php',DIR_WS_TEMPLATE$current_page_base,'sideboxes') . '/tpl_prolist.php');
    $allowed4 array_merge(range('a''z'), range('A''Z'),range(09), array(' ''+''/''-''*'));
        
    $strippedcat2 zen_get_categories_name((int)$current_category_id);
        
    $array4 str_split($strippedcat2);
        
    $title .= '&darr; Върни се към &darr;<br/><a href="' zen_href_link(FILENAME_DEFAULT'cPath=' $_GET['cPath'], 'NONSSL') . '" title="' .implode(''array_intersect($array4$allowed4)). '" >' implode(''array_intersect($array4$allowed4)) .  '</a><br/>';
        
    $title_link false;

        require(
    $template->get_template_dir($column_box_defaultDIR_WS_TEMPLATE$current_page_base,'common') . '/' $column_box_default);}

    ?>
    and here the code in my tpl_prolist.php dile in templates directory

    PHP Code:
    <?php
    if (($current_page_base == 'product_info') and ((in_array($cPath,explode(",",'133,122'))) or strpos($cPath'134_') === 0)){
        require(
    $template->get_template_dir('tpl_prolist.php',DIR_WS_TEMPLATE$current_page_base,'sideboxes') . '/tpl_prolist.php');
        
    $title .= '&darr; Върни се към &darr;<br/><a href="' zen_href_link(FILENAME_DEFAULT'cPath=' $_GET['cPath'], 'NONSSL') . '" title="' .zen_get_categories_name((int)$current_category_id). '" >' zen_get_categories_name((int)$current_category_id) .  '</a><br/>';
        
    $title_link false;

        require(
    $template->get_template_dir($column_box_defaultDIR_WS_TEMPLATE$current_page_base,'common') . '/' $column_box_default);}
        
        elseif (
    $_GET["main_page"]=="product_info"){
        require(
    $template->get_template_dir('tpl_prolist.php',DIR_WS_TEMPLATE$current_page_base,'sideboxes') . '/tpl_prolist.php');
    $allowed4 array_merge(range('a''z'), range('A''Z'),range(09), array(' ''+''/''-''*'));
        
    $strippedcat2 zen_get_categories_name((int)$current_category_id);
        
    $array4 str_split($strippedcat2);
        
    $title .= '&darr; Върни се към &darr;<br/><a href="' zen_href_link(FILENAME_DEFAULT'cPath=' $_GET['cPath'], 'NONSSL') . '" title="' .implode(''array_intersect($array4$allowed4)). '" >' implode(''array_intersect($array4$allowed4)) .  '</a><br/>';
        
    $title_link false;

        require(
    $template->get_template_dir($column_box_defaultDIR_WS_TEMPLATE$current_page_base,'common') . '/' $column_box_default);}

    ?>
    Thanks in addvance
    My most recent work: magprom.net

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Howto Add class=selected to curent product image in sidebox when on product info

    You posted the same code twice, not the template file.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3

    Default Re: Howto Add class=selected to curent product image in sidebox when on product info

    oh yes sorry.

    PHP Code:
    <?php
    /**
     * Product Listing Sidebox
     *
     */

      
    $content '';
      
    $content .= '<div id="' str_replace('_''-'$box_id 'Content') . '" class="sideBoxContent">';
        
        
    $prolist_query "select 

                products.products_image, products_description.products_name, products_to_categories.*, categories_description.categories_id
                
                from products, products_description, products_to_categories, categories_description
                
                where categories_description.categories_id = '
    $current_category_id'
                and categories_description.categories_id = products_to_categories.categories_id
                and products_description.products_id = products_to_categories.products_id
                and products.products_id = products_description.products_id
                
                order by products_description.products_name
                "
    ;
        
            
    $prolist $db->Execute($prolist_query);
            
         while (!
    $prolist->EOF) {
           
    $content .=  '<a href="' zen_href_link(zen_get_info_page($prolist->fields['products_id']), ($_GET['cPath'] > 'cPath=' $_GET['cPath'] . '&' '') . 'products_id=' $prolist->fields['products_id']) . '">' zen_image(DIR_WS_IMAGES $prolist->fields['products_image'], $prolist->fields['products_name'],SMALL_IMAGE_WIDTH*1.2SMALL_IMAGE_HEIGHT*1.2'class="listingProductImage"') . '</a>';
           
    $prolist->MoveNext();
       };
        
      
    $content .= '</div>';
        
        
    ?>
    My most recent work: magprom.net

  4. #4

    Default Re: Howto Add class=selected to curent product image in sidebox when on product info

    I tryed this

    PHP Code:
    while (!$prolist->EOF) {
             if (
    $prolist->fields['products_id'] = (int)$_GET['products_id']) {
           
    $content .=  '<a class="selectedImg" href="' zen_href_link(zen_get_info_page($prolist->fields['products_id']), ($_GET['cPath'] > 'cPath=' $_GET['cPath'] . '&' '') . 'products_id=' $prolist->fields['products_id']) . '">' zen_image(DIR_WS_IMAGES $prolist->fields['products_image'], $prolist->fields['products_name'],SMALL_IMAGE_WIDTH*1.2SMALL_IMAGE_HEIGHT*1.2'class="listingProductImage"') . '</a>';
           
    $prolist->MoveNext();}
        elseif (
    $prolist->fields['products_id'] = (int)$_GET['products_id']) {
           
    $content .=  '<a href="' zen_href_link(zen_get_info_page($prolist->fields['products_id']), ($_GET['cPath'] > 'cPath=' $_GET['cPath'] . '&' '') . 'products_id=' $prolist->fields['products_id']) . '">' zen_image(DIR_WS_IMAGES $prolist->fields['products_image'], $prolist->fields['products_name'],SMALL_IMAGE_WIDTH*1.2SMALL_IMAGE_HEIGHT*1.2'class="listingProductImage"') . '</a>';
           
    $prolist->MoveNext();}
       }; 
    but it is givving the class="selectedImg" to the all images
    My most recent work: magprom.net

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Howto Add class=selected to curent product image in sidebox when on product info

    Try this ...
    (And of course you'll still need to add your .selectedImg selector to your stylesheet.)
    Code:
    <?php
    /**
     * Product Listing Sidebox
     *
     */
    
      $content = '';
      $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';
        
        $prolist_query = "select 
    
                products.products_image, products_description.products_name, products_to_categories.*, categories_description.categories_id
                
                from products, products_description, products_to_categories, categories_description
                
                where categories_description.categories_id = '$current_category_id'
                and categories_description.categories_id = products_to_categories.categories_id
                and products_description.products_id = products_to_categories.products_id
                and products.products_id = products_description.products_id
                
                order by products_description.products_name
                ";
        
            $prolist = $db->Execute($prolist_query);
            
         while (!$prolist->EOF) {
           $classHref = ($prolist->fields['products_id'] == $_GET['products_id']) ? ' class="selectedImg"' : '';
           $classImg = ($prolist->fields['products_id'] == $_GET['products_id']) ? ' selectedImg' : '';
           $content .=  '<a' . $classHref . ' href="' . zen_href_link(zen_get_info_page($prolist->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : '') . 'products_id=' . $prolist->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $prolist->fields['products_image'], $prolist->fields['products_name'],SMALL_IMAGE_WIDTH*1.2, SMALL_IMAGE_HEIGHT*1.2, 'class="listingProductImage' . $classImg . ' "') . '</a>';
           $prolist->MoveNext();
       };
        
      $content .= '</div>';
    Last edited by DrByte; 30 Jun 2013 at 03:20 PM. Reason: fixed typo
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6

    Default Re: Howto Add class=selected to curent product image in sidebox when on product info

    Thanks a lot DrByte it worked great.

    Many, many thanks.
    My most recent work: magprom.net

  7. #7

    Default Re: Howto Add class=selected to curent product image in sidebox when on product info

    Hello again,

    I want to do one last thing to this sideboxs. Is there a way to make the product that has class="selectedImg" first in the list?

    It is not something essential but will be nice efect.

    Thanks a lot again and many regards.
    My most recent work: magprom.net

  8. #8
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Howto Add class=selected to curent product image in sidebox when on product info

    Quote Originally Posted by perfumbg View Post
    I want to do one last thing to this sideboxs. Is there a way to make the product that has class="selectedImg" first in the list?
    You said you're using the following SQL query:
    Code:
        $prolist_query = "select 
    
                products.products_image, products_description.products_name, products_to_categories.*, categories_description.categories_id
                
                from products, products_description, products_to_categories, categories_description
                
                where categories_description.categories_id = '$current_category_id'
                and categories_description.categories_id = products_to_categories.categories_id
                and products_description.products_id = products_to_categories.products_id
                and products.products_id = products_description.products_id
                
                order by products_description.products_name
                ";
    To sort it and insert the currently-selected product at the top of the results, make the following changes:
    Code:
        $prolist_query = "select if(p.products_id = " . (int)$_GET['products_id'] . ", 0, 1) as sorter,
    
                products.products_image, products_description.products_name, products_to_categories.*, categories_description.categories_id
                
                from products, products_description, products_to_categories, categories_description
                
                where categories_description.categories_id = '$current_category_id'
                and categories_description.categories_id = products_to_categories.categories_id
                and products_description.products_id = products_to_categories.products_id
                and products.products_id = products_description.products_id
                
                order by sorter, products_description.products_name
                ";
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. Replies: 3
    Last Post: 15 May 2013, 06:00 PM
  2. Blank page when product selected from sidebox
    By PK_Lisa in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 4 Nov 2011, 04:46 AM
  3. Blank page when product selected from sidebox
    By PK_Lisa in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 3 Nov 2011, 04:26 AM
  4. Change product image when attribute is selected
    By webstar59 in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 24 Aug 2011, 07:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR