Forums / General Questions / Howto Add class=selected to curent product image in sidebox when on product info page

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

Started by perfumbg on 28 Jun 2013, 5:07 PM · Views: 1,192

Results 1 to 8 of 8
28 Jun 2013, 5:07 PM
#1
perfumbg avatar

perfumbg

Zen Follower

Join Date:
May 2010
Posts:
192
Plugin Contributions:
5

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
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 .= '↓ Върни се към ↓<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_default, DIR_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(0, 9), array(' ', '+', '/', '-', '*'));
	$strippedcat2 = zen_get_categories_name((int)$current_category_id);
	$array4 = str_split($strippedcat2);
    $title .= '↓ Върни се към ↓<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_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);}

?>

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

<?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 .= '↓ Върни се към ↓<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_default, DIR_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(0, 9), array(' ', '+', '/', '-', '*'));
	$strippedcat2 = zen_get_categories_name((int)$current_category_id);
	$array4 = str_split($strippedcat2);
    $title .= '↓ Върни се към ↓<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_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);}

?>

Thanks in addvance

My most recent work: magprom.net

28 Jun 2013, 8:20 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

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

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.

29 Jun 2013, 10:51 AM
#3
perfumbg avatar

perfumbg

Zen Follower

Join Date:
May 2010
Posts:
192
Plugin Contributions:
5

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

oh yes sorry.

<?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'] > 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"') . '</a>';
   	$prolist->MoveNext();
   };
	
  $content .= '</div>';
	
	
?>

My most recent work: magprom.net

29 Jun 2013, 4:20 PM
#4
perfumbg avatar

perfumbg

Zen Follower

Join Date:
May 2010
Posts:
192
Plugin Contributions:
5

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

I tryed this

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'] > 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"') . '</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'] > 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"') . '</a>';
   	$prolist->MoveNext();}
   };

but it is givving the class="selectedImg" to the all images

My most recent work: magprom.net

29 Jun 2013, 6:23 PM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

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

Try this ...
(And of course you'll still need to add your .selectedImg selector to your stylesheet.)

<?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) {
[B]       $classHref = ($prolist->fields['products_id'] == $_GET['products_id']) ? ' class="selectedImg"' : '';
       $classImg = ($prolist->fields['products_id'] == $_GET['products_id']) ? ' selectedImg' : '';[/B]
       $content .=  '<a[B]' . $classHref . ' [/B]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[B]' . $classImg . ' [/B]"') . '</a>';
       $prolist->MoveNext();
   };
    
  $content .= '</div>';

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

30 Jun 2013, 4:56 PM
#6
perfumbg avatar

perfumbg

Zen Follower

Join Date:
May 2010
Posts:
192
Plugin Contributions:
5

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

Thanks a lot DrByte it worked great.

Many, many thanks.

My most recent work: magprom.net

1 Jul 2013, 9:20 AM
#7
perfumbg avatar

perfumbg

Zen Follower

Join Date:
May 2010
Posts:
192
Plugin Contributions:
5

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

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

15 Jul 2013, 3:50 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

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

perfumbg:

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:```
$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: ```
    $prolist_query = "select [B]if(p.products_id = " . (int)$_GET['products_id'] . ", 0, 1) as sorter,[/B]

            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 [B]sorter, [/B]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.