2

我们的团队购买了Blanco 主题,是 Magento 的一个不错的主题。然后安装后我尝试进入产品详细信息页面并收到此错误:

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

首先,我查看了提供商网站以阅读常见问题解答和任何可能的问题。没有运气,所以我在那里发布了我的问题。无论如何,我等不及他们回答了……我搜索了这个错误,并在 StackOverflow、这篇文章、这篇文章和其他一些文章中找到了一些建议。但是那里给出的答案没有用,或者我没有正确实施。尝试使用,function_exist但它会阻止加载该功能,并且在产品详细信息页面上根本没有加载主题。作品都没有include_once "head.html";

我验证了该函数未在代码的其他任何地方声明。

你建议我做什么?是一个phtml文件,所以它里面有php和html标签的组合。这是代码:

<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]-->
4

3 回答 3

4

这篇文章为解决这个问题开了个好头。我确实注释掉了雅罗斯拉夫建议的行,但它并没有为我解决问题。然后我使用function_exists了似乎可行的结构。它必须用于 head.phtml 中的 2 个功能

1)函数主题选项($themeOption)

2) 函数 jsString($str='')

将上述函数包装在 function_exits 中

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

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

在此之后,一切似乎都运行良好。

于 2012-11-25T04:23:20.243 回答
2

由于此模块的编码方式错误(永远不应在模板中声明 php 函数,而应在块中声明!)解决您的问题的 2 个方法:

  • 查看您的布局以了解为什么此模板被包含两次。是否正常(您试图在 2 个不同的位置显示此模板?如果是这样:您需要转到解决方案 #2,因为无法重新声明 PHP 函数)

  • 修改模块以使用“magento 方式”(MVC):将函数声明移动到专用块中(在模块的 BLock 文件夹中)。如果需要,在模块的 config.xml 中声明 BLock 层,并在模块的布局 XML 文件中链接您的模板和 Block。

并告诉模板创建者尊重 magento 标准;)

于 2012-11-21T20:40:26.920 回答
0

最后,全新安装的 Magento 再次出现错误。在仔细查看 exception.log 文件和发现错误的特定 phtml 文件后,我设法通过注释一行并添加一小段代码来使其正常工作。

这是 exception.log 文件中的错误:

异常“异常”,带有消息“注意:未定义的变量:C 中的选项卡:\wamp\www\magento\app\design\frontend\default\blanco\template\catalog\product\view\tabs.phtml 第 8 行”在 C 中:\wamp\www\magento\app\code\core\Mage\Core\functions.php:245

这是 tab.phtml 文件中的有罪行:

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

我所做的是评论它并添加一个新行:

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

现在一切似乎都很顺利,我正在检查它,产品详细信息正在显示,所有花哨的翻转工作和标签也正常。

于 2012-11-22T11:35:20.333 回答