Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Color Swatches with Tooltips
 
oakRunk
Sr. Member
 
Total Posts:  117
Joined:  2008-09-15
 

Has anyone gotten this to work? The article is located in the wiki - http://www.magentocommerce.com/wiki/adding_colour_swatches_to_configurable_products

I get a simple error stating unexpected T_CONSTANT_ENCAPSED_STRING, expecting ‘,’ or ‘;’
on this line:

echo '<li> <div onMouseover="ddrivetip(''.$colour_pick.'')"; onMouseout="hideddrivetip()"><img src="/media/catalog/colours/'.$colour_filename.'.jpg" alt="'.$colour_pick.'" width="48" height="48" title="'.$colour_pick.'" /></div></li>';

Here is the full code:

<div class="product-img-box">
            
<?php echo $this->getChildHtml('media'?>
            
#
<?php if($_product->isConfigurable()){

                        
echo '<div class="more-views"><h3>Colour Options</h3><ul>';

                        
$colours = array();

                        
$temp =  new Mage_Catalog_Block_Product_View_Type_Configurable();

                        
$_assProducts Mage::helper('core')->decorateArray($temp->getAllowProducts());

                        foreach(
$_assProducts as $_assProduct){

                                $tempProduct 
Mage::getModel('catalog/product');

                                
$tempProduct->load($_assProduct->getId());

                                
array_push($colours$tempProduct->getAttributeText('color'));

                                
array_push($colours$tempProduct->getAttributeText('color01'));

                        
}

                        $colour_swatch 
array_unique($colours);

                        foreach(
$colour_swatch as $colour_pick){

                                
if ($colour_pick!=NULL{

                                        $colour_filename 
preg_replace("/[^a-zA-Z0-9]/"""$colour_pick);

                                        echo 
'<li> <div onMouseover="ddrivetip(''.$colour_pick.'')"; onMouseout="hideddrivetip()"><img src="/media/catalog/colours/'.$colour_filename.'.jpg" alt="'.$colour_pick.'" width="48" height="48" title="'.$colour_pick.'" /></div></li>';

                                
}

                        }

                        
echo '</ul></div>';

                
} ?>
       
</div>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

Oops! There is an edit on that line for the ‘onclick’ - this was taken out as it was specific to a particular color/size combination.. The line should be:

echo '<li> <div onMouseover="ddrivetip(\''.$colour_pick.'\')"; onMouseout="hideddrivetip()"><img src="/media/catalog/colours/'.$colour_filename.'.jpg" alt="'.$colour_pick.'" width="48" height="48" title="'.$colour_pick.'" /></div></li>';

The working line, with the ‘onclick’ is:

echo '<li> <div onMouseover="ddrivetip(\''.$colour_pick.'\')"; onMouseout="hideddrivetip()"; onClick="document.getElementById(\'attribute890\').selectedIndex = '.$selected_colour.'; spConfig.configureElement($(\'attribute890\'))"><img src="/media/catalog/colours/'.$colour_filename.'.jpg" alt="'.$colour_pick.'" width="48" height="48" title="'.$colour_pick.'" /></div></li>';

You can go with that if you want, but you will have to update the attribute code for color, your site will have a different value than ‘attribute890’, this can be determined with firebug when inspecting the color dropdown. (The ‘onclick’ is used to update the dropdown with whatever swatch you click on.)

 
Magento Community Magento Community
Magento Community
Magento Community
 
oakRunk
Sr. Member
 
Total Posts:  117
Joined:  2008-09-15
 

Thanks for the update.

The first code posted worked, the second through an error though.

I have it on the site but I dont think its quite working as expected. Do you have this working on a test site I could check out?

 
Magento Community Magento Community
Magento Community
Magento Community
 
oakRunk
Sr. Member
 
Total Posts:  117
Joined:  2008-09-15
 

So, that second code is throwing an error:  Undefined variable: selected_colour

hmmm, I am going to play around with this and see if I can make the code do what I want it too.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sofian
Jr. Member
 
Total Posts:  9
Joined:  2008-12-27
 

Hi,

The selected_colour variable is not defined in view.phtml so I get the following error :

Notice: Undefined variable: selected_colour in C:\wamp\www\magento\app\design\frontend\default\modern\template\catalog\product\view.phtml on line 79

Please Discovery, could you provide us whith the code ?

Thx

 
Magento Community Magento Community
Magento Community
Magento Community
 
ins0
Member
 
Avatar
Total Posts:  38
Joined:  2008-03-26
 
oakRunk - 12 December 2008 06:17 PM

So, that second code is throwing an error:  Undefined variable: selected_colour

Anybody find the answer to this yet?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Designer
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2008-07-31
 

I’m upping this topic, because I’m stuck with it like everyone else…

 
Magento Community Magento Community
Magento Community
Magento Community
 
dealerpower
Jr. Member
 
Avatar
Total Posts:  21
Joined:  2008-08-04
 

I came across this video tutorial that may help........... http://activecodeline.com/wp-content/uploads/videos/MagentoProductColorChooser.swf

 
Magento Community Magento Community
Magento Community
Magento Community
 
darkedge3
Jr. Member
 
Total Posts:  24
Joined:  2009-03-13
 
sofian - 27 December 2008 06:50 AM

Hi,

The selected_colour variable is not defined in view.phtml so I get the following error :

Notice: Undefined variable: selected_colour in C:\wamp\www\magento\app\design\frontend\default\modern\template\catalog\product\view.phtml on line 79


Please Discovery, could you provide us whith the code ?


Thx

I’m getting the same ... I’m certain there is a solution here, because the example site is working fantastically - its probably just a very small thing wrong, but i cant put my finger on it!

 
Magento Community Magento Community
Magento Community
Magento Community
 
neurone
Member
 
Total Posts:  33
Joined:  2007-08-31
Paris - France
 

I have the same error and i am looking for the same think ... Please provide help smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
purush
Jr. Member
 
Total Posts:  7
Joined:  2009-04-23
 

Hi,

I am getting the below error

Undefined variableselected_colour

How to fix this, please reply asap.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top