2

Our team has bought the Blanco theme, is a nice theme for Magento. Then after installing I tried to enter a product detail page and got this error:

Fatal error: Cannot redeclare themeOptions() (previously declared in
C:\wamp\www\magento\app\design\frontend\default\blanco\template\page\html\head.phtml:6) in
C:\wamp\www\magento\app\design\frontend\default\blanco\template\page\html\head.phtml on line 113

First I checked the provider website to read the FAQ's and any possible issue. No luck, so I posted my question there. Anyway I cannot wait for them to answer so... I searched about this error and found some suggestions here in StackOverflow, this post, this other one and some other. But the answers given there are not useful, or maybe I'm not implementing it right. Tried using the function_exist but it prevents the function from being loaded and the theme is not loaded at all on the product details page. Neither the include_once "head.html"; works.

I verified that the function is not declared anywhere else on the code.

What you recommend me to do? Is a phtml file, so it has a combination of php and html tags inside it. Here is the code:

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<script type="text/javascript">var slide_on=false;</script>
<?php 
function themeOptions ($themeOption) {
    switch ($themeOption) {

         /* GENERAL */
         case 'additionalLink':
           return Mage::getStoreConfig('mygeneral/generaloptions/additional_nav', Mage::app()->getStore()->getId());
         break;
         case 'menutype':
           return Mage::getStoreConfig('mygeneral/generaloptions/menutype', Mage::app()->getStore()->getId());
         break;
         case 'use_cufon':
           return (Mage::getStoreConfig('mygeneral/generaloptions/use_cufon', Mage::app()->getStore()->getId()) == 1);
         break;
         case 'topbanner':
           return Mage::getStoreConfig('mygeneral/generaloptions/topbanner', Mage::app()->getStore()->getId());
         break;     
         case 'phones':
           return Mage::getStoreConfig('mygeneral/generaloptions/phones', Mage::app()->getStore()->getId());
         break;
         case 'additionalLinkUrl':
           return Mage::getStoreConfig('mygeneral/generaloptions/additional_nav_href', Mage::app()->getStore()->getId());
         break;
         case 'topbtn':
           return (Mage::getStoreConfig('mygeneral/generaloptions/topbtn', Mage::app()->getStore()->getId()) == 1);
         break;
         case 'enable_ajax':
           return (Mage::getStoreConfig('mygeneral/generaloptions/enable_ajax', Mage::app()->getStore()->getId()) == 1);
         break;

          /* BackGroung */
         case 'pattern':
           return Mage::getStoreConfig('mygeneral/background/pattern', Mage::app()->getStore()->getId());
         break; 
         case 'maincolor':
           return Mage::getStoreConfig('mygeneral/background/maincolor', Mage::app()->getStore()->getId());
         break;  
         case 'bg_repeat':
           return Mage::getStoreConfig('mygeneral/background/bg_repeat', Mage::app()->getStore()->getId());
         break;  
         case 'bg_attachment':
           return Mage::getStoreConfig('mygeneral/background/bg_attachment', Mage::app()->getStore()->getId());
         break;  
         case 'bg_position_x':
           return Mage::getStoreConfig('mygeneral/background/bg_position_x', Mage::app()->getStore()->getId());
         break; 
         case 'bg_position_y':
           return Mage::getStoreConfig('mygeneral/background/bg_position_y', Mage::app()->getStore()->getId());
         break;   

         /* SLIDESHOW */
         case 'use_slideshow':
           return (Mage::getStoreConfig('mygeneral/slideshow/use_slideshow', Mage::app()->getStore()->getId()) == 1);
         break;
         case 'autoplay':
           return (Mage::getStoreConfig('mygeneral/slideshow/autoplay', Mage::app()->getStore()->getId()) == 1);
         break;
         case 'speed':
           return Mage::getStoreConfig('mygeneral/slideshow/speed', Mage::app()->getStore()->getId());
         break;

         /* PRODUCT LIST */
         case 'hover_swap':
           return (Mage::getStoreConfig('mygeneral/product_list/hover_swap', Mage::app()->getStore()->getId()) == 1);
         break;
         case 'column_count':
           return Mage::getStoreConfig('mygeneral/product_list/column_count', Mage::app()->getStore()->getId());
         break;
         case 'layer':
           return Mage::getStoreConfig('mygeneral/product_list/layer', Mage::app()->getStore()->getId());
         break;
         case 'new_label':
           return (Mage::getStoreConfig('mygeneral/product_list/new_label', Mage::app()->getStore()->getId()) == 1);
         break;
         case 'sale_label':
           return (Mage::getStoreConfig('mygeneral/product_list/sale_label', Mage::app()->getStore()->getId()) == 1);
         break;
         case 'addto':
           return (Mage::getStoreConfig('mygeneral/product_list/addto', Mage::app()->getStore()->getId()) == 1);

         /* SHARE */
         break;
         case 'use_share':
           return (Mage::getStoreConfig('mygeneral/share/use_share', Mage::app()->getStore()->getId()) == 1);
         break;
         case 'share_code':
           return Mage::getStoreConfig('mygeneral/share/share_code', Mage::app()->getStore()->getId());
         break;

         /* PRODUCT PAGE */
         case 'layout':
           return Mage::getStoreConfig('mygeneral/productpage/layout', Mage::app()->getStore()->getId());
         break;
         case 'use_zoom':
           return (Mage::getStoreConfig('mygeneral/productpage/use_zoom', Mage::app()->getStore()->getId()) == 1);
         break;
         case 'use_carousel':
           return (Mage::getStoreConfig('mygeneral/productpage/use_carousel', Mage::app()->getStore()->getId()) == 1);
         break;

         /* COLORS */
         case 'active_color':
           return Mage::getStoreConfig('mygeneral/colors/active_color');
         break;
         case 'button_hover':
           return Mage::getStoreConfig('mygeneral/colors/button_hover');
         break;
    }
}
?>
<meta http-equiv="Content-Type" content="<?php echo $this->getContentType() ?>" />
<title><?php echo $this->getTitle() ?></title>
<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" />
<meta name="robots" content="<?php echo htmlspecialchars($this->getRobots()) ?>" />
<link rel="icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
<!--[if lt IE 7]>
<script type="text/javascript">
//<![CDATA[
    var BLANK_URL = '<?php echo $this->helper('core/js')->getJsUrl('blank.html') ?>';
    var BLANK_IMG = '<?php echo $this->helper('core/js')->getJsUrl('spacer.gif') ?>';
