Php 属性工具提示-如何改进代码?

Php 属性工具提示-如何改进代码?,php,magento,optimization,Php,Magento,Optimization,我在一个网站上工作,该网站需要根据产品显示各种工具提示。我正在使用Magento 1.9.0.1 CE。我正在寻找一种最小化代码的方法 我的代码如下所示: 根据magento中定义的属性设置attributeLabel $attributeLabel1 = $_product->getSpecField1Label(); $attributeLabel2 = $_product->getSpecField2Label(); $attributeLabel3 = $_product-&

我在一个网站上工作,该网站需要根据产品显示各种工具提示。我正在使用Magento 1.9.0.1 CE。我正在寻找一种最小化代码的方法

我的代码如下所示:

根据magento中定义的属性设置attributeLabel

$attributeLabel1 = $_product->getSpecField1Label();
$attributeLabel2 = $_product->getSpecField2Label();
$attributeLabel3 = $_product->getSpecField3Label();
$attributeLabel4 = $_product->getSpecField4Label();
$attributeLabel5 = $_product->getSpecField5Label();
$attributeLabel6 = $_product->getSpecField6Label();
$attributeLabel7 = $_product->getSpecField7Label();
$attributeLabel8 = $_product->getSpecField8Label();
用丹麦语和挪威语设置个人属性。该网站以两种语言的多存储运行。有比这些更多的属性(总共21个),但它会让您了解代码是如何工作的

$TipLyskvalitet = '<div class="tooltipText">Lyskvaliteten er baseret på vores eksperters test og vudering af produktet.</div>';
$TipKvalitet = '<div class="tooltipText">Kvaliteten er baseret på våre eksperters tester og vurdering av produktet.</div>';

$TipErstatter = '<div class="tooltipText">Produktet kan erstatte Tilsvarerende glødepærer/halogen spot  med det viste antal Watt.</div>';
$TipTilsvarer = '<div class="tooltipText">Produktet kan erstatte Tilsvarerende glødepærer/halogen spot med det viste antall Watt.</div>';

$TipBruger = '<div class="tooltipText">Produktet bruger maksimalt det viste antal Watt.</div>';
$TipBruker = '<div class="tooltipText">Produktet bruker maksimalt det viste antall Watt.</div>';

$TipDaempbar = '<div class="tooltipText">Kan produktet dæmpes med en lysdæmper? <ul><li><strong>Ja</strong> = Ja det kan det på de fleste lysdæmpere </li><li><strong>(Ja)</strong> = Ja - med forbehold, læs den fulde produktbeskrivelse for yderligere information.</li><li><strong>Nej</strong> = Dette produkt kan ikke dæmpes.</li></ul></div>';
$TipDimbar = '<div class="tooltipText">Kan produktet dimmes med en dimmer? <ul><li><strong>Ja</strong> = Ja det kan det på de fleste typer dimmere </li><li><strong>(Ja)</strong> = Ja - med forbehold, les den fulle produktbeskrivelsen for ytterligere informasjon.</li><li><strong>NEI</strong> = Dette produkt kan ikke dimmes.</li></ul></div>';
在站点上显示最终结果

<?php if ($_product->getAttributeText('spec_field1') == ""): ?>

<li style="display: none;"></li>

<?php else: ?>

<li><div class="product-infobox-header-bg"><?php if ($productTooltip1 != ""): echo '<div class="attributeTooltipLabel">' . $attributeLabel1  . $tooltipIcon; else: echo $attributeLabel1 . '<div>'; endif;?><div class="attributeTooltip"><div class="tooltipHeadline"><?php echo $attributeLabel1; ?></div>

<?php echo $productTooltip1; ?>

      </div></div>

      </div><br><?php print $_product->getAttributeText('spec_field1'); ?></li>

<?php endif; ?>


  • 所以我的问题是——有没有更简单的方法?代码可以工作,但我遇到了服务器内存问题,我正在尝试优化我的代码

    出于安全考虑,我不允许向您展示代码的其余部分,但我将尝试适应对代码段的任何请求

    if ($attributeLabel1 == 'Lyskvalitet'):
        $productTooltip1 = $TipLyskvalitet;
    elseif ($attributeLabel1 == 'Kvalitet'):
        $productTooltip1 = $TipKvalitet;
    else: $productTooltip1 = '';
    endif;
    
    if ($attributeLabel2 == 'Lyskvalitet'):
    $productTooltip2 = $TipLyskvalitet;
    elseif ($attributeLabel2 == 'Kvalitet'):
    $productTooltip2 = $TipKvalitet;
    else: $productTooltip2 = '';
    endif;
    
    if ($attributeLabel3 == 'Lyskvalitet'):
    $productTooltip3 = $TipLyskvalitet;
    elseif ($attributeLabel3 == 'Kvalitet'):
    $productTooltip3 = $TipKvalitet;
    else: $productTooltip3 = '';
    endif;
    
    if ($attributeLabel4 == 'Lyskvalitet'):
    $productTooltip4 = $TipLyskvalitet;
    elseif ($attributeLabel4 == 'Kvalitet'):
    $productTooltip4 = $TipKvalitet;
    else: $productTooltip4 = '';
    endif;
    
    if ($attributeLabel5 == 'Lyskvalitet'):
    $productTooltip5 = $TipLyskvalitet;
    elseif ($attributeLabel5 == 'Kvalitet'):
    $productTooltip5 = $TipKvalitet;
    else: $productTooltip5 = '';
    endif;
    
    if ($attributeLabel6 == 'Lyskvalitet'):
    $productTooltip6 = $TipLyskvalitet;
    elseif ($attributeLabel6 == 'Kvalitet'):
    $productTooltip6 = $TipKvalitet;
    else: $productTooltip6 = '';
    endif;
    
    if ($attributeLabel7 == 'Lyskvalitet'):
    $productTooltip7 = $TipLyskvalitet;
    elseif ($attributeLabel7 == 'Kvalitet'):
    $productTooltip7 = $TipKvalitet;
    else: $productTooltip7 = '';
    endif;
    
    if ($attributeLabel8 == 'Lyskvalitet'):
    $productTooltip8 = $TipLyskvalitet;
    elseif ($attributeLabel8 == 'Kvalitet'):
    $productTooltip8 = $TipKvalitet;
    else: $productTooltip8 = '';
    endif;
    
    <?php if ($_product->getAttributeText('spec_field1') == ""): ?>
    
    <li style="display: none;"></li>
    
    <?php else: ?>
    
    <li><div class="product-infobox-header-bg"><?php if ($productTooltip1 != ""): echo '<div class="attributeTooltipLabel">' . $attributeLabel1  . $tooltipIcon; else: echo $attributeLabel1 . '<div>'; endif;?><div class="attributeTooltip"><div class="tooltipHeadline"><?php echo $attributeLabel1; ?></div>
    
    <?php echo $productTooltip1; ?>
    
          </div></div>
    
          </div><br><?php print $_product->getAttributeText('spec_field1'); ?></li>
    
    <?php endif; ?>