//]]>
</script>
<![endif]-->
<script type="text/javascript">
  var BASE_URL = '<?php echo $this->getBaseUrl(); ?>';
  var clearenceUrl = '<?php echo themeOptions('additionalLinkUrl'); ?>';
</script>
<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml() ?>
<?php echo $this->helper('core/js')->getTranslatorScript() ?>
<?php echo $this->getIncludes() ?>

<!-- MENU -->
<?php $menutype = themeOptions('menutype'); ?>
<?php if($menutype == 1): ?>
    <link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('css/menu1.css'); ?>" media="screen"/>
<?php elseif($menutype == 2): ?>
    <link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('css/menu2.css'); ?>" media="screen"/>
    <script type="text/javascript" src="<?php echo $this->getJsUrl('varien/menu.js'); ?>"></script>
<?php endif; ?>

<!-- ZOOM -->
<?php $use_zoom = themeOptions('use_zoom'); ?>
<?php if($use_zoom): ?>
    <script type="text/javascript" src="<?php echo $this->getJsUrl('zoom/easyzoom.js'); ?>"></script>
    <link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('css/easyzoom.css'); ?>" media="screen"/>
<?php endif; ?>
<!-- CUFON -->
<?php $use_cufon = themeOptions('use_cufon'); ?>
<?php $use_slideshow = themeOptions('use_slideshow'); ?>
<?php if($use_cufon): ?>
    <script type="text/javascript" src="<?php echo $this->getJsUrl('cufon/cufon-yui.js'); ?>"></script>
    <script type="text/javascript" src="<?php echo $this->getJsUrl('cufon/Bebas_Neue_400.font.js'); ?>"></script>
    <script type="text/javascript" src="<?php echo $this->getJsUrl('cufon/cufon-replace.js'); ?>"></script>
<?php endif; ?>


<?php 
$selectors = Array();
$selectors['active_color'] = '
#nav > li.over > a > span,
#nav > li:hover > a > span,
#nav > li.active > a > span,
.product-tabs li.active a,
a:hover,
#nav > li > ul > li.parent > a:hover,
.footer-container a:hover,
.block-layered-nav dd a:hover,
.blocklist > li > ul > li a:hover,
#nav > li > ul > li ul > li a:hover,
.block-account .block-content li.current strong,
.form-search button.button:hover,
.special-price .price,
.product-tabs li a:hover,
.products-grid li.item:hover a,
.newproducts li.item:hover a,
.related li.item:hover a,
.saleproduct  
';

$selectors['active_color_imp'] = '.special-price .price';

$selectors['active_bg'] = '
.pages li a:hover,
.pages .current, 
button.button:hover,
.tintButton:hover,
.footer-container .form-subscribe button.button,
.add-to-cart button.button,
#added a:hover,
button.button.btn-checkout,
.opc .active .step-title,
a.readmore,
#added a,
.quantity_box_button_up:hover,
.quantity_box_button_down:hover,
.left-categorys-container a:hover,
.home-text a.readmore,
.box-tags button.button,
.tintButton,
.blocklist > li > ul > li:hover, 
#nav > li > ul > li ul > li:hover,
.block-account .block-title,
.block.left-categorys .block-title
';

$selectors['active_bg2'] = '
.add-to-cart button.button:hover,
button.btn-checkout.button:hover,
#banner-rotator .tintButton:hover,
a.readmore:hover,
.box-tags button.button:hover,
#added a:hover,
.footer-container .form-subscribe button.button:hover 
';

$selectors['active_border'] = '
.etheme_cp .etheme_cp_content .etheme_cp_section .pattern_select.selected,
.product-view .product-img-box .more-views a.thumbnail-active    
';

$selectors['brown_color'] = '
.blocklist > li > ul > li a,
#nav > li > ul > li ul > li a';

$selectors['brown_bg'] = '
.blocklist > li > ul > li,
.left-categorys-container a,
#nav > li > ul > li ul > li';

    function jsString($str='') { 
        return trim(preg_replace("/('|\"|\r?\n)/", '', $str)); 
    }     
?>


<style type="text/css">
    /* Active Color */
    <?php echo jsString($selectors['active_color']); ?>              { color: #<?php echo themeOptions('active_color') ?>; }

    <?php echo jsString($selectors['active_color_imp']); ?>          { color: #<?php echo themeOptions('active_color') ?>!important; }

    ::-moz-selection, ::selection { background-color: #<?php echo themeOptions('active_color') ?>; }
    /* Active BG */
    <?php echo jsString($selectors['active_bg']); ?>                 {  background-color: #<?php echo themeOptions('active_color') ?>; }

    <?php echo jsString($selectors['active_bg2']); ?>                {  background-color: #<?php echo themeOptions('button_hover') ?>; text-decoration: underline; }

    /* Active Border */
    <?php echo jsString($selectors['active_border']); ?>             {  border-color: #<?php echo themeOptions('active_color') ?>; }

    <?php echo jsString($selectors['brown_color']); ?>               {  color:#818181; }

    <?php echo jsString($selectors['brown_bg']); ?>                  {  background-color:#818181; }



</style>

<?php if($use_slideshow): ?>
<?php $speed = themeOptions('speed'); ?>
<script type="text/javascript">
    if(slide_on){
        jQuery(document).ready(function($) {
            $('.iosSlider').iosSlider({
                desktopClickDrag: true,
                touchMoveThreshold:4,
                snapToChildren: true,
                infiniteSlider: true,
                autoSlide:<?php echo (themeOptions('autoplay')) ? 'true' : 'false'; ?>,
                autoSlideTimer:<?php echo ($speed) ? $speed : '3000'  ?>,
                navSlideSelector: '.sliderNavi .naviItem',                
                navNextSelector: '.iosSlider .next',
                navPrevSelector: '.iosSlider .prev',
                onSlideChange: slideContentChange,
                onSlideComplete: slideContentComplete,
                onSliderLoaded: slideContentLoaded
            }); 

        }); 
    }
</script>
<?php endif; ?>

<script type="text/javascript">
        jQuery(document).ready(function (){
            jQuery('.toolbar').jqTransform({imgPath:'<?php echo $this->getSkinUrl('images/jqforms/'); ?>'});
            jQuery('.limiter').jqTransform({imgPath:'<?php echo $this->getSkinUrl('images/jqforms/'); ?>'});
        });  
</script>
<style>
    body{
        background-color:#<?php echo themeOptions('maincolor') ?>;
        background-attachment: <?php echo themeOptions('bg_attachment') ?>;
        background-position: <?php echo themeOptions('bg_position_y') ?> <?php echo themeOptions('bg_position_x') ?>;
        background-repeat: <?php echo themeOptions('bg_repeat') ?>;
    }   
</style>
<?php if(themeOptions('pattern') && themeOptions('pattern') != ''): ?>
    <style>
        body{ background-image: url(<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'wysiwyg/blanco/'.themeOptions('pattern') ?>); }    
    </style>
<?php endif; ?>
<!--[if IE 7]>
    <link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('css/ie7.css'); ?>" media="screen"/>
<![endif]-->
<!--[if IE 9]>
    <link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('css/ie9.css'); ?>" media="screen"/>
<![endif]-->
Community
  • 1
  • 1
Yaroslav
  • 6,476
  • 10
  • 48
  • 89
  • 1
    tell them that a tempalte is not a good place to put a php function (the Block layer is dedicated for that!). If it would have been correctly coded you wouldn't have this problem. – Jscti Nov 21 '12 at 10:48
  • 1
    ask the theme provider company, they are abide to solve your problem. – Kalpesh Nov 21 '12 at 10:50
  • They have just answered: "Your logs seems to say you are testing on local server, so we couldn’t have a look at it. The latest version of our template shouldn’t produce any errors on hosting." So, any recommendation, other than waiting for them to give me an successful answer? – Yaroslav Nov 21 '12 at 10:57

3 Answers3

4

This article gave a good head start to pin down the issue. I did comment out the lines suggested by Yaroslav, but it did not resolve issue for me. Then I used function_exists struct which seemed to work out. It has to used for 2 functions in the head.phtml

1) function themeOptions ($themeOption)

2) function jsString($str='')

Wrap the above functions in function_exits

if(!function_exists(themeOptions)){
function themeOptions ($themeOption) {
    //Piece of Code
    }
    }

if(!function_exists(jsString)){
    function jsString($str='') {
//Piece of Code
}
}

After this it all seems to be working fine.

jaipster
  • 11,967
  • 2
  • 21
  • 24
  • Need to try it out. On my previous tests using the `function_exists` prevented the details page to be loaded at all. Will check the jsString function. – Yaroslav Nov 25 '12 at 09:02
  • This solution in particular does not work for me. I had already previously tried the `if(!function_exists(themeOptions))` but this time added the one checking for the `jsString` function. Same results as before, the details page does not load at all. Nevertheless I will leave the upvote as it can be usefull to others having similar problem. – Yaroslav Nov 26 '12 at 09:15
  • Check my answer, edited and added the error. Verified again, is the same error in both cases, using only first `!function_exists` (as on my first tests) and using both checks (as you suggested). – Yaroslav Nov 27 '12 at 08:51
2

Since this module is coded the wrong way (a php function should never be declared in a template but in a BLock!) 2 solutions for your problem :

  • look at your layouts to understand why this template is included twice. Is it normal (you're trying to display this template in 2 different locations ? If so : you need to go to solution #2 since a PHP function cannot be redeclared)

  • modify the module to get in work the "magento way" (MVC) : move the function declaration in a dedicated Block (in the BLock folder of the module). Declare the BLock layer in the module's config.xml if needed and link your template and Block in the module's layout XML file.

and tell the template creator to respect magento standard ;)

Yaroslav
  • 6,476
  • 10
  • 48
  • 89
Jscti
  • 14,096
  • 4
  • 62
  • 87
  • Ok, I will try it tomorrow as soon as I get to the office...please don't use the f* word – Yaroslav Nov 21 '12 at 23:29
  • Following the advice of one of our developers I installed a new Magento instance. Everything works fine on this fresh Magento installation. Will start clean from here. As suggested by @Bixi, the answer should be related to a duplicate call to this template layout somewhere deep on the code. I have several different modules on previous Magento installation, some made by myself others from 3rd part. Maybe some of them were messing up with this theme or something alike. Nevertheless I will follow your recommendations Bixi and try to find out what was wrong. – Yaroslav Nov 22 '12 at 08:41
0

Finally the error appeared again with the fresh installation of Magento. After carefully reviewing the exception.log file and the particular phtml file where the error was found I managed to get it working by commenting a line and adding small piece of code.

This is the error from the exception.log file:

exception 'Exception' with message 'Notice: Undefined variable: tab in C:\wamp\www\magento\app\design\frontend\default\blanco\template\catalog\product\view\tabs.phtml on line 8' in C:\wamp\www\magento\app\code\core\Mage\Core\functions.php:245

Here is the guilty line on the tab.phtml file:

<?php if ($tab != $this->getChildHtml('product_custom_tab')): $last = 'last'; endif; ?>

What I've done is comment it and add a new line:

<?php //if ($tab != $this->getChildHtml('product_custom_tab')): $last = 'last'; endif; ?>
<?php $last = 'last'; ?>

Now everything seems to go smoothly, I'm checking it at this moment, product details is showing, all fancy rollovers work and tabs are ok too.

Yaroslav
  • 6,476
  • 10
  • 48
  • 89
  • I faced the same issue. I tried suggested by you, but got no results. Any specific caches need to be cleared that you may recommend. Thanks – jaipster Nov 24 '12 at 20:21
  • Ok I figured it out. Thank you. Your article gave me good head start to resolve the issue. I am posting my solution as an answer. The `function_exists` struct solved the issue for me. – jaipster Nov 25 '12 at 04:08